From e6bf014608b6acf831da84b8a46e912f2290ed74 Mon Sep 17 00:00:00 2001 From: Daniel Kimmich Date: Sat, 25 Feb 2023 10:26:21 +0100 Subject: [PATCH] feat!: limit options according to EcmaScript specification --- README.md | 15 +++++++-------- .../country/intl-country-pipe-default-options.ts | 3 ++- .../src/lib/country/intl-country.pipe.ts | 4 ++-- .../intl-currency-pipe-default-options.ts | 3 ++- .../src/lib/currency/intl-currency.pipe.ts | 5 +++-- .../lib/date/intl-date-pipe-default-options.ts | 3 ++- .../src/lib/date/intl-date.pipe.ts | 2 +- .../decimal/intl-decimal-pipe-default-options.ts | 3 ++- .../src/lib/decimal/intl-decimal.pipe.ts | 5 +++-- .../intl-language-pipe-default-options.ts | 3 ++- .../src/lib/language/intl-language.pipe.ts | 2 +- .../percent/intl-percent-pipe-default-options.ts | 3 ++- .../src/lib/percent/intl-percent.pipe.ts | 5 +++-- .../lib/unit/intl-unit-pipe-default-options.ts | 3 ++- .../src/lib/unit/intl-unit.pipe.ts | 5 +++-- 15 files changed, 37 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index bb6a04df..b45dc12a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The input date can be one of the following: * undefined The options are the same as the options for `new Intl.DateTimeFormat()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options). With the `INTL_DATE_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -85,7 +85,7 @@ The input can be one of the following: * undefined The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options). With the `INTL_DECIMAL_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -105,7 +105,7 @@ The input can be one of the following: * undefined The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options). With the `INTL_PERCENT_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -128,7 +128,7 @@ The currency code parameter is required and must be a valid ISO 4217 currency co number instead, use the `intlDecimal` pipe. The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options). With the `INTL_CURRENCY_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -147,7 +147,7 @@ The input can be one of the following: * undefined The options are the same as the options for `new Intl.DisplayNames()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options). With the `INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -166,7 +166,7 @@ The input can be one of the following: * undefined The options are the same as the options for `new Intl.DisplayNames()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options). With the `INTL_COUNTRY_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -190,7 +190,7 @@ the [specification](https://tc39.es/proposal-unified-intl-numberformat/section6/ for a full list of possible values. If you want to transform a decimal number instead, use the `intlDecimal` pipe. The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see -their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat). +their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options). With the `INTL_UNIT_PIPE_DEFAULT_OPTIONS` injection token you can specify default options. @@ -201,7 +201,6 @@ For more context, see the following [GitHub issue](https://github.com/angular/an ## Feature Roadmap * Performance: Prepare Intl.* object with default options, only construct new object when necessary -* Limit options to only what is allowed by Intl API * List pipe * Relative time pipe * Migration Schematics for usages of Angular pipes diff --git a/projects/angular-ecmascript-intl/src/lib/country/intl-country-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/country/intl-country-pipe-default-options.ts index fece9940..bc127e70 100644 --- a/projects/angular-ecmascript-intl/src/lib/country/intl-country-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/country/intl-country-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlCountryPipeOptions} from "./intl-country.pipe"; -export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlCountryPipeDefaultOptions'); +export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlCountryPipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/country/intl-country.pipe.ts b/projects/angular-ecmascript-intl/src/lib/country/intl-country.pipe.ts index 4a89566f..2c2edb4b 100644 --- a/projects/angular-ecmascript-intl/src/lib/country/intl-country.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/country/intl-country.pipe.ts @@ -3,7 +3,7 @@ import {INTL_LOCALES} from "../locale"; import {INTL_COUNTRY_PIPE_DEFAULT_OPTIONS} from "./intl-country-pipe-default-options"; import {IntlPipeOptions} from "../intl-pipe-options"; -export type IntlCountryPipeOptions = Partial & IntlPipeOptions; +export type IntlCountryPipeOptions = Omit, 'languageDisplay'> & IntlPipeOptions; @Pipe({ name: 'intlCountry', @@ -12,7 +12,7 @@ export type IntlCountryPipeOptions = Partial & IntlPip export class IntlCountryPipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: string | null | undefined, options?: IntlCountryPipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/currency/intl-currency-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/currency/intl-currency-pipe-default-options.ts index f3c02941..23bbfc9c 100644 --- a/projects/angular-ecmascript-intl/src/lib/currency/intl-currency-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/currency/intl-currency-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlCurrencyPipeOptions} from "./intl-currency.pipe"; -export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlCurrencyPipeDefaultOptions'); +export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlCurrencyPipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/currency/intl-currency.pipe.ts b/projects/angular-ecmascript-intl/src/lib/currency/intl-currency.pipe.ts index 3d794786..38d4e0f9 100644 --- a/projects/angular-ecmascript-intl/src/lib/currency/intl-currency.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/currency/intl-currency.pipe.ts @@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale"; import {INTL_CURRENCY_PIPE_DEFAULT_OPTIONS} from "./intl-currency-pipe-default-options"; import {getNumericValue} from "../utils/number-utils"; -export type IntlCurrencyPipeOptions = Partial & IntlPipeOptions; +type OmitOptions = 'unit' | 'unitDisplay' | 'currency'; +export type IntlCurrencyPipeOptions = Omit, OmitOptions> & IntlPipeOptions; @Pipe({ name: 'intlCurrency', @@ -13,7 +14,7 @@ export type IntlCurrencyPipeOptions = Partial & IntlPi export class IntlCurrencyPipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_CURRENCY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_CURRENCY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: number | string | null | undefined, currency: string, options?: IntlCurrencyPipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/date/intl-date-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/date/intl-date-pipe-default-options.ts index cd138cf9..49d6340d 100644 --- a/projects/angular-ecmascript-intl/src/lib/date/intl-date-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/date/intl-date-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlDatePipeOptions} from "./intl-date.pipe"; -export const INTL_DATE_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlDatePipeDefaultOptions'); +export const INTL_DATE_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlDatePipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/date/intl-date.pipe.ts b/projects/angular-ecmascript-intl/src/lib/date/intl-date.pipe.ts index 5f639526..e9fdabcb 100644 --- a/projects/angular-ecmascript-intl/src/lib/date/intl-date.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/date/intl-date.pipe.ts @@ -12,7 +12,7 @@ export type IntlDatePipeOptions = Partial & IntlPipe export class IntlDatePipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_DATE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_DATE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: string | number | Date | null | undefined, options?: IntlDatePipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal-pipe-default-options.ts index 3b12bb55..fbff54f8 100644 --- a/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlDecimalPipeOptions} from "./intl-decimal.pipe"; -export const INTL_DECIMAL_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlDecimalPipeDefaultOptions'); +export const INTL_DECIMAL_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlDecimalPipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal.pipe.ts b/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal.pipe.ts index 92ad692a..84731b11 100644 --- a/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal.pipe.ts @@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale"; import {INTL_DECIMAL_PIPE_DEFAULT_OPTIONS} from "./intl-decimal-pipe-default-options"; import {getNumericValue} from "../utils/number-utils"; -export type IntlDecimalPipeOptions = Partial & IntlPipeOptions; +type OmitOptions = 'unit' | 'unitDisplay' | 'currency' | 'currencyDisplay' | 'currencySign'; +export type IntlDecimalPipeOptions = Omit, OmitOptions> & IntlPipeOptions; @Pipe({ name: 'intlDecimal', @@ -13,7 +14,7 @@ export type IntlDecimalPipeOptions = Partial & IntlPip export class IntlDecimalPipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_DECIMAL_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_DECIMAL_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: number | string | null | undefined, options?: IntlDecimalPipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/language/intl-language-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/language/intl-language-pipe-default-options.ts index bcd0b814..f2d99030 100644 --- a/projects/angular-ecmascript-intl/src/lib/language/intl-language-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/language/intl-language-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlLanguagePipeOptions} from "./intl-language.pipe"; -export const INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlLanguagePipeDefaultOptions'); +export const INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlLanguagePipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/language/intl-language.pipe.ts b/projects/angular-ecmascript-intl/src/lib/language/intl-language.pipe.ts index 6364da10..e2fdf9b0 100644 --- a/projects/angular-ecmascript-intl/src/lib/language/intl-language.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/language/intl-language.pipe.ts @@ -12,7 +12,7 @@ export type IntlLanguagePipeOptions = Partial & IntlPi export class IntlLanguagePipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: string | null | undefined, options?: IntlLanguagePipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/percent/intl-percent-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/percent/intl-percent-pipe-default-options.ts index a99486e2..34333acf 100644 --- a/projects/angular-ecmascript-intl/src/lib/percent/intl-percent-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/percent/intl-percent-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlPercentPipeOptions} from "./intl-percent.pipe"; -export const INTL_PERCENT_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlPercentPipeDefaultOptions'); +export const INTL_PERCENT_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlPercentPipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/percent/intl-percent.pipe.ts b/projects/angular-ecmascript-intl/src/lib/percent/intl-percent.pipe.ts index 28cf081b..f27de62b 100644 --- a/projects/angular-ecmascript-intl/src/lib/percent/intl-percent.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/percent/intl-percent.pipe.ts @@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale"; import {getNumericValue} from "../utils/number-utils"; import {INTL_PERCENT_PIPE_DEFAULT_OPTIONS} from "./intl-percent-pipe-default-options"; -export type IntlPercentPipeOptions = Partial & IntlPipeOptions; +type OmitOptions = 'unit' | 'unitDisplay' | 'currency' | 'currencyDisplay' | 'currencySign'; +export type IntlPercentPipeOptions = Omit, OmitOptions> & IntlPipeOptions; @Pipe({ name: 'intlPercent', @@ -13,7 +14,7 @@ export type IntlPercentPipeOptions = Partial & IntlPip export class IntlPercentPipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_PERCENT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_PERCENT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: number | string | null | undefined, options?: IntlPercentPipeOptions): string | null { diff --git a/projects/angular-ecmascript-intl/src/lib/unit/intl-unit-pipe-default-options.ts b/projects/angular-ecmascript-intl/src/lib/unit/intl-unit-pipe-default-options.ts index 66552f41..e3dafefa 100644 --- a/projects/angular-ecmascript-intl/src/lib/unit/intl-unit-pipe-default-options.ts +++ b/projects/angular-ecmascript-intl/src/lib/unit/intl-unit-pipe-default-options.ts @@ -1,3 +1,4 @@ import {InjectionToken} from "@angular/core"; +import {IntlUnitPipeOptions} from "./intl-unit.pipe"; -export const INTL_UNIT_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlUnitPipeDefaultOptions'); +export const INTL_UNIT_PIPE_DEFAULT_OPTIONS = new InjectionToken>('IntlUnitPipeDefaultOptions'); diff --git a/projects/angular-ecmascript-intl/src/lib/unit/intl-unit.pipe.ts b/projects/angular-ecmascript-intl/src/lib/unit/intl-unit.pipe.ts index 0dec65a5..b98662e9 100644 --- a/projects/angular-ecmascript-intl/src/lib/unit/intl-unit.pipe.ts +++ b/projects/angular-ecmascript-intl/src/lib/unit/intl-unit.pipe.ts @@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale"; import {getNumericValue} from "../utils/number-utils"; import {INTL_UNIT_PIPE_DEFAULT_OPTIONS} from "./intl-unit-pipe-default-options"; -export type IntlUnitPipeOptions = Partial & IntlPipeOptions; +type OmitOptions = 'unit' | 'currency' | 'currencyDisplay' | 'currencySign'; +export type IntlUnitPipeOptions = Omit, OmitOptions> & IntlPipeOptions; @Pipe({ name: 'intlUnit', @@ -13,7 +14,7 @@ export type IntlUnitPipeOptions = Partial & IntlPipeOp export class IntlUnitPipe implements PipeTransform { constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null, - @Optional() @Inject(INTL_UNIT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial | null) { + @Optional() @Inject(INTL_UNIT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit | null) { } transform(value: number | string | null | undefined, unit: string | undefined, options?: IntlUnitPipeOptions): string | null {