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.1.0 to 2.2.0

locale-data/en-US.json

8

CHANGELOG.md

@@ -0,1 +1,9 @@

2.2.0 / 2017-09-06
==================
* Implement date formatting (non-standard)
2.1.0 / 2017-02-17
==================
* Support negative masked dates
* Support negative masked years
2.0.0 / 2016-08-17

@@ -2,0 +10,0 @@ ==================

12

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

@@ -11,3 +11,3 @@ "main": "index.js",

"coverage": "istanbul cover _mocha",
"prepublish": "npm run compile",
"prepare": "npm run compile",
"pretest": "npm run lint",

@@ -37,11 +37,11 @@ "test": "mocha"

"dependencies": {
"nearley": "^2.5.0",
"randexp": "^0.4.2"
"nearley": "^2.11.0",
"randexp": "^0.4.6"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^3.3.1",
"eslint": "^3.19.0",
"istanbul": "^0.4.3",
"mocha": "^3.0.2"
"mocha": "^3.5.0"
}
}

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

const { isArray } = Array
const { defineProperty: prop } = Object

@@ -90,6 +89,2 @@ const P = new WeakMap()

this.unspecified = unspecified
prop(this, 'format', {
value: format.bind(null, this)
})
}

@@ -259,4 +254,4 @@

localize(...args) {
return this.format(...args).format(this)
format(...args) {
return format(this, ...args)
}

@@ -263,0 +258,0 @@

'use strict'
const { assign } = Object
const LC = require('../locale-data')
function format(date, locale, options = {}) {
const noTime = {
timeZoneName: undefined,
hour: undefined,
minute: undefined,
second: undefined
}
const DEFAULTS = [
assign({ weekday: undefined, day: undefined, month: undefined }, noTime),
assign({ weekday: undefined, day: undefined }, noTime),
assign({}, noTime),
]
function getFormat(date, locale, options) {
const defaults = {}

@@ -10,28 +24,73 @@

case 3:
if (options.weekday) defaults.weekday = options.weekday
else defaults.day = options.day || 'numeric'
defaults.day = 'numeric'
// eslint-disable-next-line no-fallthrough
case 2:
defaults.month = options.month || 'numeric'
defaults.month = 'numeric'
// eslint-disable-next-line no-fallthrough
case 1:
defaults.year = options.year || 'numeric'
defaults.year = 'numeric'
break
}
defaults.hour = undefined
defaults.minute = undefined
defaults.second = undefined
defaults.timeZoneName = undefined
return new Intl.DateTimeFormat(
locale,
assign(defaults, options, DEFAULTS[date.precision])
)
}
break
function getPatternsFor(fmt) {
const { locale, weekday, month, year } = fmt.resolvedOptions()
const lc = LC[locale]
if (lc == null) return null
const variant = (weekday || month === 'long') ? 'long' :
(!month || year === '2-digit') ? 'short' : 'medium'
return {
approximate: lc.date.approximate[variant],
uncertain: lc.date.uncertain[variant]
}
}
return new Intl.DateTimeFormat(locale, assign({}, options, defaults))
function isDMY(type) {
return type === 'day' || type === 'month' || type === 'year'
}
function format(date, locale = 'en-US', options = {}) {
const fmt = getFormat(date, locale, options)
const pat = getPatternsFor(fmt)
if (!date.isEDTF || pat == null) {
return fmt.format(date)
}
let string = ''
if (date.unspecified.value && typeof fmt.formatToParts === 'function') {
for (let { type, value } of fmt.formatToParts(date)) {
string += (isDMY(type) && date.unspecified.is(type)) ?
value.replace(/./g, 'X') :
value
}
} else {
string = fmt.format(date)
}
if (date.approximate.value) {
string = pat.approximate.replace('%D', string)
}
if (date.uncertain.value) {
string = pat.uncertain.replace('%D', string)
}
return string
}
module.exports = {
getFormat,
format
}

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

var grammar = {
Lexer: undefined,
ParserRules: [

@@ -353,3 +354,3 @@ {"name": "edtf", "symbols": ["L0"], "postprocess": id},

{"name": "_$ebnf$1", "symbols": []},
{"name": "_$ebnf$1", "symbols": [{"literal":" "}, "_$ebnf$1"], "postprocess": function arrconcat(d) {return [d[0]].concat(d[1]);}},
{"name": "_$ebnf$1", "symbols": ["_$ebnf$1", {"literal":" "}], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "_", "symbols": ["_$ebnf$1"]}

@@ -356,0 +357,0 @@ ]

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

get isEDTF() {
return true
}
toJSON() {

@@ -39,0 +43,0 @@ return this.toEDTF()

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