@react-aria/i18n
Advanced tools
Comparing version 3.0.0-nightly.736 to 3.0.0-nightly.738
@@ -56,2 +56,38 @@ var _intlMessageformat = $parcel$interopDefault(require("intl-messageformat")); | ||
function $dbb62b32f79d03a795a46f9fbec514c$export$numberFormatSignDisplayPolyfill(numberFormat, signDisplay, num) { | ||
if (signDisplay === 'auto') { | ||
return numberFormat.format(num); | ||
} else if (signDisplay === 'never') { | ||
return numberFormat.format(Math.abs(num)); | ||
} else { | ||
let needsPositiveSign = false; | ||
if (signDisplay === 'always') { | ||
needsPositiveSign = num > 0 || Object.is(num, 0); | ||
} else if (signDisplay === 'exceptZero') { | ||
if (Object.is(num, -0) || Object.is(num, 0)) { | ||
num = Math.abs(num); | ||
} else { | ||
needsPositiveSign = num > 0; | ||
} | ||
} | ||
if (needsPositiveSign) { | ||
let negative = numberFormat.format(-num); | ||
let noSign = numberFormat.format(num); // ignore RTL/LTR marker character | ||
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, ''); | ||
if ([...minus].length !== 1) { | ||
console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case'); | ||
} | ||
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign); | ||
return positive; | ||
} else { | ||
return numberFormat.format(num); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -286,3 +322,7 @@ * Gets the locale setting of the browser. | ||
exports.useNumberParser = useNumberParser; | ||
let $fa77db1482937b6cdb6683d9d7eb896$var$formatterCache = new Map(); | ||
let $fa77db1482937b6cdb6683d9d7eb896$var$formatterCache = new Map(); // @ts-ignore | ||
const $fa77db1482937b6cdb6683d9d7eb896$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', { | ||
signDisplay: 'exceptZero' | ||
}).resolvedOptions().signDisplay === 'exceptZero'; | ||
/** | ||
@@ -304,4 +344,17 @@ * Provides localized number formatting for the current locale. Automatically updates when the locale changes, | ||
let numberFormatter = new Intl.NumberFormat(locale, options); | ||
$fa77db1482937b6cdb6683d9d7eb896$var$formatterCache.set(cacheKey, numberFormatter); | ||
let numberFormatter = new Intl.NumberFormat(locale, options); // @ts-ignore | ||
let { | ||
signDisplay | ||
} = options || {}; | ||
$fa77db1482937b6cdb6683d9d7eb896$var$formatterCache.set(cacheKey, !$fa77db1482937b6cdb6683d9d7eb896$var$supportsSignDisplay && signDisplay != null ? new Proxy(numberFormatter, { | ||
get(target, property) { | ||
if (property === 'format') { | ||
return v => $dbb62b32f79d03a795a46f9fbec514c$export$numberFormatSignDisplayPolyfill(numberFormatter, signDisplay, v); | ||
} else { | ||
return target[property]; | ||
} | ||
} | ||
}) : numberFormatter); | ||
return numberFormatter; | ||
@@ -308,0 +361,0 @@ } |
@@ -38,2 +38,38 @@ import _intlMessageformat from "intl-messageformat"; | ||
function $d26e725ad56fbcb2c25f52b7de27$export$numberFormatSignDisplayPolyfill(numberFormat, signDisplay, num) { | ||
if (signDisplay === 'auto') { | ||
return numberFormat.format(num); | ||
} else if (signDisplay === 'never') { | ||
return numberFormat.format(Math.abs(num)); | ||
} else { | ||
let needsPositiveSign = false; | ||
if (signDisplay === 'always') { | ||
needsPositiveSign = num > 0 || Object.is(num, 0); | ||
} else if (signDisplay === 'exceptZero') { | ||
if (Object.is(num, -0) || Object.is(num, 0)) { | ||
num = Math.abs(num); | ||
} else { | ||
needsPositiveSign = num > 0; | ||
} | ||
} | ||
if (needsPositiveSign) { | ||
let negative = numberFormat.format(-num); | ||
let noSign = numberFormat.format(num); // ignore RTL/LTR marker character | ||
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, ''); | ||
if ([...minus].length !== 1) { | ||
console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case'); | ||
} | ||
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign); | ||
return positive; | ||
} else { | ||
return numberFormat.format(num); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -257,3 +293,7 @@ * Gets the locale setting of the browser. | ||
} | ||
let $ece3e138e83d330f42860705a2ec18a$var$formatterCache = new Map(); | ||
let $ece3e138e83d330f42860705a2ec18a$var$formatterCache = new Map(); // @ts-ignore | ||
const $ece3e138e83d330f42860705a2ec18a$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', { | ||
signDisplay: 'exceptZero' | ||
}).resolvedOptions().signDisplay === 'exceptZero'; | ||
/** | ||
@@ -275,4 +315,17 @@ * Provides localized number formatting for the current locale. Automatically updates when the locale changes, | ||
let numberFormatter = new Intl.NumberFormat(locale, options); | ||
$ece3e138e83d330f42860705a2ec18a$var$formatterCache.set(cacheKey, numberFormatter); | ||
let numberFormatter = new Intl.NumberFormat(locale, options); // @ts-ignore | ||
let { | ||
signDisplay | ||
} = options || {}; | ||
$ece3e138e83d330f42860705a2ec18a$var$formatterCache.set(cacheKey, !$ece3e138e83d330f42860705a2ec18a$var$supportsSignDisplay && signDisplay != null ? new Proxy(numberFormatter, { | ||
get(target, property) { | ||
if (property === 'format') { | ||
return v => $d26e725ad56fbcb2c25f52b7de27$export$numberFormatSignDisplayPolyfill(numberFormatter, signDisplay, v); | ||
} else { | ||
return target[property]; | ||
} | ||
} | ||
}) : numberFormatter); | ||
return numberFormatter; | ||
@@ -279,0 +332,0 @@ } |
{ | ||
"name": "@react-aria/i18n", | ||
"version": "3.0.0-nightly.736+0ac271ac", | ||
"version": "3.0.0-nightly.738+dc6d7873", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,4 +21,4 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/ssr": "3.0.2-nightly.2414+0ac271ac", | ||
"@react-types/shared": "3.0.0-nightly.736+0ac271ac", | ||
"@react-aria/ssr": "3.0.2-nightly.2416+dc6d7873", | ||
"@react-types/shared": "3.0.0-nightly.738+dc6d7873", | ||
"intl-messageformat": "^2.2.0" | ||
@@ -32,3 +32,3 @@ }, | ||
}, | ||
"gitHead": "0ac271ac5508fc6b03e0bd416142aba02546164a" | ||
"gitHead": "dc6d78733fb26fa02afeb1a36e11de7d71c84467" | ||
} |
@@ -13,2 +13,3 @@ /* | ||
import {numberFormatSignDisplayPolyfill} from './utils'; | ||
import {useLocale} from './context'; | ||
@@ -18,2 +19,5 @@ | ||
// @ts-ignore | ||
const supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero'; | ||
/** | ||
@@ -26,3 +30,3 @@ * Provides localized number formatting for the current locale. Automatically updates when the locale changes, | ||
let {locale} = useLocale(); | ||
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : ''); | ||
@@ -34,4 +38,14 @@ if (formatterCache.has(cacheKey)) { | ||
let numberFormatter = new Intl.NumberFormat(locale, options); | ||
formatterCache.set(cacheKey, numberFormatter); | ||
// @ts-ignore | ||
let {signDisplay} = options || {}; | ||
formatterCache.set(cacheKey, (!supportsSignDisplay && signDisplay != null) ? new Proxy(numberFormatter, { | ||
get(target, property) { | ||
if (property === 'format') { | ||
return (v) => numberFormatSignDisplayPolyfill(numberFormatter, signDisplay, v); | ||
} else { | ||
return target[property]; | ||
} | ||
} | ||
}) : numberFormatter); | ||
return numberFormatter; | ||
} |
@@ -34,1 +34,34 @@ /* | ||
} | ||
export function numberFormatSignDisplayPolyfill(numberFormat: Intl.NumberFormat, signDisplay: 'always' | 'exceptZero' | 'auto' | 'never', num: number) { | ||
if (signDisplay === 'auto') { | ||
return numberFormat.format(num); | ||
} else if (signDisplay === 'never') { | ||
return numberFormat.format(Math.abs(num)); | ||
} else { | ||
let needsPositiveSign = false; | ||
if (signDisplay === 'always') { | ||
needsPositiveSign = num > 0 || Object.is(num, 0); | ||
} else if (signDisplay === 'exceptZero') { | ||
if (Object.is(num, -0) || Object.is(num, 0)) { | ||
num = Math.abs(num); | ||
} else { | ||
needsPositiveSign = num > 0; | ||
} | ||
} | ||
if (needsPositiveSign) { | ||
let negative = numberFormat.format(-num); | ||
let noSign = numberFormat.format(num); | ||
// ignore RTL/LTR marker character | ||
let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, ''); | ||
if ([...minus].length !== 1) { | ||
console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case'); | ||
} | ||
let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign); | ||
return positive; | ||
} else { | ||
return numberFormat.format(num); | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
117157
1075