Comparing version 4.1.0 to 4.2.0
@@ -0,1 +1,9 @@ | ||
4.1.0 / 2021-08-31 | ||
================== | ||
* Publish as dual-package, including a CJS fallback build | ||
4.0.0 / 2021-06-17 | ||
================== | ||
* Use native ESM module syntax | ||
3.1.0 / 2020-11-06 | ||
@@ -2,0 +10,0 @@ ================== |
{ | ||
"name": "edtf", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Extended Date Time Format (EDTF) / ISO 8601-2 Parser and Library", | ||
@@ -51,11 +51,12 @@ "type": "module", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^20.0.0", | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"c8": "^7.7.3", | ||
"chai": "^4.2.0", | ||
"eslint": "^7.12.1", | ||
"mocha": "^9.0.0", | ||
"eslint": "^8.11.0", | ||
"mocha": "^10.0.0", | ||
"rollup": "^2.56.3" | ||
} | ||
} |
@@ -18,7 +18,8 @@ # EDTF.js | ||
1. Seasons in intervals are supported at the experimental/non-standard | ||
level 3. | ||
level 3. To enable season intervals, enable `seasonIntervals` in | ||
`defaults` or when passing constraints to the parse function. | ||
### ESM | ||
Since version 4.0 EDTF.js uses Nodes.js native ESM module implementation. | ||
If you require CommonJS modules, please use package version '< 4.0'. | ||
Since version 4.1 EDTF.js is published as a dual-package. | ||
@@ -227,2 +228,4 @@ | ||
#### Tuning parser compliance | ||
By passing `level` or `types` constraints to the parser, you can ensure | ||
@@ -240,3 +243,2 @@ EDTF.js will accept only dates supported by your application. | ||
parse('2016?', { level: 0, types: ['Date'] }) #-> parse error | ||
@@ -246,2 +248,17 @@ parse('2016?', { level: 1, types: ['Date'] }) #-> ok | ||
Specific features can be enabled, | ||
regardless of `level` or `types` constraints. | ||
parse('2016-21/2016-22', { level: 1 }) #-> parse error | ||
parse('2016-21/2016-22', { | ||
level: 1, | ||
seasonIntervals: true | ||
}) #-> ok | ||
You can review or change the parser's default constraints | ||
via the `defaults` object. | ||
import { defaults } from 'edtf' | ||
defaults.level = 1 | ||
### Generator | ||
@@ -248,0 +265,0 @@ |
@@ -1,2 +0,2 @@ | ||
import LC from '../locale-data/index.cjs' | ||
import LC from '../locale-data/index.js' | ||
@@ -3,0 +3,0 @@ const { assign } = Object |
@@ -6,3 +6,4 @@ import nearley from 'nearley' | ||
level: 2, | ||
types: [] | ||
types: [], | ||
seasonIntervals: false | ||
} | ||
@@ -14,10 +15,29 @@ | ||
function limit(results, { level, types } = defaults) { | ||
function limit(results, constraints = {}) { | ||
if (!results.length) return results | ||
if (typeof level !== 'number') level = defaults.level | ||
return results.filter(res => | ||
(level >= res.level) && (!types || types.includes(res.type))) | ||
let { | ||
level, | ||
types, | ||
seasonIntervals | ||
} = { ...defaults, ...constraints } | ||
return results.filter(res => { | ||
if (seasonIntervals && isSeasonInterval(res)) | ||
return true | ||
if (res.level > level) | ||
return false | ||
if (types.length && !types.includes(res.type)) | ||
return false | ||
return true | ||
}) | ||
} | ||
function isSeasonInterval({ type, values }) { | ||
return type === 'Interval' && values[0].type === 'Season' | ||
} | ||
function best(results) { | ||
@@ -24,0 +44,0 @@ if (results.length < 2) return results[0] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
308
172902
9
42
3790
3