@formatjs/intl-utils
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -6,2 +6,19 @@ # Change Log | ||
# [2.1.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-utils@2.0.4...@formatjs/intl-utils@2.1.0) (2020-01-22) | ||
### Bug Fixes | ||
* **@formatjs/intl-unified-numberformat:** fix moar test262 cases ([#464](https://github.com/formatjs/formatjs/issues/464)) ([c3bec6e](https://github.com/formatjs/formatjs/commit/c3bec6e9dda928a48c8ecda7a9e515da7790fde1)) | ||
* **@formatjs/intl-unified-numberformat:** fix some 262 test cases ([3e8e931](https://github.com/formatjs/formatjs/commit/3e8e931a9a7bc6901ac7c89f10f8bf19e9fa0fca)) | ||
### Features | ||
* **@formatjs/intl-displaynames:** initial commit ([#469](https://github.com/formatjs/formatjs/issues/469)) ([137b994](https://github.com/formatjs/formatjs/commit/137b994846526b02de80b024c860b2771868f236)) | ||
## [2.0.4](https://github.com/formatjs/formatjs/compare/@formatjs/intl-utils@2.0.3...@formatjs/intl-utils@2.0.4) (2020-01-09) | ||
@@ -8,0 +25,0 @@ |
export { selectUnit } from './diff'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, LiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, } from './polyfill-utils'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, LiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, isWellFormedCurrencyCode, toString, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -10,3 +10,4 @@ export * from './units'; | ||
export * from './number-types'; | ||
export * from './displaynames-types'; | ||
export { getCanonicalLocales } from './get-canonical-locales'; | ||
export { invariant } from './invariant'; |
@@ -23,2 +23,4 @@ "use strict"; | ||
exports.objectIs = polyfill_utils_1.objectIs; | ||
exports.isWellFormedCurrencyCode = polyfill_utils_1.isWellFormedCurrencyCode; | ||
exports.toString = polyfill_utils_1.toString; | ||
var resolve_locale_1 = require("./resolve-locale"); | ||
@@ -25,0 +27,0 @@ exports.createResolveLocale = resolve_locale_1.createResolveLocale; |
@@ -8,2 +8,6 @@ import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions } from './number-types'; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
export declare function toString(o: unknown): string; | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
@@ -65,1 +69,6 @@ * @param opts | ||
export declare function objectIs(x: any, y: any): boolean; | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
export declare function isWellFormedCurrencyCode(currency: string): boolean; |
@@ -18,2 +18,13 @@ "use strict"; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
function toString(o) { | ||
// Only symbol is irregular... | ||
if (typeof o === 'symbol') { | ||
throw TypeError('Cannot convert a Symbol value to a string'); | ||
} | ||
return String(o); | ||
} | ||
exports.toString = toString; | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
@@ -37,6 +48,6 @@ * @param opts | ||
if (type === 'string') { | ||
value = String(value); | ||
value = toString(value); | ||
} | ||
if (values !== undefined && !values.filter(function (val) { return val == value; }).length) { | ||
throw new RangeError(value + " in not within " + values); | ||
throw new RangeError(value + " is not within " + values.join(', ')); | ||
} | ||
@@ -106,3 +117,4 @@ return value; | ||
function setMultiInternalSlots(map, pl, props) { | ||
for (var k in props) { | ||
for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) { | ||
var k = _a[_i]; | ||
setInternalSlot(map, pl, k, props[k]); | ||
@@ -220,1 +232,24 @@ } | ||
exports.objectIs = objectIs; | ||
var NOT_A_Z_REGEX = /[^A-Z]/; | ||
/** | ||
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping | ||
* @param str string to convert | ||
*/ | ||
function toUpperCase(str) { | ||
return str.replace(/([a-z])/g, function (_, c) { return c.toUpperCase(); }); | ||
} | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
function isWellFormedCurrencyCode(currency) { | ||
currency = toUpperCase(currency); | ||
if (currency.length !== 3) { | ||
return false; | ||
} | ||
if (NOT_A_Z_REGEX.test(currency)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.isWellFormedCurrencyCode = isWellFormedCurrencyCode; |
export { selectUnit } from './diff'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, LiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, } from './polyfill-utils'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, LiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, isWellFormedCurrencyCode, toString, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -10,3 +10,4 @@ export * from './units'; | ||
export * from './number-types'; | ||
export * from './displaynames-types'; | ||
export { getCanonicalLocales } from './get-canonical-locales'; | ||
export { invariant } from './invariant'; |
export { selectUnit } from './diff'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, } from './polyfill-utils'; | ||
export { defaultNumberOption, getAliasesByLang, getInternalSlot, getMultiInternalSlots, getNumberOption, getOption, getParentLocalesByLang, isLiteralPart, partitionPattern, setInternalSlot, setMultiInternalSlots, setNumberFormatDigitOptions, toObject, objectIs, isWellFormedCurrencyCode, toString, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -4,0 +4,0 @@ export * from './units'; |
@@ -11,2 +11,4 @@ | ||
declare type CurrencyCode = string; | ||
export declare interface CurrencyData { | ||
@@ -53,2 +55,44 @@ displayName: LDMLPluralRuleMap<string>; | ||
export declare interface DisplayNamesData { | ||
/** | ||
* Note that for style fields, `short` and `narrow` might not exist. | ||
* At runtime, the fallback order will be narrow -> short -> long. | ||
*/ | ||
types: { | ||
/** | ||
* Maps language subtag like `zh-CN` to their display names. | ||
*/ | ||
language: { | ||
narrow: Record<LanguageTag, string>; | ||
short: Record<LanguageTag, string>; | ||
long: Record<LanguageTag, string>; | ||
}; | ||
region: { | ||
narrow: Record<RegionCode, string>; | ||
short: Record<RegionCode, string>; | ||
long: Record<RegionCode, string>; | ||
}; | ||
script: { | ||
narrow: Record<ScriptCode, string>; | ||
short: Record<ScriptCode, string>; | ||
long: Record<ScriptCode, string>; | ||
}; | ||
currency: { | ||
narrow: Record<CurrencyCode, string>; | ||
short: Record<CurrencyCode, string>; | ||
long: Record<CurrencyCode, string>; | ||
}; | ||
}; | ||
/** | ||
* Not in spec, but we need this to display both language and region in display name. | ||
* e.g. zh-Hans-SG + "{0}({1})" -> 简体中文(新加坡) | ||
* Here {0} is replaced by language display name and {1} is replaced by region display name. | ||
*/ | ||
patterns: { | ||
locale: string; | ||
}; | ||
} | ||
export declare type DisplayNamesLocaleData = LocaleData<DisplayNamesData>; | ||
export declare interface FieldData { | ||
@@ -129,2 +173,10 @@ '0'?: string; | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
export declare function isWellFormedCurrencyCode(currency: string): boolean; | ||
declare type LanguageTag = string; | ||
export declare type LDMLPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'; | ||
@@ -315,2 +367,4 @@ | ||
declare type RegionCode = string; | ||
declare type RelativeTimeData = { | ||
@@ -334,2 +388,4 @@ [u in LDMLPluralRule]?: string; | ||
declare type ScriptCode = string; | ||
export declare function selectUnit(from: Date | number, to?: Date | number, thresholds?: Partial<Thresholds>): { | ||
@@ -394,2 +450,7 @@ value: number; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
export declare function toString(o: unknown): string; | ||
export declare type UnifiedNumberFormatLocaleData = LocaleData<NumberInternalSlots>; | ||
@@ -396,0 +457,0 @@ |
@@ -8,2 +8,6 @@ import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions } from './number-types'; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
export declare function toString(o: unknown): string; | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
@@ -65,1 +69,6 @@ * @param opts | ||
export declare function objectIs(x: any, y: any): boolean; | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
export declare function isWellFormedCurrencyCode(currency: string): boolean; |
@@ -15,2 +15,12 @@ import aliases from './aliases'; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
export function toString(o) { | ||
// Only symbol is irregular... | ||
if (typeof o === 'symbol') { | ||
throw TypeError('Cannot convert a Symbol value to a string'); | ||
} | ||
return String(o); | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
@@ -34,6 +44,6 @@ * @param opts | ||
if (type === 'string') { | ||
value = String(value); | ||
value = toString(value); | ||
} | ||
if (values !== undefined && !values.filter(function (val) { return val == value; }).length) { | ||
throw new RangeError(value + " in not within " + values); | ||
throw new RangeError(value + " is not within " + values.join(', ')); | ||
} | ||
@@ -97,3 +107,4 @@ return value; | ||
export function setMultiInternalSlots(map, pl, props) { | ||
for (var k in props) { | ||
for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) { | ||
var k = _a[_i]; | ||
setInternalSlot(map, pl, k, props[k]); | ||
@@ -204,1 +215,23 @@ } | ||
} | ||
var NOT_A_Z_REGEX = /[^A-Z]/; | ||
/** | ||
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping | ||
* @param str string to convert | ||
*/ | ||
function toUpperCase(str) { | ||
return str.replace(/([a-z])/g, function (_, c) { return c.toUpperCase(); }); | ||
} | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
export function isWellFormedCurrencyCode(currency) { | ||
currency = toUpperCase(currency); | ||
if (currency.length !== 3) { | ||
return false; | ||
} | ||
if (NOT_A_Z_REGEX.test(currency)) { | ||
return false; | ||
} | ||
return true; | ||
} |
{ | ||
"name": "@formatjs/intl-utils", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Smartly determine best unit for relative time format", | ||
@@ -24,2 +24,3 @@ "keywords": [ | ||
"module": "lib/index.js", | ||
"jsnext": "dist-es6/index.js", | ||
"types": "dist/index.d.ts", | ||
@@ -34,3 +35,3 @@ "files": [ | ||
"cldr": "ts-node --project tsconfig.cjs.json scripts/cldr", | ||
"build": "npm run cldr && tsc && api-extractor run --local && tsc -p tsconfig.cjs.json", | ||
"build": "npm run cldr && tsc && api-extractor run --local && tsc -p tsconfig.es6.json && tsc -p tsconfig.cjs.json", | ||
"test": "cross-env TS_NODE_PROJECT=tsconfig.cjs.json mocha --opts ../../mocha.opts tests/*" | ||
@@ -40,3 +41,3 @@ }, | ||
"license": "MIT", | ||
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c" | ||
"gitHead": "86f218a78e66f003e35d4807842102d6ff670af9" | ||
} |
@@ -18,2 +18,4 @@ export {selectUnit} from './diff'; | ||
objectIs, | ||
isWellFormedCurrencyCode, | ||
toString, | ||
} from './polyfill-utils'; | ||
@@ -33,3 +35,4 @@ export { | ||
export * from './number-types'; | ||
export * from './displaynames-types'; | ||
export {getCanonicalLocales} from './get-canonical-locales'; | ||
export {invariant} from './invariant'; |
@@ -23,2 +23,13 @@ import aliases from './aliases'; | ||
/** | ||
* https://tc39.es/ecma262/#sec-tostring | ||
*/ | ||
export function toString(o: unknown): string { | ||
// Only symbol is irregular... | ||
if (typeof o === 'symbol') { | ||
throw TypeError('Cannot convert a Symbol value to a string'); | ||
} | ||
return String(o); | ||
} | ||
/** | ||
* https://tc39.es/ecma402/#sec-getoption | ||
@@ -48,6 +59,6 @@ * @param opts | ||
if (type === 'string') { | ||
value = String(value); | ||
value = toString(value); | ||
} | ||
if (values !== undefined && !values.filter(val => val == value).length) { | ||
throw new RangeError(`${value} in not within ${values}`); | ||
throw new RangeError(`${value} is not within ${values.join(', ')}`); | ||
} | ||
@@ -149,3 +160,3 @@ return value; | ||
) { | ||
for (const k in props) { | ||
for (const k of Object.keys(props) as K[]) { | ||
setInternalSlot(map, pl, k, props[k]); | ||
@@ -309,1 +320,26 @@ } | ||
} | ||
const NOT_A_Z_REGEX = /[^A-Z]/; | ||
/** | ||
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping | ||
* @param str string to convert | ||
*/ | ||
function toUpperCase(str: string): string { | ||
return str.replace(/([a-z])/g, (_, c) => c.toUpperCase()); | ||
} | ||
/** | ||
* https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-iswellformedcurrencycode | ||
* @param currency | ||
*/ | ||
export function isWellFormedCurrencyCode(currency: string): boolean { | ||
currency = toUpperCase(currency); | ||
if (currency.length !== 3) { | ||
return false; | ||
} | ||
if (NOT_A_Z_REGEX.test(currency)) { | ||
return false; | ||
} | ||
return true; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
200794
86
5103