Skip to content

Commit 4ebd2da

Browse files
authored
feat!: limit options according to EcmaScript specification (#12)
1 parent 03387f0 commit 4ebd2da

15 files changed

+37
-27
lines changed

Diff for: README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The input date can be one of the following:
6565
* undefined
6666

6767
The options are the same as the options for `new Intl.DateTimeFormat()`. For a list of the options, see
68-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat).
68+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options).
6969

7070
With the `INTL_DATE_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
7171

@@ -85,7 +85,7 @@ The input can be one of the following:
8585
* undefined
8686

8787
The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see
88-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat).
88+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options).
8989

9090
With the `INTL_DECIMAL_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
9191

@@ -105,7 +105,7 @@ The input can be one of the following:
105105
* undefined
106106

107107
The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see
108-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat).
108+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options).
109109

110110
With the `INTL_PERCENT_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
111111

@@ -128,7 +128,7 @@ The currency code parameter is required and must be a valid ISO 4217 currency co
128128
number instead, use the `intlDecimal` pipe.
129129

130130
The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see
131-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat).
131+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options).
132132

133133
With the `INTL_CURRENCY_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
134134

@@ -147,7 +147,7 @@ The input can be one of the following:
147147
* undefined
148148

149149
The options are the same as the options for `new Intl.DisplayNames()`. For a list of the options, see
150-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames).
150+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options).
151151

152152
With the `INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
153153

@@ -166,7 +166,7 @@ The input can be one of the following:
166166
* undefined
167167

168168
The options are the same as the options for `new Intl.DisplayNames()`. For a list of the options, see
169-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames).
169+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options).
170170

171171
With the `INTL_COUNTRY_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
172172

@@ -190,7 +190,7 @@ the [specification](https://tc39.es/proposal-unified-intl-numberformat/section6/
190190
for a full list of possible values. If you want to transform a decimal number instead, use the `intlDecimal` pipe.
191191

192192
The options are the same as the options for `new Intl.NumberFormat()`. For a list of the options, see
193-
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat).
193+
their [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options).
194194

195195
With the `INTL_UNIT_PIPE_DEFAULT_OPTIONS` injection token you can specify default options.
196196

@@ -201,7 +201,6 @@ For more context, see the following [GitHub issue](https://github.com/angular/an
201201
## Feature Roadmap
202202

203203
* Performance: Prepare Intl.* object with default options, only construct new object when necessary
204-
* Limit options to only what is allowed by Intl API
205204
* List pipe
206205
* Relative time pipe
207206
* Migration Schematics for usages of Angular pipes
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlCountryPipeOptions} from "./intl-country.pipe";
23

3-
export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.DisplayNamesOptions>>('IntlCountryPipeDefaultOptions');
4+
export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlCountryPipeOptions, 'locale'>>('IntlCountryPipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/country/intl-country.pipe.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {INTL_LOCALES} from "../locale";
33
import {INTL_COUNTRY_PIPE_DEFAULT_OPTIONS} from "./intl-country-pipe-default-options";
44
import {IntlPipeOptions} from "../intl-pipe-options";
55

6-
export type IntlCountryPipeOptions = Partial<Intl.DisplayNamesOptions> & IntlPipeOptions;
6+
export type IntlCountryPipeOptions = Omit<Partial<Intl.DisplayNamesOptions>, 'languageDisplay'> & IntlPipeOptions;
77

88
@Pipe({
99
name: 'intlCountry',
@@ -12,7 +12,7 @@ export type IntlCountryPipeOptions = Partial<Intl.DisplayNamesOptions> & IntlPip
1212
export class IntlCountryPipe implements PipeTransform {
1313

1414
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
15-
@Optional() @Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.DisplayNamesOptions> | null) {
15+
@Optional() @Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlCountryPipeOptions, 'locale'> | null) {
1616
}
1717

1818
transform(value: string | null | undefined, options?: IntlCountryPipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlCurrencyPipeOptions} from "./intl-currency.pipe";
23

3-
export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.NumberFormatOptions>>('IntlCurrencyPipeDefaultOptions');
4+
export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlCurrencyPipeOptions, 'locale'>>('IntlCurrencyPipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/currency/intl-currency.pipe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale";
44
import {INTL_CURRENCY_PIPE_DEFAULT_OPTIONS} from "./intl-currency-pipe-default-options";
55
import {getNumericValue} from "../utils/number-utils";
66

7-
export type IntlCurrencyPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPipeOptions;
7+
type OmitOptions = 'unit' | 'unitDisplay' | 'currency';
8+
export type IntlCurrencyPipeOptions = Omit<Partial<Intl.NumberFormatOptions>, OmitOptions> & IntlPipeOptions;
89

910
@Pipe({
1011
name: 'intlCurrency',
@@ -13,7 +14,7 @@ export type IntlCurrencyPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPi
1314
export class IntlCurrencyPipe implements PipeTransform {
1415

1516
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
16-
@Optional() @Inject(INTL_CURRENCY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.NumberFormatOptions> | null) {
17+
@Optional() @Inject(INTL_CURRENCY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlCurrencyPipeOptions, 'locale'> | null) {
1718
}
1819

1920
transform(value: number | string | null | undefined, currency: string, options?: IntlCurrencyPipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlDatePipeOptions} from "./intl-date.pipe";
23

3-
export const INTL_DATE_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.DateTimeFormatOptions>>('IntlDatePipeDefaultOptions');
4+
export const INTL_DATE_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlDatePipeOptions, 'locale'>>('IntlDatePipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/date/intl-date.pipe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type IntlDatePipeOptions = Partial<Intl.DateTimeFormatOptions> & IntlPipe
1212
export class IntlDatePipe implements PipeTransform {
1313

1414
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
15-
@Optional() @Inject(INTL_DATE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.DateTimeFormatOptions> | null) {
15+
@Optional() @Inject(INTL_DATE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlDatePipeOptions, 'locale'> | null) {
1616
}
1717

1818
transform(value: string | number | Date | null | undefined, options?: IntlDatePipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlDecimalPipeOptions} from "./intl-decimal.pipe";
23

3-
export const INTL_DECIMAL_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.NumberFormatOptions>>('IntlDecimalPipeDefaultOptions');
4+
export const INTL_DECIMAL_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlDecimalPipeOptions, 'locale'>>('IntlDecimalPipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/decimal/intl-decimal.pipe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale";
44
import {INTL_DECIMAL_PIPE_DEFAULT_OPTIONS} from "./intl-decimal-pipe-default-options";
55
import {getNumericValue} from "../utils/number-utils";
66

7-
export type IntlDecimalPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPipeOptions;
7+
type OmitOptions = 'unit' | 'unitDisplay' | 'currency' | 'currencyDisplay' | 'currencySign';
8+
export type IntlDecimalPipeOptions = Omit<Partial<Intl.NumberFormatOptions>, OmitOptions> & IntlPipeOptions;
89

910
@Pipe({
1011
name: 'intlDecimal',
@@ -13,7 +14,7 @@ export type IntlDecimalPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPip
1314
export class IntlDecimalPipe implements PipeTransform {
1415

1516
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
16-
@Optional() @Inject(INTL_DECIMAL_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.NumberFormatOptions> | null) {
17+
@Optional() @Inject(INTL_DECIMAL_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlDecimalPipeOptions, 'locale'> | null) {
1718
}
1819

1920
transform(value: number | string | null | undefined, options?: IntlDecimalPipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlLanguagePipeOptions} from "./intl-language.pipe";
23

3-
export const INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.DisplayNamesOptions>>('IntlLanguagePipeDefaultOptions');
4+
export const INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlLanguagePipeOptions, 'locale'>>('IntlLanguagePipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/language/intl-language.pipe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type IntlLanguagePipeOptions = Partial<Intl.DisplayNamesOptions> & IntlPi
1212
export class IntlLanguagePipe implements PipeTransform {
1313

1414
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
15-
@Optional() @Inject(INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.DisplayNamesOptions> | null) {
15+
@Optional() @Inject(INTL_LANGUAGE_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlLanguagePipeOptions, 'locale'> | null) {
1616
}
1717

1818
transform(value: string | null | undefined, options?: IntlLanguagePipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlPercentPipeOptions} from "./intl-percent.pipe";
23

3-
export const INTL_PERCENT_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.NumberFormatOptions>>('IntlPercentPipeDefaultOptions');
4+
export const INTL_PERCENT_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlPercentPipeOptions, 'locale'>>('IntlPercentPipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/percent/intl-percent.pipe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale";
44
import {getNumericValue} from "../utils/number-utils";
55
import {INTL_PERCENT_PIPE_DEFAULT_OPTIONS} from "./intl-percent-pipe-default-options";
66

7-
export type IntlPercentPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPipeOptions;
7+
type OmitOptions = 'unit' | 'unitDisplay' | 'currency' | 'currencyDisplay' | 'currencySign';
8+
export type IntlPercentPipeOptions = Omit<Partial<Intl.NumberFormatOptions>, OmitOptions> & IntlPipeOptions;
89

910
@Pipe({
1011
name: 'intlPercent',
@@ -13,7 +14,7 @@ export type IntlPercentPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPip
1314
export class IntlPercentPipe implements PipeTransform {
1415

1516
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
16-
@Optional() @Inject(INTL_PERCENT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.NumberFormatOptions> | null) {
17+
@Optional() @Inject(INTL_PERCENT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlPercentPipeOptions, 'locale'> | null) {
1718
}
1819

1920
transform(value: number | string | null | undefined, options?: IntlPercentPipeOptions): string | null {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import {InjectionToken} from "@angular/core";
2+
import {IntlUnitPipeOptions} from "./intl-unit.pipe";
23

3-
export const INTL_UNIT_PIPE_DEFAULT_OPTIONS = new InjectionToken<Partial<Intl.NumberFormatOptions>>('IntlUnitPipeDefaultOptions');
4+
export const INTL_UNIT_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlUnitPipeOptions, 'locale'>>('IntlUnitPipeDefaultOptions');

Diff for: projects/angular-ecmascript-intl/src/lib/unit/intl-unit.pipe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {INTL_LOCALES} from "../locale";
44
import {getNumericValue} from "../utils/number-utils";
55
import {INTL_UNIT_PIPE_DEFAULT_OPTIONS} from "./intl-unit-pipe-default-options";
66

7-
export type IntlUnitPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPipeOptions;
7+
type OmitOptions = 'unit' | 'currency' | 'currencyDisplay' | 'currencySign';
8+
export type IntlUnitPipeOptions = Omit<Partial<Intl.NumberFormatOptions>, OmitOptions> & IntlPipeOptions;
89

910
@Pipe({
1011
name: 'intlUnit',
@@ -13,7 +14,7 @@ export type IntlUnitPipeOptions = Partial<Intl.NumberFormatOptions> & IntlPipeOp
1314
export class IntlUnitPipe implements PipeTransform {
1415

1516
constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
16-
@Optional() @Inject(INTL_UNIT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Partial<Intl.NumberFormatOptions> | null) {
17+
@Optional() @Inject(INTL_UNIT_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlUnitPipeOptions, 'locale'> | null) {
1718
}
1819

1920
transform(value: number | string | null | undefined, unit: string | undefined, options?: IntlUnitPipeOptions): string | null {

0 commit comments

Comments
 (0)