PipeAdded in v16.9Optional

wrList

Join a list with the commas and the last "and" or "or" of the app locale.

Installation

Import the class. This entry point has no stylesheet.

import { Component } from '@angular/core';
import { WrList, wrFormatList } from 'ngwr/pipes';

@Component({ imports: [WrList] })
export class MyComponent {}

Basic usage

join(', ') drops the last word and is wrong in every language. The pipe joins through Intl.ListFormat in LOCALE_ID.

Ada, Alan, and Grace

Ada, Alan, or Grace

5 kg, 200 g

5 kg 200 g

<p>{{ names | wrList }}</p>
<p>{{ names | wrList: 'disjunction' }}</p>
<p>{{ parts | wrList: 'unit' }}</p>
<p>{{ parts | wrList: { type: 'unit', style: 'narrow' } }}</p>

Playground

Blank items are left out. One item renders as it is, none as an empty string.

Ada, Alan, and Grace

{{ items | wrList: { type: 'conjunction', style: 'long' } }}

Customize

Items, comma-separated
Type
Style

In TypeScript

wrFormatList gives the same text for a string built in code, in the locale you pass.

import { wrFormatList } from 'ngwr/pipes';

wrFormatList(['Ada', 'Alan', 'Grace'], 'en-GB');                // "Ada, Alan and Grace"
wrFormatList(['Ada', 'Alan', 'Grace'], 'en-GB', 'disjunction'); // "Ada, Alan or Grace"
wrFormatList(['Ада', 'Алан', 'Грейс'], 'ru');                   // "Ада, Алан и Грейс"
LocaleAndOr
en-GBAda, Alan and GraceAda, Alan or Grace
deAda, Alan und GraceAda, Alan oder Grace
esAda, Alan y GraceAda, Alan o Grace
ruАда, Алан и ГрейсАда, Алан или Грейс
jaエイダ、アラン、グレースエイダ、アラン、またはグレース

API

NameDescriptionTypeDefault
wrListJoins the items through Intl.ListFormat in LOCALE_ID. Takes a type shortcut or the full options object. Blank items are left out; null, undefined and an empty list give an empty string.(value: Iterable<string> | null | undefined, typeOrOptions: WrListType | Intl.ListFormatOptions = 'conjunction') => string-
wrFormatListThe pipe as a function, in the locale given.(value: Iterable<string> | null | undefined, locale: string, typeOrOptions: WrListType | Intl.ListFormatOptions = 'conjunction') => string-
WrListTypeWhat joins the last item: "and", "or", or nothing, for a compound unit.'conjunction' | 'disjunction' | 'unit''conjunction'
options.styleHow much of the joining word is written, as Intl.ListFormat reads it.'long' | 'short' | 'narrow''long'

See also