Comparing version 3.0.1 to 3.1.0
@@ -0,1 +1,5 @@ | ||
3.1.0 / 2020-11-06 | ||
================== | ||
* Support '..' affix for earlier/later in inclusive lists | ||
3.0.0 / 2020-06-30 | ||
@@ -2,0 +6,0 @@ ================== |
36
index.js
'use strict' | ||
const edtf = require('./src/edtf') | ||
const Bitmask = require('./src/bitmask') | ||
const types = require('./src/types') | ||
const { sample } = require('./src/sample') | ||
const { parse, defaults } = require('./src/parser') | ||
const { format } = require('./src/format') | ||
const { assign, keys } = Object | ||
const UNIX_TIME = /^\d{5,}$/ | ||
function edtf(...args) { | ||
if (!args.length) | ||
return new edtf.Date() | ||
if (args.length === 1) { | ||
switch (typeof args[0]) { | ||
case 'object': | ||
return new (edtf[args[0].type] || edtf.Date)(args[0]) | ||
case 'number': | ||
return new edtf.Date(args[0]) | ||
case 'string': | ||
if ((UNIX_TIME).test(args[0])) | ||
return new edtf.Date(Number(args[0])) | ||
} | ||
} | ||
let res = parse(...args) | ||
return new edtf[res.type](res) | ||
} | ||
module.exports = assign(edtf, types, { | ||
module.exports = Object.assign(edtf, types, { | ||
Bitmask, | ||
defaults, | ||
parse, | ||
sample, | ||
format, | ||
types: keys(types) | ||
get sample() { | ||
return require('./src/sample').sample | ||
}, | ||
types: Object.keys(types) | ||
}) |
{ | ||
"name": "edtf", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Extended Date Time Format (EDTF) / ISO 8601-2 Parser and Library", | ||
"main": "index.js", | ||
"type": "commonjs", | ||
"main": "./index.js", | ||
"module": "./index.mjs", | ||
"exports": { | ||
"import": "./index.mjs", | ||
"require": "./index.js" | ||
}, | ||
"scripts": { | ||
@@ -37,3 +43,5 @@ "lint": "eslint src test", | ||
"dependencies": { | ||
"nearley": "^2.19.4", | ||
"nearley": "^2.19.7" | ||
}, | ||
"optionalDependencies": { | ||
"randexp": "^0.5.3" | ||
@@ -43,6 +51,6 @@ }, | ||
"chai": "^4.2.0", | ||
"eslint": "^7.3.1", | ||
"eslint": "^7.12.1", | ||
"istanbul": "^0.4.3", | ||
"mocha": "^8.0.1" | ||
"mocha": "^8.2.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
// Generated automatically by nearley, version 2.19.4 | ||
// Generated automatically by nearley, version 2.19.7 | ||
// http://github.com/Hardmath123/nearley | ||
@@ -258,2 +258,4 @@ (function () { | ||
{"name": "LLB", "symbols": [{"literal":"{"}], "postprocess": () => ({ type: 'List' })}, | ||
{"name": "LLB$string$1", "symbols": [{"literal":"{"}, {"literal":"."}, {"literal":"."}], "postprocess": function joiner(d) {return d.join('');}}, | ||
{"name": "LLB", "symbols": ["LLB$string$1"], "postprocess": () => ({ type: 'List', earlier: true })}, | ||
{"name": "RSB", "symbols": [{"literal":"]"}], "postprocess": nothing}, | ||
@@ -263,2 +265,4 @@ {"name": "RSB$string$1", "symbols": [{"literal":"."}, {"literal":"."}, {"literal":"]"}], "postprocess": function joiner(d) {return d.join('');}}, | ||
{"name": "RLB", "symbols": [{"literal":"}"}], "postprocess": nothing}, | ||
{"name": "RLB$string$1", "symbols": [{"literal":"."}, {"literal":"."}, {"literal":"}"}], "postprocess": function joiner(d) {return d.join('');}}, | ||
{"name": "RLB", "symbols": ["RLB$string$1"], "postprocess": () => ({ later: true })}, | ||
{"name": "OL", "symbols": ["LI"], "postprocess": data => [data[0]]}, | ||
@@ -265,0 +269,0 @@ {"name": "OL", "symbols": ["OL", "_", {"literal":","}, "_", "LI"], "postprocess": data => [...data[0], data[4]]}, |
@@ -37,2 +37,5 @@ 'use strict' | ||
this.concat(...obj.values) | ||
this.earlier = !!obj.earlier | ||
this.later = !!obj.later | ||
} | ||
@@ -97,7 +100,7 @@ break | ||
get min() { | ||
return this.empty ? 0 : this.first.min | ||
return this.earlier ? -Infinity : (this.empty ? 0 : this.first.min) | ||
} | ||
get max() { | ||
return this.empty ? 0 : this.last.max | ||
return this.later ? Infinity : (this.empty ? 0 : this.last.max) | ||
} | ||
@@ -113,6 +116,13 @@ | ||
toEDTF() { | ||
return `{${this.content()}}` | ||
return this.wrap(this.empty ? | ||
'' : | ||
`${this.earlier ? '..' : ''}${this.content()}${this.later ? '..' : ''}` | ||
) | ||
} | ||
wrap(content) { | ||
return `{${content}}` | ||
} | ||
} | ||
module.exports = List |
@@ -11,11 +11,2 @@ 'use strict' | ||
constructor(obj) { | ||
super(...arguments) | ||
if (obj && typeof obj === 'object') { | ||
this.earlier = !!obj.earlier | ||
this.later = !!obj.later | ||
} | ||
} | ||
get type() { | ||
@@ -25,17 +16,7 @@ return 'Set' | ||
get min() { | ||
return this.earlier ? -Infinity : super.min | ||
wrap(content) { | ||
return `[${content}]` | ||
} | ||
get max() { | ||
return this.later ? Infinity : super.max | ||
} | ||
toEDTF() { | ||
return this.empty ? '[]' : [ | ||
this.earlier ? '[..' : '[', this.content(), this.later ? '..]' : ']' | ||
].join('') | ||
} | ||
} | ||
module.exports = Set |
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
126967
32
2026
- Removedrandexp@^0.5.3
Updatednearley@^2.19.7