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

format-message-formats

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-message-formats - npm Package Compare versions

Comparing version 5.1.0 to 6.0.0-alpha.0

177

index.js

@@ -0,1 +1,8 @@

// @flow
const LONG = 'long'
const SHORT = 'short'
const NARROW = 'narrow'
const NUMERIC = 'numeric'
const TWODIGIT = '2-digit'
/**

@@ -26,26 +33,26 @@ * formatting information

short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
month: NUMERIC,
day: NUMERIC,
year: TWODIGIT
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
month: SHORT,
day: NUMERIC,
year: NUMERIC
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
month: LONG,
day: NUMERIC,
year: NUMERIC
},
full: {
month: 'long',
day: 'numeric',
year: 'numeric',
weekday: 'long'
month: LONG,
day: NUMERIC,
year: NUMERIC,
weekday: LONG
},
default: {
month: 'short',
day: 'numeric',
year: 'numeric'
month: SHORT,
day: NUMERIC,
year: NUMERIC
}

@@ -55,28 +62,134 @@ },

short: {
hour: 'numeric',
minute: 'numeric'
hour: NUMERIC,
minute: NUMERIC
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
hour: NUMERIC,
minute: NUMERIC,
second: NUMERIC
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
hour: NUMERIC,
minute: NUMERIC,
second: NUMERIC,
timeZoneName: SHORT
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
hour: NUMERIC,
minute: NUMERIC,
second: NUMERIC,
timeZoneName: SHORT
},
default: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
hour: NUMERIC,
minute: NUMERIC,
second: NUMERIC
}
},
duration: {
default: {
hours: {
minimumIntegerDigits: 1,
maximumFractionDigits: 0
},
minutes: {
minimumIntegerDigits: 2,
maximumFractionDigits: 0
},
seconds: {
minimumIntegerDigits: 2,
maximumFractionDigits: 3
}
}
},
parseNumberPattern: function (pattern/*: ?string */) {
if (!pattern) return
const options = {}
const currency = pattern.match(/\b[A-Z]{3}\b/i)
let syms = pattern.replace(/[^¤]/g, '').length
if (!syms && currency) syms = 1
if (syms) {
options.style = 'currency'
options.currencyDisplay = syms === 1 ? 'symbol' : syms === 2 ? 'code' : 'name'
options.currency = currency ? currency[0].toUpperCase() : 'USD'
} else if (pattern.indexOf('%') >= 0) {
options.style = 'percent'
}
if (!/[@#0]/.test(pattern)) return options.style ? options : undefined
options.useGrouping = pattern.indexOf(',') >= 0
if (/E\+?[@#0]+/i.test(pattern) || pattern.indexOf('@') >= 0) {
const size = pattern.replace(/E\+?[@#0]+|[^@#0]/gi, '')
options.minimumSignificantDigits = Math.min(Math.max(size.replace(/[^@0]/g, '').length, 1), 21)
options.maximumSignificantDigits = Math.min(Math.max(size.length, 1), 21)
} else {
const parts = pattern.replace(/[^#0.]/g, '').split('.')
const integer = parts[0]
let n = integer.length - 1
while (integer[n] === '0') --n
options.minimumIntegerDigits = Math.min(Math.max(integer.length - 1 - n, 1), 21)
const fraction = parts[1] || ''
n = 0
while (fraction[n] === '0') ++n
options.minimumFractionDigits = Math.min(Math.max(n, 0), 20)
while (fraction[n] === '#') ++n
options.maximumFractionDigits = Math.min(Math.max(n, 0), 20)
}
return options
},
parseDatePattern: function (pattern/*: ?string */) {
if (!pattern) return
const options = {}
for (let i = 0; i < pattern.length;) {
const current = pattern[i]
let n = 1
while (pattern[++i] === current) ++n
switch (current) {
case 'G':
options.era = n === 5 ? NARROW : n === 4 ? LONG : SHORT
break
case 'y':
case 'Y':
options.year = n === 2 ? TWODIGIT : NUMERIC
break
case 'M':
case 'L':
n = Math.min(Math.max(n - 1, 0), 4)
options.month = [ NUMERIC, TWODIGIT, SHORT, LONG, NARROW ][n]
break
case 'E':
case 'e':
case 'c':
options.weekday = n === 5 ? NARROW : n === 4 ? LONG : SHORT
break
case 'd':
case 'D':
options.day = n === 2 ? TWODIGIT : NUMERIC
break
case 'h':
case 'K':
options.hour12 = true
options.hour = n === 2 ? TWODIGIT : NUMERIC
break
case 'H':
case 'k':
options.hour12 = false
options.hour = n === 2 ? TWODIGIT : NUMERIC
break
case 'm':
options.minute = n === 2 ? TWODIGIT : NUMERIC
break
case 's':
case 'S':
options.second = n === 2 ? TWODIGIT : NUMERIC
break
case 'z':
case 'Z':
case 'v':
case 'V':
options.timeZoneName = n === 1 ? SHORT : LONG
break
}
}
return Object.keys(options).length ? options : undefined
}
}

6

package.json
{
"name": "format-message-formats",
"version": "5.1.0",
"version": "6.0.0-alpha.0",
"description": "Options for Intl APIs used by format-message",
"author": "Andy VanWagoner <thetalecrafter@gmail.com> (https://thetalecrafter.com/)",
"homepage": "https://github.com/format-message/format-message",
"author": "Andy VanWagoner <andy@thetalecrafter.com> (https://thetalecrafter.com/)",
"homepage": "https://github.com/format-message/format-message/tree/master/packages/format-message-formats",
"license": "MIT",

@@ -8,0 +8,0 @@ "repository": "format-message/format-message",

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