Skip to content

Commit cdd05bd

Browse files
petebacondarwinIgorMinar
authored andcommitted
docs(common): move Pipe param docs to transform function (#23062)
PR Close #23062
1 parent 079d8e5 commit cdd05bd

File tree

5 files changed

+91
-85
lines changed

5 files changed

+91
-85
lines changed

packages/common/src/pipes/date_pipe.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,7 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
1717
*
1818
* Uses the function {@link formatDate} to format a date according to locale rules.
1919
*
20-
* Where:
21-
* - `value` is a date object or a number (milliseconds since UTC epoch) or an ISO string
22-
* (https://www.w3.org/TR/NOTE-datetime).
23-
* - `format` indicates which date/time components to include. The format can be predefined as
24-
* shown below (all examples are given for `en-US`) or custom as shown in the table.
25-
* - `'short'`: equivalent to `'M/d/yy, h:mm a'` (e.g. `6/15/15, 9:03 AM`).
26-
* - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (e.g. `Jun 15, 2015, 9:03:01 AM`).
27-
* - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (e.g. `June 15, 2015 at 9:03:01 AM GMT+1`).
28-
* - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (e.g. `Monday, June 15, 2015 at
29-
* 9:03:01 AM GMT+01:00`).
30-
* - `'shortDate'`: equivalent to `'M/d/yy'` (e.g. `6/15/15`).
31-
* - `'mediumDate'`: equivalent to `'MMM d, y'` (e.g. `Jun 15, 2015`).
32-
* - `'longDate'`: equivalent to `'MMMM d, y'` (e.g. `June 15, 2015`).
33-
* - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (e.g. `Monday, June 15, 2015`).
34-
* - `'shortTime'`: equivalent to `'h:mm a'` (e.g. `9:03 AM`).
35-
* - `'mediumTime'`: equivalent to `'h:mm:ss a'` (e.g. `9:03:01 AM`).
36-
* - `'longTime'`: equivalent to `'h:mm:ss a z'` (e.g. `9:03:01 AM GMT+1`).
37-
* - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (e.g. `9:03:01 AM GMT+01:00`).
38-
* - `timezone` to be used for formatting. It understands UTC/GMT and the continental US time zone
39-
* abbreviations, but for general use, use a time zone offset (e.g. `'+0430'`).
40-
* If not specified, the local system timezone of the end-user's browser will be used.
41-
* - `locale` is a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
42-
* default).
43-
*
20+
* The following tabled describes the formatting options.
4421
*
4522
* | Field Type | Format | Description | Example Value |
4623
* |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
@@ -129,6 +106,29 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
129106
export class DatePipe implements PipeTransform {
130107
constructor(@Inject(LOCALE_ID) private locale: string) {}
131108

109+
/**
110+
* @param value a date object or a number (milliseconds since UTC epoch) or an ISO string
111+
* (https://www.w3.org/TR/NOTE-datetime).
112+
* @param format indicates which date/time components to include. The format can be predefined as
113+
* shown below (all examples are given for `en-US`) or custom as shown in the table.
114+
* - `'short'`: equivalent to `'M/d/yy, h:mm a'` (e.g. `6/15/15, 9:03 AM`).
115+
* - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (e.g. `Jun 15, 2015, 9:03:01 AM`).
116+
* - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (e.g. `June 15, 2015 at 9:03:01 AM GMT+1`).
117+
* - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (e.g. `Monday, June 15, 2015 at
118+
* 9:03:01 AM GMT+01:00`).
119+
* - `'shortDate'`: equivalent to `'M/d/yy'` (e.g. `6/15/15`).
120+
* - `'mediumDate'`: equivalent to `'MMM d, y'` (e.g. `Jun 15, 2015`).
121+
* - `'longDate'`: equivalent to `'MMMM d, y'` (e.g. `June 15, 2015`).
122+
* - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (e.g. `Monday, June 15, 2015`).
123+
* - `'shortTime'`: equivalent to `'h:mm a'` (e.g. `9:03 AM`).
124+
* - `'mediumTime'`: equivalent to `'h:mm:ss a'` (e.g. `9:03:01 AM`).
125+
* - `'longTime'`: equivalent to `'h:mm:ss a z'` (e.g. `9:03:01 AM GMT+1`).
126+
* - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (e.g. `9:03:01 AM GMT+01:00`).
127+
* @param timezone to be used for formatting the time. It understands UTC/GMT and the continental US time zone
128+
* abbreviations, but for general use, use a time zone offset (e.g. `'+0430'`).
129+
* @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
130+
* default).
131+
*/
132132
transform(value: any, format = 'mediumDate', timezone?: string, locale?: string): string|null {
133133
if (value == null || value === '' || value !== value) return null;
134134

packages/common/src/pipes/i18n_plural_pipe.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ const _INTERPOLATION_REGEXP: RegExp = /#/g;
1818
*
1919
* Maps a value to a string that pluralizes the value according to locale rules.
2020
*
21-
* Where:
22-
* - `expression` is a number.
23-
* - `mapping` is an object that mimics the ICU format, see
24-
* http://userguide.icu-project.org/formatparse/messages
25-
* - `locale` is a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
26-
* default)
27-
*
2821
* ## Example
2922
*
3023
* {@example common/pipes/ts/i18n_pipe.ts region='I18nPluralPipeComponent'}
@@ -35,6 +28,13 @@ const _INTERPOLATION_REGEXP: RegExp = /#/g;
3528
export class I18nPluralPipe implements PipeTransform {
3629
constructor(private _localization: NgLocalization) {}
3730

31+
/**
32+
* @param value the number to be formatted
33+
* @param pluralMap an object that mimics the ICU format, see
34+
* http://userguide.icu-project.org/formatparse/messages.
35+
* @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
36+
* default).
37+
*/
3838
transform(value: number, pluralMap: {[count: string]: string}, locale?: string): string {
3939
if (value == null) return '';
4040

packages/common/src/pipes/i18n_select_pipe.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
1515
*
1616
* Generic selector that displays the string that matches the current value.
1717
*
18-
* Where `mapping` is an object that indicates the text that should be displayed
19-
* for different values of the provided `expression`.
20-
* If none of the keys of the mapping match the value of the `expression`, then the content
21-
* of the `other` key is returned when present, otherwise an empty string is returned.
18+
* If none of the keys of the `mapping` match the `value`, then the content
19+
* of the `other` key is returned when present, otherwise an empty string is returned.
2220
*
23-
* ## Example
21+
* ## Example
2422
*
2523
* {@example common/pipes/ts/i18n_pipe.ts region='I18nSelectPipeComponent'}
2624
*
27-
* @experimental
25+
* @experimental
2826
*/
2927
@Pipe({name: 'i18nSelect', pure: true})
3028
export class I18nSelectPipe implements PipeTransform {
29+
/**
30+
* @param value a string to be internationalized.
31+
* @param mapping an object that indicates the text that should be displayed
32+
* for different values of the provided `value`.
33+
*/
3134
transform(value: string|null|undefined, mapping: {[key: string]: string}): string {
3235
if (value == null) return '';
3336

packages/common/src/pipes/number_pipe.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
2020
* Formats a number as text. Group sizing and separator and other locale-specific
2121
* configurations are based on the locale.
2222
*
23-
* Where:
24-
* - `value` is a number
25-
* - `digitInfo` is a `string` which has a following format: <br>
26-
* <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
27-
* - `minIntegerDigits` is the minimum number of integer digits to use. Defaults to `1`.
28-
* - `minFractionDigits` is the minimum number of digits after the decimal point. Defaults to `0`.
29-
* - `maxFractionDigits` is the maximum number of digits after the decimal point. Defaults to `3`.
30-
* - `locale` is a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
31-
* default).
32-
*
3323
* ### Example
3424
*
3525
* {@example common/pipes/ts/number_pipe.ts region='NumberPipe'}
@@ -40,6 +30,16 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
4030
export class DecimalPipe implements PipeTransform {
4131
constructor(@Inject(LOCALE_ID) private _locale: string) {}
4232

33+
/**
34+
* @param value a number to be formatted.
35+
* @param digitsInfo a `string` which has a following format: <br>
36+
* <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
37+
* - `minIntegerDigits` is the minimum number of integer digits to use. Defaults to `1`.
38+
* - `minFractionDigits` is the minimum number of digits after the decimal point. Defaults to `0`.
39+
* - `maxFractionDigits` is the maximum number of digits after the decimal point. Defaults to `3`.
40+
* @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
41+
* default).
42+
*/
4343
transform(value: any, digitsInfo?: string, locale?: string): string|null {
4444
if (isEmpty(value)) return null;
4545

@@ -61,12 +61,6 @@ export class DecimalPipe implements PipeTransform {
6161
* Uses the function {@link formatPercent} to format a number as a percentage according
6262
* to locale rules.
6363
*
64-
* Where:
65-
* - `value` is a number.
66-
* - `digitInfo` See {@link DecimalPipe} for more details.
67-
* - `locale` is a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
68-
* default).
69-
*
7064
* ### Example
7165
*
7266
* {@example common/pipes/ts/percent_pipe.ts region='PercentPipe'}
@@ -77,6 +71,13 @@ export class DecimalPipe implements PipeTransform {
7771
export class PercentPipe implements PipeTransform {
7872
constructor(@Inject(LOCALE_ID) private _locale: string) {}
7973

74+
/**
75+
*
76+
* @param value a number to be formatted as a percentage.
77+
* @param digitsInfo see {@link DecimalPipe} for more details.
78+
* @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
79+
* default).
80+
*/
8081
transform(value: any, digitsInfo?: string, locale?: string): string|null {
8182
if (isEmpty(value)) return null;
8283

@@ -98,22 +99,6 @@ export class PercentPipe implements PipeTransform {
9899
* Uses the functions {@link getCurrencySymbol} and {@link formatCurrency} to format a
99100
* number as currency using locale rules.
100101
*
101-
* Where:
102-
* - `value` is a number.
103-
* - `currencyCode` is the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, such
104-
* as `USD` for the US dollar and `EUR` for the euro.
105-
* - `display` indicates whether to show the currency symbol, the code or a custom value:
106-
* - `code`: use code (e.g. `USD`).
107-
* - `symbol`(default): use symbol (e.g. `$`).
108-
* - `symbol-narrow`: some countries have two symbols for their currency, one regular and one
109-
* narrow (e.g. the canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`).
110-
* - `string`: use this value instead of a code or a symbol.
111-
* - boolean (deprecated from v5): `true` for symbol and false for `code`.
112-
* If there is no narrow symbol for the chosen currency, the regular symbol will be used.
113-
* - `digitInfo` See {@link DecimalPipe} for more details.
114-
* - `locale` is a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
115-
* default).
116-
*
117102
* ### Example
118103
*
119104
* {@example common/pipes/ts/currency_pipe.ts region='CurrencyPipe'}
@@ -124,6 +109,23 @@ export class PercentPipe implements PipeTransform {
124109
export class CurrencyPipe implements PipeTransform {
125110
constructor(@Inject(LOCALE_ID) private _locale: string) {}
126111

112+
/**
113+
*
114+
* @param value a number to be formatted as currency.
115+
* @param currencyCodeis the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, such
116+
* as `USD` for the US dollar and `EUR` for the euro.
117+
* @param display indicates whether to show the currency symbol, the code or a custom value:
118+
* - `code`: use code (e.g. `USD`).
119+
* - `symbol`(default): use symbol (e.g. `$`).
120+
* - `symbol-narrow`: some countries have two symbols for their currency, one regular and one
121+
* narrow (e.g. the canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`).
122+
* - `string`: use this value instead of a code or a symbol.
123+
* - boolean (deprecated from v5): `true` for symbol and false for `code`.
124+
* If there is no narrow symbol for the chosen currency, the regular symbol will be used.
125+
* @param digitsInfo see {@link DecimalPipe} for more details.
126+
* @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
127+
* default).
128+
*/
127129
transform(
128130
value: any, currencyCode?: string,
129131
display: 'code'|'symbol'|'symbol-narrow'|string|boolean = 'symbol', digitsInfo?: string,

packages/common/src/pipes/slice_pipe.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,17 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
1313
* @ngModule CommonModule
1414
* @description
1515
*
16-
* Creates a new List or String containing a subset (slice) of the elements.
17-
*
18-
* Where the input expression is a `List` or `String`, and:
19-
* - `start`: The starting index of the subset to return.
20-
* - **a positive integer**: return the item at `start` index and all items after
21-
* in the list or string expression.
22-
* - **a negative integer**: return the item at `start` index from the end and all items after
23-
* in the list or string expression.
24-
* - **if positive and greater than the size of the expression**: return an empty list or string.
25-
* - **if negative and greater than the size of the expression**: return entire list or string.
26-
* - `end`: The ending index of the subset to return.
27-
* - **omitted**: return all items until the end.
28-
* - **if positive**: return all items before `end` index of the list or string.
29-
* - **if negative**: return all items before `end` index from the end of the list or string.
16+
* Creates a new `Array` or `String` containing a subset (slice) of the elements.
3017
*
3118
* All behavior is based on the expected behavior of the JavaScript API `Array.prototype.slice()`
3219
* and `String.prototype.slice()`.
3320
*
34-
* When operating on a [List], the returned list is always a copy even when all
21+
* When operating on an `Array`, the returned `Array` is always a copy even when all
3522
* the elements are being returned.
3623
*
3724
* When operating on a blank value, the pipe returns the blank value.
3825
*
39-
* ## List Example
26+
* ### List Example
4027
*
4128
* This `ngFor` example:
4229
*
@@ -56,6 +43,20 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
5643

5744
@Pipe({name: 'slice', pure: false})
5845
export class SlicePipe implements PipeTransform {
46+
/**
47+
* @param value a list or a string to be sliced.
48+
* @param start the starting index of the subset to return:
49+
* - **a positive integer**: return the item at `start` index and all items after
50+
* in the list or string expression.
51+
* - **a negative integer**: return the item at `start` index from the end and all items after
52+
* in the list or string expression.
53+
* - **if positive and greater than the size of the expression**: return an empty list or string.
54+
* - **if negative and greater than the size of the expression**: return entire list or string.
55+
* @param end the ending index of the subset to return:
56+
* - **omitted**: return all items until the end.
57+
* - **if positive**: return all items before `end` index of the list or string.
58+
* - **if negative**: return all items before `end` index from the end of the list or string.
59+
*/
5960
transform(value: any, start: number, end?: number): any {
6061
if (value == null) return value;
6162

0 commit comments

Comments
 (0)