date-format-parse
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -0,1 +1,10 @@ | ||
## [0.2.6](https://github.com/mengxiong10/date-format-parse/compare/v0.2.5...v0.2.6) (2020-11-17) | ||
### Bug Fixes | ||
* the word that contain "." cann't be parsed ([91544a3](https://github.com/mengxiong10/date-format-parse/commit/91544a3f61f75e4e0b9e092a9e06d70725ffbbe4)) | ||
## [0.2.5](https://github.com/mengxiong10/date-format-parse/compare/v0.2.4...v0.2.5) (2019-11-13) | ||
@@ -2,0 +11,0 @@ |
@@ -41,5 +41,4 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123 | ||
// const matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
var YEAR = 'year'; | ||
@@ -72,2 +71,18 @@ var MONTH = 'month'; | ||
var escapeStringRegExp = function escapeStringRegExp(str) { | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); | ||
}; | ||
var matchWordRegExp = function matchWordRegExp(localeKey) { | ||
return function (locale) { | ||
var array = locale[localeKey]; | ||
if (!Array.isArray(array)) { | ||
throw new Error("Locale[".concat(localeKey, "] need an array")); | ||
} | ||
return new RegExp(array.map(escapeStringRegExp).join('|')); | ||
}; | ||
}; | ||
var matchWordCallback = function matchWordCallback(localeKey, key) { | ||
@@ -106,4 +121,4 @@ return function (input, locale) { | ||
}); | ||
addParseFlag('MMM', matchWord, matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWord, matchWordCallback('months', MONTH)); | ||
addParseFlag('MMM', matchWordRegExp('monthsShort'), matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWordRegExp('months'), matchWordCallback('months', MONTH)); | ||
addParseFlag('D', match1to2, DAY); | ||
@@ -172,5 +187,5 @@ addParseFlag('DD', match2, DAY); | ||
addParseFlag('d', match1, 'weekday'); | ||
addParseFlag('dd', matchWord, matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag('ddd', matchWord, matchWordCallback('weekdaysShort', 'weekday')); | ||
addParseFlag('dddd', matchWord, matchWordCallback('weekdays', 'weekday')); | ||
addParseFlag('dd', matchWordRegExp('weekdaysMin'), matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag('ddd', matchWordRegExp('weekdaysShort'), matchWordCallback('weekdaysShort', 'weekday')); | ||
addParseFlag('dddd', matchWordRegExp('weekdays'), matchWordCallback('weekdays', 'weekday')); | ||
addParseFlag('w', match1to2, 'week'); | ||
@@ -177,0 +192,0 @@ addParseFlag('ww', match2, 'week'); |
@@ -52,5 +52,4 @@ "use strict"; | ||
var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123 | ||
// const matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
var YEAR = 'year'; | ||
@@ -83,2 +82,18 @@ var MONTH = 'month'; | ||
var escapeStringRegExp = function escapeStringRegExp(str) { | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); | ||
}; | ||
var matchWordRegExp = function matchWordRegExp(localeKey) { | ||
return function (locale) { | ||
var array = locale[localeKey]; | ||
if (!Array.isArray(array)) { | ||
throw new Error("Locale[".concat(localeKey, "] need an array")); | ||
} | ||
return new RegExp(array.map(escapeStringRegExp).join('|')); | ||
}; | ||
}; | ||
var matchWordCallback = function matchWordCallback(localeKey, key) { | ||
@@ -117,4 +132,4 @@ return function (input, locale) { | ||
}); | ||
addParseFlag('MMM', matchWord, matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWord, matchWordCallback('months', MONTH)); | ||
addParseFlag('MMM', matchWordRegExp('monthsShort'), matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWordRegExp('months'), matchWordCallback('months', MONTH)); | ||
addParseFlag('D', match1to2, DAY); | ||
@@ -183,5 +198,5 @@ addParseFlag('DD', match2, DAY); | ||
addParseFlag('d', match1, 'weekday'); | ||
addParseFlag('dd', matchWord, matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag('ddd', matchWord, matchWordCallback('weekdaysShort', 'weekday')); | ||
addParseFlag('dddd', matchWord, matchWordCallback('weekdays', 'weekday')); | ||
addParseFlag('dd', matchWordRegExp('weekdaysMin'), matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag('ddd', matchWordRegExp('weekdaysShort'), matchWordCallback('weekdaysShort', 'weekday')); | ||
addParseFlag('dddd', matchWordRegExp('weekdays'), matchWordCallback('weekdays', 'weekday')); | ||
addParseFlag('w', match1to2, 'week'); | ||
@@ -188,0 +203,0 @@ addParseFlag('ww', match2, 'week'); |
{ | ||
"name": "date-format-parse", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Lightweight date format and parse", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -18,3 +18,3 @@ import { Unionize, PickByValue } from 'utility-types'; | ||
const matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
// const matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; // Word | ||
@@ -75,2 +75,16 @@ const YEAR = 'year'; | ||
const escapeStringRegExp = (str: string) => { | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); | ||
}; | ||
const matchWordRegExp = (localeKey: string) => { | ||
return (locale: Locale) => { | ||
const array = locale[localeKey]; | ||
if (!Array.isArray(array)) { | ||
throw new Error(`Locale[${localeKey}] need an array`); | ||
} | ||
return new RegExp(array.map(escapeStringRegExp).join('|')); | ||
}; | ||
}; | ||
const matchWordCallback = (localeKey: string, key: 'month' | 'weekday') => { | ||
@@ -101,4 +115,4 @@ return (input: string, locale: Locale) => { | ||
addParseFlag('MM', match2, input => ({ [MONTH]: parseInt(input, 10) - 1 })); | ||
addParseFlag('MMM', matchWord, matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWord, matchWordCallback('months', MONTH)); | ||
addParseFlag('MMM', matchWordRegExp('monthsShort'), matchWordCallback('monthsShort', MONTH)); | ||
addParseFlag('MMMM', matchWordRegExp('months'), matchWordCallback('months', MONTH)); | ||
addParseFlag('D', match1to2, DAY); | ||
@@ -159,5 +173,9 @@ addParseFlag('DD', match2, DAY); | ||
addParseFlag('d', match1, 'weekday'); | ||
addParseFlag('dd', matchWord, matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag('ddd', matchWord, matchWordCallback('weekdaysShort', 'weekday')); | ||
addParseFlag('dddd', matchWord, matchWordCallback('weekdays', 'weekday')); | ||
addParseFlag('dd', matchWordRegExp('weekdaysMin'), matchWordCallback('weekdaysMin', 'weekday')); | ||
addParseFlag( | ||
'ddd', | ||
matchWordRegExp('weekdaysShort'), | ||
matchWordCallback('weekdaysShort', 'weekday') | ||
); | ||
addParseFlag('dddd', matchWordRegExp('weekdays'), matchWordCallback('weekdays', 'weekday')); | ||
@@ -164,0 +182,0 @@ addParseFlag('w', match1to2, 'week'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211558
4259