@lion/localize
Advanced tools
Comparing version 0.14.4 to 0.14.5
# Change Log | ||
## 0.14.5 | ||
### Patch Changes | ||
- b9327627: These packages were using out of sync type definitions for FormatOptions, and the types were missing a bunch of options that Intl would normally accept. We now extend Intl's NumberFormatOptions and DateTimeFormatOptions properly, so we always have the right types and are more consistent on it. | ||
- Updated dependencies [01a798e5] | ||
- @lion/core@0.13.0 | ||
## 0.14.4 | ||
@@ -4,0 +12,0 @@ |
{ | ||
"name": "@lion/localize", | ||
"version": "0.14.4", | ||
"version": "0.14.5", | ||
"description": "The localization system helps to manage localization data split into locales and automate its loading", | ||
@@ -33,3 +33,3 @@ "license": "MIT", | ||
"@bundled-es-modules/message-format": "6.0.4", | ||
"@lion/core": "0.12.0", | ||
"@lion/core": "0.13.0", | ||
"singleton-manager": "1.1.2" | ||
@@ -36,0 +36,0 @@ }, |
@@ -5,38 +5,5 @@ /** | ||
* @param {Date} date | ||
* @param {Object} [options] Intl options are available | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.formatMatcher] | ||
* @param {boolean}[options.hour12] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.calendar] | ||
* @param {string} [options.timeZone] | ||
* @param {string} [options.timeZoneName] | ||
* @param {string} [options.weekday] | ||
* @param {string} [options.era] | ||
* @param {string} [options.year] | ||
* @param {string} [options.month] | ||
* @param {string} [options.day] | ||
* @param {string} [options.hour] | ||
* @param {string} [options.minute] | ||
* @param {string} [options.second] | ||
* @param {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} [options] Intl options are available | ||
* @returns {string} | ||
*/ | ||
export function formatDate(date: Date, options?: { | ||
locale?: string; | ||
localeMatcher?: string; | ||
formatMatcher?: string; | ||
hour12?: boolean; | ||
numberingSystem?: string; | ||
calendar?: string; | ||
timeZone?: string; | ||
timeZoneName?: string; | ||
weekday?: string; | ||
era?: string; | ||
year?: string; | ||
month?: string; | ||
day?: string; | ||
hour?: string; | ||
minute?: string; | ||
second?: string; | ||
} | undefined): string; | ||
export function formatDate(date: Date, options?: import("../../types/LocalizeMixinTypes.js").FormatDateOptions | undefined): string; |
@@ -8,19 +8,3 @@ import { getLocale } from './getLocale.js'; | ||
* @param {Date} date | ||
* @param {Object} [options] Intl options are available | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.formatMatcher] | ||
* @param {boolean}[options.hour12] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.calendar] | ||
* @param {string} [options.timeZone] | ||
* @param {string} [options.timeZoneName] | ||
* @param {string} [options.weekday] | ||
* @param {string} [options.era] | ||
* @param {string} [options.year] | ||
* @param {string} [options.month] | ||
* @param {string} [options.day] | ||
* @param {string} [options.hour] | ||
* @param {string} [options.minute] | ||
* @param {string} [options.second] | ||
* @param {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} [options] Intl options are available | ||
* @returns {string} | ||
@@ -32,4 +16,6 @@ */ | ||
} | ||
/** @type {options} */ | ||
const formatOptions = options || {}; | ||
const formatOptions = | ||
options || | ||
/** @type {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} */ ({}); | ||
/** | ||
@@ -36,0 +22,0 @@ * Set smart defaults if: |
/** | ||
* Gets the locale to use | ||
* | ||
* @param {string} locale Locale to override browser locale | ||
* @param {string|undefined} locale Locale to override browser locale | ||
* @returns {string} | ||
*/ | ||
export function getLocale(locale: string): string; | ||
export function getLocale(locale: string | undefined): string; |
@@ -6,3 +6,3 @@ import { localize } from '../localize.js'; | ||
* | ||
* @param {string} locale Locale to override browser locale | ||
* @param {string|undefined} locale Locale to override browser locale | ||
* @returns {string} | ||
@@ -9,0 +9,0 @@ */ |
/** | ||
* When number is NaN we should return an empty string or returnIfNaN param | ||
* | ||
* @param {string} returnIfNaN | ||
* @param {string|undefined} returnIfNaN | ||
* @returns {string} | ||
*/ | ||
export function emptyStringWhenNumberNan(returnIfNaN: string): string; | ||
export function emptyStringWhenNumberNan(returnIfNaN: string | undefined): string; |
@@ -6,3 +6,3 @@ import { localize } from '../localize.js'; | ||
* | ||
* @param {string} returnIfNaN | ||
* @param {string|undefined} returnIfNaN | ||
* @returns {string} | ||
@@ -9,0 +9,0 @@ */ |
@@ -6,11 +6,6 @@ /** | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
*/ | ||
export function forceENAUSymbols(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: { | ||
currency?: string; | ||
currencyDisplay?: string; | ||
} | undefined): FormatNumberPart[]; | ||
export function forceENAUSymbols(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: import("../../types/LocalizeMixinTypes").FormatNumberOptions | undefined): FormatNumberPart[]; | ||
/** | ||
@@ -17,0 +12,0 @@ * Change the symbols for locale 'en-AU', due to bug in Chrome |
@@ -13,5 +13,3 @@ /** @type {Object.<string,string>} */ | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
@@ -21,3 +19,3 @@ */ | ||
const result = formattedParts; | ||
if (formattedParts.length > 1 && currencyDisplay === 'symbol') { | ||
if (formattedParts.length > 1 && currencyDisplay === 'symbol' && currency) { | ||
if (Object.keys(CURRENCY_CODE_SYMBOL_MAP).includes(currency)) { | ||
@@ -24,0 +22,0 @@ result[0].value = CURRENCY_CODE_SYMBOL_MAP[currency]; |
@@ -6,11 +6,6 @@ /** | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
*/ | ||
export function forceSpaceBetweenCurrencyCodeAndNumber(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: { | ||
currency?: string; | ||
currencyDisplay?: string; | ||
} | undefined): FormatNumberPart[]; | ||
export function forceSpaceBetweenCurrencyCodeAndNumber(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: import("../../types/LocalizeMixinTypes").FormatNumberOptions | undefined): FormatNumberPart[]; | ||
/** | ||
@@ -17,0 +12,0 @@ * When in some locales there is no space between currency and amount it is added |
@@ -6,5 +6,3 @@ /** | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
@@ -11,0 +9,0 @@ */ |
/** | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
*/ | ||
export function forceTryCurrencyCode(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: { | ||
currency?: string; | ||
currencyDisplay?: string; | ||
} | undefined): FormatNumberPart[]; | ||
export function forceTryCurrencyCode(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: import("../../types/LocalizeMixinTypes").FormatNumberOptions | undefined): FormatNumberPart[]; | ||
export type FormatNumberPart = import("../../types/LocalizeMixinTypes").FormatNumberPart; |
/** | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
@@ -8,0 +6,0 @@ */ |
/** | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
*/ | ||
export function forceYenSymbol(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: { | ||
currency?: string; | ||
currencyDisplay?: string; | ||
} | undefined): FormatNumberPart[]; | ||
export function forceYenSymbol(formattedParts: FormatNumberPart[], { currency, currencyDisplay }?: import("../../types/LocalizeMixinTypes").FormatNumberOptions | undefined): FormatNumberPart[]; | ||
export type FormatNumberPart = import("../../types/LocalizeMixinTypes").FormatNumberPart; |
/** | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} [options] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] | ||
* @returns {FormatNumberPart[]} | ||
@@ -8,0 +6,0 @@ */ |
@@ -5,36 +5,8 @@ /** | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @typedef {import('@lion/localize/types/LocalizeMixinTypes').FormatNumberOptions} FormatOptions | ||
* @param {number} number Number to be formatted | ||
* @param {Object} [options] Intl options are available extended by roundMode and returnIfNaN | ||
* @param {string} [options.roundMode] | ||
* @param {string} [options.returnIfNaN] | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {boolean}[options.useGrouping] | ||
* @param {number} [options.minimumIntegerDigits] | ||
* @param {number} [options.minimumFractionDigits] | ||
* @param {number} [options.maximumFractionDigits] | ||
* @param {number} [options.minimumSignificantDigits] | ||
* @param {number} [options.maximumSignificantDigits] | ||
* @param {FormatOptions} [options] Intl options are available extended by roundMode and returnIfNaN | ||
* @returns {string} | ||
*/ | ||
export function formatNumber(number: number, options?: { | ||
roundMode?: string; | ||
returnIfNaN?: string; | ||
locale?: string; | ||
localeMatcher?: string; | ||
numberingSystem?: string; | ||
style?: string; | ||
currency?: string; | ||
currencyDisplay?: string; | ||
useGrouping?: boolean; | ||
minimumIntegerDigits?: number; | ||
minimumFractionDigits?: number; | ||
maximumFractionDigits?: number; | ||
minimumSignificantDigits?: number; | ||
maximumSignificantDigits?: number; | ||
} | undefined): string; | ||
export function formatNumber(number: number, options?: import("../../types/LocalizeMixinTypes.js").FormatNumberOptions | undefined): string; | ||
/** | ||
@@ -44,1 +16,5 @@ * Formats a number based on locale and options. It uses Intl for the formatting. | ||
export type FormatNumberPart = import("../../types/LocalizeMixinTypes.js").FormatNumberPart; | ||
/** | ||
* Formats a number based on locale and options. It uses Intl for the formatting. | ||
*/ | ||
export type FormatOptions = import("../../types/LocalizeMixinTypes.js").FormatNumberOptions; |
@@ -8,21 +8,8 @@ import { localize } from '../localize.js'; | ||
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart | ||
* @typedef {import('@lion/localize/types/LocalizeMixinTypes').FormatNumberOptions} FormatOptions | ||
* @param {number} number Number to be formatted | ||
* @param {Object} [options] Intl options are available extended by roundMode and returnIfNaN | ||
* @param {string} [options.roundMode] | ||
* @param {string} [options.returnIfNaN] | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {boolean}[options.useGrouping] | ||
* @param {number} [options.minimumIntegerDigits] | ||
* @param {number} [options.minimumFractionDigits] | ||
* @param {number} [options.maximumFractionDigits] | ||
* @param {number} [options.minimumSignificantDigits] | ||
* @param {number} [options.maximumSignificantDigits] | ||
* @param {FormatOptions} [options] Intl options are available extended by roundMode and returnIfNaN | ||
* @returns {string} | ||
*/ | ||
export function formatNumber(number, options = {}) { | ||
export function formatNumber(number, options = /** @type {FormatOptions} */ ({})) { | ||
if (number === undefined || number === null) return ''; | ||
@@ -29,0 +16,0 @@ const formattedToParts = formatNumberToParts(number, options); |
@@ -6,35 +6,6 @@ /** | ||
* @param {number} number Number to split up | ||
* @param {Object} [options] Intl options are available extended by roundMode,returnIfNaN | ||
* @param {string} [options.roundMode] | ||
* @param {string} [options.returnIfNaN] | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {boolean}[options.useGrouping] | ||
* @param {number} [options.minimumIntegerDigits] | ||
* @param {number} [options.minimumFractionDigits] | ||
* @param {number} [options.maximumFractionDigits] | ||
* @param {number} [options.minimumSignificantDigits] | ||
* @param {number} [options.maximumSignificantDigits] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] Intl options are available extended by roundMode,returnIfNaN | ||
* @returns {string | FormatNumberPart[]} Array with parts or (an empty string or returnIfNaN if not a number) | ||
*/ | ||
export function formatNumberToParts(number: number, options?: { | ||
roundMode?: string; | ||
returnIfNaN?: string; | ||
locale?: string; | ||
localeMatcher?: string; | ||
numberingSystem?: string; | ||
style?: string; | ||
currency?: string; | ||
currencyDisplay?: string; | ||
useGrouping?: boolean; | ||
minimumIntegerDigits?: number; | ||
minimumFractionDigits?: number; | ||
maximumFractionDigits?: number; | ||
minimumSignificantDigits?: number; | ||
maximumSignificantDigits?: number; | ||
} | undefined): string | FormatNumberPart[]; | ||
export function formatNumberToParts(number: number, options?: import("../../types/LocalizeMixinTypes.js").FormatNumberOptions | undefined): string | FormatNumberPart[]; | ||
/** | ||
@@ -41,0 +12,0 @@ * Splits a number up in parts for integer, fraction, group, literal, decimal and currency. |
@@ -14,17 +14,3 @@ import { emptyStringWhenNumberNan } from './emptyStringWhenNumberNan.js'; | ||
* @param {number} number Number to split up | ||
* @param {Object} [options] Intl options are available extended by roundMode,returnIfNaN | ||
* @param {string} [options.roundMode] | ||
* @param {string} [options.returnIfNaN] | ||
* @param {string} [options.locale] | ||
* @param {string} [options.localeMatcher] | ||
* @param {string} [options.numberingSystem] | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {boolean}[options.useGrouping] | ||
* @param {number} [options.minimumIntegerDigits] | ||
* @param {number} [options.minimumFractionDigits] | ||
* @param {number} [options.maximumFractionDigits] | ||
* @param {number} [options.minimumSignificantDigits] | ||
* @param {number} [options.maximumSignificantDigits] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] Intl options are available extended by roundMode,returnIfNaN | ||
* @returns {string | FormatNumberPart[]} Array with parts or (an empty string or returnIfNaN if not a number) | ||
@@ -31,0 +17,0 @@ */ |
@@ -6,6 +6,6 @@ /** | ||
* @param {string} currencyIso iso code like USD | ||
* @param {Object} options Intl options are available extended by roundMode | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] Intl options are available extended by roundMode | ||
* @returns {string} currency name like 'US dollar' | ||
*/ | ||
export function getCurrencyName(currencyIso: string, options: Object): string; | ||
export function getCurrencyName(currencyIso: string, options?: import("../../types/LocalizeMixinTypes.js").FormatNumberOptions | undefined): string; | ||
/** | ||
@@ -12,0 +12,0 @@ * Based on number, returns currency name like 'US dollar' |
@@ -8,3 +8,3 @@ import { formatNumberToParts } from './formatNumberToParts.js'; | ||
* @param {string} currencyIso iso code like USD | ||
* @param {Object} options Intl options are available extended by roundMode | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] Intl options are available extended by roundMode | ||
* @returns {string} currency name like 'US dollar' | ||
@@ -11,0 +11,0 @@ */ |
/** | ||
* To get the decimal separator | ||
* | ||
* @param {string} locale To override the browser locale | ||
* @param {string} [locale] To override the browser locale | ||
* @returns {string} The separator | ||
*/ | ||
export function getDecimalSeparator(locale: string): string; | ||
export function getDecimalSeparator(locale?: string | undefined): string; |
@@ -6,3 +6,3 @@ import { getLocale } from './getLocale.js'; | ||
* | ||
* @param {string} locale To override the browser locale | ||
* @param {string} [locale] To override the browser locale | ||
* @returns {string} The separator | ||
@@ -9,0 +9,0 @@ */ |
@@ -6,14 +6,7 @@ /** | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} options | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} options | ||
* @param {string} _locale | ||
* @returns {FormatNumberPart[]} | ||
*/ | ||
export function normalizeIntl(formattedParts: FormatNumberPart[], options: { | ||
style?: string; | ||
currency?: string; | ||
currencyDisplay?: string; | ||
} | undefined, _locale: string): FormatNumberPart[]; | ||
export function normalizeIntl(formattedParts: FormatNumberPart[], options: import("../../types/LocalizeMixinTypes.js").FormatNumberOptions | undefined, _locale: string): FormatNumberPart[]; | ||
/** | ||
@@ -20,0 +13,0 @@ * Function with all fixes on localize |
@@ -16,6 +16,3 @@ import { getGroupSeparator } from './getGroupSeparator.js'; | ||
* @param {FormatNumberPart[]} formattedParts | ||
* @param {Object} options | ||
* @param {string} [options.style] | ||
* @param {string} [options.currency] | ||
* @param {string} [options.currencyDisplay] | ||
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} options | ||
* @param {string} _locale | ||
@@ -22,0 +19,0 @@ * @returns {FormatNumberPart[]} |
@@ -8,2 +8,25 @@ import { Constructor } from '@open-wc/dedupe-mixin'; | ||
// Take the DateTimeFormat and add the missing resolved options as well as optionals | ||
export declare interface FormatDateOptions extends Intl.DateTimeFormatOptions { | ||
locale?: string; | ||
calendar?: string; | ||
numberingSystem?: string; | ||
timeZone?: string; | ||
roundMode?: string; | ||
returnIfNaN?: string; | ||
decimalSeparator?: string; | ||
mode?: 'pasted' | 'auto'; | ||
} | ||
// Take the DateTimeFormat and add the missing resolved options as well as optionals, and our own | ||
export declare interface FormatNumberOptions extends Intl.NumberFormatOptions { | ||
locale?: string; | ||
numberingSystem?: string; | ||
roundMode?: string; | ||
returnIfNaN?: string; | ||
decimalSeparator?: string; | ||
mode?: 'pasted' | 'auto'; | ||
} | ||
interface StringToFunctionMap { | ||
@@ -10,0 +33,0 @@ [key: string]: Function; |
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
234207
5105
+ Added@lion/core@0.13.0(transitive)
- Removed@lion/core@0.12.0(transitive)
Updated@lion/core@0.13.0