aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/date-fns/locale/_lib/buildMatchFn/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/date-fns/locale/_lib/buildMatchFn/index.js')
-rw-r--r--node_modules/date-fns/locale/_lib/buildMatchFn/index.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/node_modules/date-fns/locale/_lib/buildMatchFn/index.js b/node_modules/date-fns/locale/_lib/buildMatchFn/index.js
new file mode 100644
index 0000000..8b9ab2c
--- /dev/null
+++ b/node_modules/date-fns/locale/_lib/buildMatchFn/index.js
@@ -0,0 +1,49 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = buildMatchFn;
+function buildMatchFn(args) {
+ return function (string) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var width = options.width;
+ var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
+ var matchResult = string.match(matchPattern);
+ if (!matchResult) {
+ return null;
+ }
+ var matchedString = matchResult[0];
+ var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
+ var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
+ return pattern.test(matchedString);
+ }) : findKey(parsePatterns, function (pattern) {
+ return pattern.test(matchedString);
+ });
+ var value;
+ value = args.valueCallback ? args.valueCallback(key) : key;
+ value = options.valueCallback ? options.valueCallback(value) : value;
+ var rest = string.slice(matchedString.length);
+ return {
+ value: value,
+ rest: rest
+ };
+ };
+}
+function findKey(object, predicate) {
+ for (var key in object) {
+ if (object.hasOwnProperty(key) && predicate(object[key])) {
+ return key;
+ }
+ }
+ return undefined;
+}
+function findIndex(array, predicate) {
+ for (var key = 0; key < array.length; key++) {
+ if (predicate(array[key])) {
+ return key;
+ }
+ }
+ return undefined;
+}
+module.exports = exports.default; \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage