Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edtf

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edtf - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

2

package.json
{
"name": "edtf",
"version": "2.0.1",
"version": "2.1.0",
"description": "Extended Date Time Format (EDTF) / ISO 8601-2 Parser and Library",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -240,6 +240,7 @@ 'use strict'

let sign = (this.year < 0) ? '-' : ''
let values = this.values.map(Date.pad)
if (this.unspecified.value)
return this.unspecified.masks(values).join('-')
return sign + this.unspecified.masks(values).join('-')

@@ -254,3 +255,3 @@ if (this.uncertain.value)

return values.join('-')
return sign + values.join('-')
}

@@ -262,12 +263,11 @@

static pad(number, idx = 0) { // idx 0 = year, 1 = month, ...
if (!idx) {
static pad(number, idx = 0) {
if (!idx) { // idx 0 = year, 1 = month, ...
let k = abs(number)
let sign = (k === number) ? '' : '-'
if (k < 10) return `${sign}000${k}`
if (k < 100) return `${sign}00${k}`
if (k < 1000) return `${sign}0${k}`
if (k < 10) return `000${k}`
if (k < 100) return `00${k}`
if (k < 1000) return `0${k}`
return `${number}`
return `${k}`
}

@@ -274,0 +274,0 @@

@@ -100,14 +100,14 @@ // Generated automatically by nearley

{"name": "L1X$string$1", "symbols": [{"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["d4", {"literal":"-"}, "md", "L1X$string$1"], "postprocess": masked()},
{"name": "L1X", "symbols": ["nd4", {"literal":"-"}, "md", "L1X$string$1"], "postprocess": masked()},
{"name": "L1X$string$2", "symbols": [{"literal":"-"}, {"literal":"X"}, {"literal":"X"}, {"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["d4", "L1X$string$2"], "postprocess": masked()},
{"name": "L1X", "symbols": ["nd4", "L1X$string$2"], "postprocess": masked()},
{"name": "L1X$string$3", "symbols": [{"literal":"X"}, {"literal":"X"}, {"literal":"X"}, {"literal":"X"}, {"literal":"-"}, {"literal":"X"}, {"literal":"X"}, {"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["L1X$string$3"], "postprocess": masked()},
{"name": "L1X$string$4", "symbols": [{"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["d4", "L1X$string$4"], "postprocess": masked()},
{"name": "L1X", "symbols": ["nd4", "L1X$string$4"], "postprocess": masked()},
{"name": "L1X$string$5", "symbols": [{"literal":"X"}, {"literal":"X"}, {"literal":"X"}, {"literal":"X"}, {"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["L1X$string$5"], "postprocess": masked()},
{"name": "L1X$string$6", "symbols": [{"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["d2", "L1X$string$6"], "postprocess": masked()},
{"name": "L1X", "symbols": ["d3", {"literal":"X"}], "postprocess": masked()},
{"name": "L1X", "symbols": ["nd2", "L1X$string$6"], "postprocess": masked()},
{"name": "L1X", "symbols": ["nd3", {"literal":"X"}], "postprocess": masked()},
{"name": "L1X$string$7", "symbols": [{"literal":"X"}, {"literal":"X"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},

@@ -255,2 +255,8 @@ {"name": "L1X", "symbols": ["L1X$string$7"], "postprocess": masked()},

{"name": "digits", "symbols": ["digits", "digit"], "postprocess": join},
{"name": "nd4", "symbols": ["d4"]},
{"name": "nd4", "symbols": [{"literal":"-"}, "d4"], "postprocess": join},
{"name": "nd3", "symbols": ["d3"]},
{"name": "nd3", "symbols": [{"literal":"-"}, "d3"], "postprocess": join},
{"name": "nd2", "symbols": ["d2"]},
{"name": "nd2", "symbols": [{"literal":"-"}, "d2"], "postprocess": join},
{"name": "d4", "symbols": ["d2", "d2"], "postprocess": join},

@@ -265,2 +271,3 @@ {"name": "d3", "symbols": ["d2", "digit"], "postprocess": join},

{"name": "dx4", "symbols": ["dx2", "dx2"], "postprocess": join},
{"name": "dx4", "symbols": [{"literal":"-"}, "dx2", "dx2"], "postprocess": join},
{"name": "md", "symbols": ["m31"], "postprocess": id},

@@ -267,0 +274,0 @@ {"name": "md", "symbols": ["m30"], "postprocess": id},

@@ -154,3 +154,3 @@ 'use strict'

toEDTF() {
return `${pad(this.year)}-${this.season}`
return `${this.year < 0 ? '-' : ''}${pad(this.year)}-${this.season}`
}

@@ -157,0 +157,0 @@ }

@@ -52,7 +52,14 @@ 'use strict'

return (data, _, reject) => {
let mask = data.join('').replace(/-/g, '')
data = data.join('')
return mask.indexOf(symbol) === -1 ? reject : {
values: Bitmask.values(mask),
[type]: Bitmask.compute(mask)
let negative = data.startsWith('-')
let mask = data.replace(/-/g, '')
if (mask.indexOf(symbol) === -1) return reject
let values = Bitmask.values(mask, 0)
if (negative) values[0] = -values[0]
return {
values, [type]: Bitmask.compute(mask)
}

@@ -59,0 +66,0 @@ }

@@ -84,3 +84,3 @@ 'use strict'

if (y < 9999) return `${pad(this.year)}${s}`
if (y <= 9999) return `${this.year < 0 ? '-' : ''}${pad(this.year)}${s}`

@@ -87,0 +87,0 @@ // TODO exponential form for ending zeroes

@@ -180,2 +180,3 @@ 'use strict'

it('YYYY-XX', () => {
expect(Date.from('2016-XX').values).to.eql([2016, 0])
expect(Date.from('2016-XX').max)

@@ -185,3 +186,8 @@ .to.eql(global.Date.UTC(2016, 11, 31, 23, 59, 59, 999))

it('-YYYY-XX', () => {
expect(Date.from('-2016-XX').values).to.eql([-2016, 0])
})
it('YYXX', () => {
expect(Date.from('20XX').values).to.eql([2000])
expect(Date.from('20XX').max)

@@ -191,2 +197,6 @@ .to.eql(global.Date.UTC(2099, 11, 31, 23, 59, 59, 999))

it('-YYXX', () => {
expect(Date.from('-20XX').values).to.eql([-2000])
})
it('YYYX', () => {

@@ -197,2 +207,7 @@ expect(Date.from('201X').max)

it('-YYYX', () => {
expect(Date.from('-201X').values).to.eql([-2010])
})
it('XXXX', () => {

@@ -312,2 +327,6 @@ expect(Date.from('XXXX').max)

it('-XYXY', () => {
expect(Date.from('-X0X6').values).to.eql([-6])
})
it('XYXX', () => {

@@ -460,2 +479,6 @@ expect(Date.from('X0XX').max)

it('-YYXX-MM-DD', () =>
expect(new Date({ values: [-300, 3, 15], unspecified: 'yyxxmmdd' }).edtf)
.to.eql('-03XX-04-15'))
it('YXYX-MX-DD', () =>

@@ -462,0 +485,0 @@ expect(new Date({ values: [2014, 3, 15], unspecified: 'yxyxmxdd' }).edtf)

@@ -36,4 +36,17 @@ 'use strict'

for (let string of [
'2016', '2016-05', '2016-05-31', '2016?', '2016-05?',
'2016-05-31?', '2016~-05?', '2016-~05'
'2016',
'2016-05',
'2016-05-31',
'2016?',
'2016-05?',
'2016-05-31?',
'2016~-05?',
'2016-~05',
'20XX',
'2XX6',
'-0300',
'-0300~',
'03XX',
'-0300-XX',
'-03XX'

@@ -40,0 +53,0 @@ ]) expect(edtf(string).edtf).to.eql(string)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc