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

format-message

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-message - npm Package Compare versions

Comparing version 6.0.1 to 6.0.3

26

base-format-children.js

@@ -24,14 +24,14 @@ // @flow

// at least one word character (letter, digit, or _) surrounded by < >
const wrappingToken = /<(\w+)>/g
var wrappingToken = /<(\w+)>/g
// at least one word character (letter, digit, or _) surrounded by < />
const selfClosingToken = /<(\w+)\/>/g
var selfClosingToken = /<(\w+)\/>/g
const results = []
let match, token, i, split, result
var results = []
var match, token, i, split, result
// check that wrapping tokens are properly nested
const tokens = []
var tokens = []
while ((match = wrappingToken.exec(message)) !== null) {
const key = match[1]
var key = match[1]
token = {

@@ -60,7 +60,7 @@ key: key,

// get the text in between the token
const start = message.lastIndexOf('<' + token.key + '>')
const end = message.lastIndexOf('</' + token.key + '>')
const value = message.substring(start + token.key.length + 2, end)
var start = message.lastIndexOf('<' + token.key + '>')
var end = message.lastIndexOf('</' + token.key + '>')
var value = message.substring(start + token.key.length + 2, end)
const children = []
var children = []

@@ -70,3 +70,3 @@ // add all children between the token, replacing any self closing tokens

split = value.split(selfClosingToken)
for (let j = 0; j < split.length; ++j) {
for (var j = 0; j < split.length; ++j) {
result = split[j]

@@ -86,4 +86,4 @@

const left = message.substring(0, start)
const right = message.substring(end + token.key.length + 3)
var left = message.substring(0, start)
var right = message.substring(end + token.key.length + 3)
message = left + '<__' + i + '__/>' + right

@@ -90,0 +90,0 @@ }

# Changelog
## 6.0.3
Use `var` declarations for wider compatibility.
## 6.0.0

@@ -4,0 +8,0 @@

// @flow
'use strict'
const parse = require('format-message-parse')
const interpret = require('format-message-interpret')
const plurals = require('format-message-interpret/plurals')
const lookupClosestLocale = require('lookup-closest-locale')
const origFormats = require('format-message-formats')
var parse = require('format-message-parse')
var interpret = require('format-message-interpret')
var plurals = require('format-message-interpret/plurals')
var lookupClosestLocale = require('lookup-closest-locale')
var origFormats = require('format-message-formats')

@@ -75,15 +75,15 @@ /*::

function namespace ()/*: FormatMessage */ {
const formats = assign({}, origFormats)
let currentLocales/*: Locales */ = 'en'
let translations/*: Translations */ = {}
let generateId/*: GenerateId */ = function (pattern) { return pattern }
let missingReplacement/*: Replacement */ = null
let missingTranslation/*: MissingTranslation */ = 'warning'
let types/*: Types */ = {}
var formats = assign({}, origFormats)
var currentLocales/*: Locales */ = 'en'
var translations/*: Translations */ = {}
var generateId/*: GenerateId */ = function (pattern) { return pattern }
var missingReplacement/*: Replacement */ = null
var missingTranslation/*: MissingTranslation */ = 'warning'
var types/*: Types */ = {}
function formatMessage (msg/*: Message */, args/*:: ?: Object */, locales/*:: ?: Locales */) {
const pattern = typeof msg === 'string' ? msg : msg.default
const id = (typeof msg === 'object' && msg.id) || generateId(pattern)
const translated = translate(pattern, id, locales || currentLocales)
const format = translated.format || (
var pattern = typeof msg === 'string' ? msg : msg.default
var id = (typeof msg === 'object' && msg.id) || generateId(pattern)
var translated = translate(pattern, id, locales || currentLocales)
var format = translated.format || (
translated.format = interpret(parse(translated.message), locales || currentLocales, types)

@@ -95,6 +95,6 @@ )

formatMessage.rich = function rich (msg/*: Message */, args/*:: ?: Object */, locales/*:: ?: Locales */) {
const pattern = typeof msg === 'string' ? msg : msg.default
const id = (typeof msg === 'object' && msg.id) || generateId(pattern)
const translated = translate(pattern, id, locales || currentLocales)
const format = translated.toParts || (
var pattern = typeof msg === 'string' ? msg : msg.default
var id = (typeof msg === 'object' && msg.id) || generateId(pattern)
var translated = translate(pattern, id, locales || currentLocales)
var format = translated.toParts || (
translated.toParts = interpret.toParts(parse(pattern, { tagsType: tagsType }), locales || currentLocales, types)

@@ -105,7 +105,7 @@ )

const tagsType = '<>'
var tagsType = '<>'
function richType (node/*: any[] */, locales/*: Locales */) {
const style = node[2]
var style = node[2]
return function (fn, args) {
const props = typeof style === 'object' ? mapObject(style, args) : style
var props = typeof style === 'object' ? mapObject(style, args) : style
return typeof fn === 'function' ? fn(props) : fn

@@ -124,5 +124,5 @@ }

function translate (pattern/*: string */, id/*: string */, locales/*: Locales */)/*: Translation */ {
const locale = lookupClosestLocale(locales, translations) || 'en'
const messages = translations[locale] || (translations[locale] = {})
let translated = messages[id]
var locale = lookupClosestLocale(locales, translations) || 'en'
var messages = translations[locale] || (translations[locale] = {})
var translated = messages[id]
if (typeof translated === 'string') {

@@ -132,3 +132,3 @@ translated = messages[id] = { message: translated }

if (!translated) {
const message = 'Translation for "' + id + '" in "' + locale + '" is missing'
var message = 'Translation for "' + id + '" in "' + locale + '" is missing'
if (missingTranslation === 'warning') {

@@ -140,3 +140,3 @@ /* istanbul ignore else */

}
const replacement = typeof missingReplacement === 'function'
var replacement = typeof missingReplacement === 'function'
? missingReplacement(pattern, id, locale) || pattern

@@ -177,20 +177,20 @@ : missingReplacement || pattern

formatMessage.number = function (value/*: number */, style/*:: ?: string */, locales/*:: ?: Locales */) {
const options = (style && formats.number[style]) ||
var options = (style && formats.number[style]) ||
formats.parseNumberPattern(style) ||
formats.number.default
return value.toLocaleString(locales || currentLocales, options)
return new Intl.NumberFormat(locales || currentLocales, options).format(value)
}
formatMessage.date = function (value/*: number | Date */, style/*:: ?: string */, locales/*:: ?: Locales */) {
const options = (style && formats.date[style]) ||
formatMessage.date = function (value/*:: ?: number | Date */, style/*:: ?: string */, locales/*:: ?: Locales */) {
var options = (style && formats.date[style]) ||
formats.parseDatePattern(style) ||
formats.date.default
return new Date(value).toLocaleDateString(locales || currentLocales, options)
return new Intl.DateTimeFormat(locales || currentLocales, options).format(value)
}
formatMessage.time = function (value/*: number | Date */, style/*:: ?: string */, locales/*:: ?: Locales */) {
const options = (style && formats.time[style]) ||
formatMessage.time = function (value/*:: ?: number | Date */, style/*:: ?: string */, locales/*:: ?: Locales */) {
var options = (style && formats.time[style]) ||
formats.parseDatePattern(style) ||
formats.time.default
return new Date(value).toLocaleTimeString(locales || currentLocales, options)
return new Intl.DateTimeFormat(locales || currentLocales, options).format(value)
}

@@ -221,4 +221,4 @@

}
const closest = lookupClosestLocale(locale || currentLocales, plurals)
const plural = (closest && plurals[closest][pluralType]) || returnOther
var closest = lookupClosestLocale(locale || currentLocales, plurals)
var plural = (closest && plurals[closest][pluralType]) || returnOther
return options['=' + +value] || options[plural(value - offset)] || options.other

@@ -225,0 +225,0 @@ }

// @flow
'use strict'
const formatChildren = require('./base-format-children')
var formatChildren = require('./base-format-children')

@@ -5,0 +5,0 @@ function applyChildren (key/*: string */, element/*: any */, children/*: ?mixed[] */) {

{
"name": "format-message",
"version": "6.0.1",
"version": "6.0.3",
"description": "Internationalize text, numbers, and dates using ICU Message Format",

@@ -24,7 +24,7 @@ "author": "Andy VanWagoner <andy@thetalecrafter.com> (https://thetalecrafter.com/)",

"dependencies": {
"format-message-formats": "^6.0.0",
"format-message-interpret": "^6.0.0",
"format-message-parse": "^6.0.0",
"lookup-closest-locale": "^6.0.0"
"format-message-formats": "^6.0.3",
"format-message-interpret": "^6.0.3",
"format-message-parse": "^6.0.3",
"lookup-closest-locale": "^6.0.3"
}
}
// @flow
'use strict'
const React = require('react')
const formatChildren = require('./base-format-children')
var React = require('react')
var formatChildren = require('./base-format-children')

@@ -6,0 +6,0 @@ function applyChildren (key/*: string */, element/*: any */, children/*: ?mixed[] */) {

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