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

edtf

Package Overview
Dependencies
Maintainers
1
Versions
37
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.2.3 to 2.3.0

3

index.js

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

const { sample } = require('./src/sample')
const { parse } = require('./src/parser')
const { parse, defaults } = require('./src/parser')
const { format } = require('./src/format')

@@ -27,2 +27,3 @@

Bitmask,
defaults,
parse,

@@ -29,0 +30,0 @@ sample,

@@ -5,5 +5,5 @@ 'use strict'

locale.en = require('./en-US')
locale.de = require('./de-DE')
locale.fr = require('./fr-FR')
locale.en = require('./en-US.json')
locale.de = require('./de-DE.json')
locale.fr = require('./fr-FR.json')

@@ -10,0 +10,0 @@ alias('en', 'AU', 'CA', 'GB', 'NZ', 'SA', 'US')

{
"name": "edtf",
"version": "2.2.3",
"version": "2.3.0",
"description": "Extended Date Time Format (EDTF) / ISO 8601-2 Parser and Library",

@@ -13,3 +13,4 @@ "main": "index.js",

"pretest": "npm run lint",
"test": "mocha"
"test": "mocha",
"debug": "node inspect $(npm bin)/_mocha"
},

@@ -42,6 +43,6 @@ "repository": {

"chai": "^4.1.2",
"eslint": "^4.12.1",
"eslint": "^4.15.0",
"istanbul": "^0.4.3",
"mocha": "^4.0.1"
"mocha": "^4.1.0"
}
}

@@ -27,9 +27,23 @@ # EDTF.js

3. Seasons in intervals are supported at the experimental/non-standard
level 3.
### ES6
EDTF.js is written in ES6 and therefore requires Node.js 6+ or a modern
browser. For Node.js 4/5 use the appropriate `--harmony` flags as necessary.
EDTF.js is written as a standard Nodes.js / CommonJS module using many ES6
features. It therefore requires Node.js 6 or later (for Nodes.js 4/5 use the
appropriate `--harmony` flags as necessary).
### Bundling using RollUp
To bundle EDTF.js with RollUp you'll need to enable the following plugins
* rollup-plugin-json
* rollup-plugin-node-resolve
* rollup-plugin-commonjs
* rollup-plugin-node-globals (optional)
* rollup-plugin-node-builtins (optional)
The last two are optional; you need them only if you want to include Node.js
`assert` in your bundle.
## Installation
$ npm install edtf

@@ -36,0 +50,0 @@

@@ -198,27 +198,2 @@ 'use strict'

*until(then) {
yield this
if (this.compare(then)) yield* this.between(then)
}
*through(then) {
yield* this.until(then)
if (this.compare(then)) yield then
}
*between(then) {
then = Date.from(then)
let cur = this
let dir = this.compare(then)
if (!dir) return
for (;;) {
cur = cur.next(-dir)
if (cur.compare(then) !== dir) break
yield cur
}
}
*[Symbol.iterator]() {

@@ -225,0 +200,0 @@ let cur = this

@@ -20,2 +20,3 @@ // Generated automatically by nearley

{"name": "edtf", "symbols": ["L2"], "postprocess": id},
{"name": "edtf", "symbols": ["L3"], "postprocess": id},
{"name": "L0", "symbols": ["date_time"], "postprocess": id},

@@ -252,2 +253,10 @@ {"name": "L0", "symbols": ["century"], "postprocess": id},

{"name": "consecutives", "symbols": ["year", "consecutives$string$3", "year"], "postprocess": d => [date([d[0]]), date([d[2]])]},
{"name": "L3", "symbols": ["L3i"], "postprocess": id},
{"name": "L3i", "symbols": ["L3S", {"literal":"/"}, "L3S"], "postprocess": interval(3)},
{"name": "L3i", "symbols": ["L3S", {"literal":"/"}, "L3i_date"], "postprocess": interval(3)},
{"name": "L3i", "symbols": ["L3i_date", {"literal":"/"}, "L3S"], "postprocess": interval(3)},
{"name": "L3i_date", "symbols": ["date_time"], "postprocess": id},
{"name": "L3i_date", "symbols": ["L2i_date"], "postprocess": id},
{"name": "L3S", "symbols": ["L1S"], "postprocess": id},
{"name": "L3S", "symbols": ["L2S"], "postprocess": id},
{"name": "digit", "symbols": ["positive_digit"], "postprocess": id},

@@ -254,0 +263,0 @@ {"name": "digit", "symbols": [{"literal":"0"}], "postprocess": id},

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

includes(other) {

@@ -96,2 +95,27 @@ let covered = this.covers(other)

}
*until(then) {
yield this
if (this.compare(then)) yield* this.between(then)
}
*through(then) {
yield* this.until(then)
if (this.compare(then)) yield then
}
*between(then) {
then = this.constructor.from(then)
let cur = this
let dir = this.compare(then)
if (!dir) return
for (;;) {
cur = cur.next(-dir)
if (cur.compare(then) !== dir) break
yield cur
}
}
}

@@ -98,0 +122,0 @@

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

const ExtDateTime = require('./interface')
const Season = require('./season')

@@ -19,3 +20,4 @@ const V = new WeakMap()

case 2:
[this.lower, this.upper] = args
this.lower = args[0]
this.upper = args[1]
break

@@ -42,3 +44,4 @@

;[this.lower, this.upper] = obj.values
this.lower = obj.values[0]
this.upper = obj.values[1]

@@ -74,3 +77,3 @@ this.earlier = obj.earlier

value = ExtDate.from(value)
value = getDateOrSeasonFrom(value)

@@ -94,3 +97,3 @@ if (value >= this.upper && this.upper != null)

value = ExtDate.from(value)
value = getDateOrSeasonFrom(value)

@@ -138,2 +141,10 @@ if (value <= this.lower)

function getDateOrSeasonFrom(value) {
try {
return ExtDate.from(value)
} catch (de) {
return Season.from(value)
}
}
module.exports = Interval

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

const defaults = {
level: 2,
types: []
}
function byLevel(a, b) {

@@ -11,5 +16,5 @@ return a.level < b.level ? -1 : a.level > b.level ? 1 : 0

function limit(results, { level, types }) {
function limit(results, { level, types } = defaults) {
if (!results.length) return results
if (typeof level !== 'number') level = 2
if (typeof level !== 'number') level = defaults.level

@@ -29,2 +34,3 @@ return results.filter(res =>

module.exports = {
defaults,

@@ -31,0 +37,0 @@ parse(input, constraints = {}) {

@@ -90,4 +90,5 @@ /*

.join('')
.replace(/ +/g, '') // filter excessive whitespace
.replace(/ +/g, '') // remove excessive whitespace
.replace(/-0000/, '0000') // filter negative year zero
}
}

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

set season(season) {
return this.values[1] = Number(season)
return validate(this.values[1] = Number(season))
}

@@ -72,4 +72,26 @@

// TODO next/prev
next(k = 1) {
let { season, year } = this
switch (true) {
case (season >= 21 && season <= 36):
[year, season] = inc(year, season, k, season - (season - 21) % 4, 4)
break
case (season >= 37 && season <= 39):
[year, season] = inc(year, season, k, 37, 3)
break
case (season >= 40 && season <= 41):
[year, season] = inc(year, season, k, 40, 2)
break
default:
throw new RangeError(`Cannot compute next/prev for season ${season}`)
}
return new Season(year, season)
}
prev(k = 1) {
return this.next(-k)
}
get min() { // eslint-disable-line complexity

@@ -160,2 +182,17 @@ switch (this.season) {

function validate(season) {
if (isNaN(season) || season < 21 || season === Infinity)
throw new RangeError(`invalid division of year: ${season}`)
return season
}
function inc(year, season, by, base, size) {
const m = (season + by) - base
return [
year + Math.floor(m / size),
validate(base + (m % size + size) % size)
]
}
module.exports = Season
'use strict'
const { Interval, Date } = require('..')
const { Interval, Date, Season } = require('..')

@@ -65,2 +65,24 @@ describe('Interval', () => {

})
describe('seasons (non-standard)', () => {
const S80 = new Interval('1980-21', '1980-24')
it('.lower', () => {
expect(S80.lower).to.be.instanceof(Season)
})
it('.edtf', () => {
expect(S80.toEDTF()).to.be.eql('1980-21/1980-24')
})
it('.covers', () => {
expect(S80.covers(new Season(1980, 22))).to.be.true
expect(S80.covers(new Date(1980, 8))).to.be.true
})
it('.includes', () => {
expect(S80.includes(new Season(1980, 22))).to.be.true
expect(S80.includes(new Date(1980, 8))).to.be.false
})
})
})

@@ -534,2 +534,20 @@ 'use strict'

describe('Level 3 (Non-Standard)', () => {
it('YYYY-SS/YYYY-SS', () =>
expect(p('2018-21/2018-23', { level: 3 }))
.to.be.an.interval.through([2018, 23]).at.level(3))
it('YYYY/YYYY-SS', () =>
expect(p('2018/2018-23', { level: 3 }))
.to.be.an.interval.through([2018, 23]).at.level(3))
it('YYYY-SS/YYYY-MM-DD', () =>
expect(p('2018-21/2017-01-01', { level: 3 }))
.to.be.an.interval.from([2018, 21]).at.level(3))
it('YYYY-01?/YYYY-SS', () =>
expect(p('2018-01?/2018-23', { level: 3 }))
.to.be.an.interval.through([2018, 23]).at.level(3))
})
describe('constrain', () => {

@@ -556,3 +574,4 @@ it('by type', () => {

expect(() => p('1800/1X01', { level: 2, types: ['Date'] })).to.be.rejected
expect(() => p('1800/1X01', { level: 2, types: ['Date'] }))
.to.be.rejected
expect(() => p('1800/1X01', { level: 1, types: ['Interval'] }))

@@ -559,0 +578,0 @@ .to.be.rejected

@@ -23,2 +23,20 @@ 'use strict'

describe('.next', () => {
it('positive', () => {
expect(new Season(2018, 21).next().toEDTF()).to.eql('2018-22')
expect(new Season(2018, 21).next(2).toEDTF()).to.eql('2018-23')
expect(new Season(2018, 21).next(3).toEDTF()).to.eql('2018-24')
expect(new Season(2018, 21).next(4).toEDTF()).to.eql('2019-21')
expect(new Season(2018, 25).next(9).toEDTF()).to.eql('2020-26')
})
it('negative', () => {
expect(new Season(2018, 24).next(-1).toEDTF()).to.eql('2018-23')
expect(new Season(2018, 24).next(-2).toEDTF()).to.eql('2018-22')
expect(new Season(2018, 24).next(-3).toEDTF()).to.eql('2018-21')
expect(new Season(2018, 24).next(-4).toEDTF()).to.eql('2017-24')
expect(new Season(2018, 24).next(-9).toEDTF()).to.eql('2016-23')
})
})
describe('.edtf', () => {

@@ -25,0 +43,0 @@ it('default', () =>

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