registration
This commit is contained in:
60
frontend/style/node_modules/date-fns/locale/_lib/buildMatchFn.cjs
generated
vendored
Normal file
60
frontend/style/node_modules/date-fns/locale/_lib/buildMatchFn.cjs
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
exports.buildMatchFn = buildMatchFn;
|
||||
|
||||
function buildMatchFn(args) {
|
||||
return (string, options = {}) => {
|
||||
const width = options.width;
|
||||
|
||||
const matchPattern =
|
||||
(width && args.matchPatterns[width]) ||
|
||||
args.matchPatterns[args.defaultMatchWidth];
|
||||
const matchResult = string.match(matchPattern);
|
||||
|
||||
if (!matchResult) {
|
||||
return null;
|
||||
}
|
||||
const matchedString = matchResult[0];
|
||||
|
||||
const parsePatterns =
|
||||
(width && args.parsePatterns[width]) ||
|
||||
args.parsePatterns[args.defaultParseWidth];
|
||||
|
||||
const key = Array.isArray(parsePatterns)
|
||||
? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
|
||||
: // [TODO] -- I challenge you to fix the type
|
||||
findKey(parsePatterns, (pattern) => pattern.test(matchedString));
|
||||
|
||||
let value;
|
||||
|
||||
value = args.valueCallback ? args.valueCallback(key) : key;
|
||||
value = options.valueCallback
|
||||
? // [TODO] -- I challenge you to fix the type
|
||||
options.valueCallback(value)
|
||||
: value;
|
||||
|
||||
const rest = string.slice(matchedString.length);
|
||||
|
||||
return { value, rest };
|
||||
};
|
||||
}
|
||||
|
||||
function findKey(object, predicate) {
|
||||
for (const key in object) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(object, key) &&
|
||||
predicate(object[key])
|
||||
) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function findIndex(array, predicate) {
|
||||
for (let key = 0; key < array.length; key++) {
|
||||
if (predicate(array[key])) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user