UNPKG

@rxap/pipes

Version:

Provides a set of Angular pipes for common data transformations, including currency formatting, string manipulation, and object property access. These pipes offer standalone functionality for easy integration into Angular templates. The package includes p

239 lines (225 loc) 11.9 kB
import * as i0 from '@angular/core'; import { Pipe, NgModule } from '@angular/core'; import * as i1 from '@angular/common'; import { CurrencyPipe, JsonPipe } from '@angular/common'; import { clone, hasIdentifierProperty, getIdentifierProperties, getFromObject } from '@rxap/utilities'; class RxapCurrencyPipe { constructor(currency) { this.currency = currency; } /** * * @param value The number to be formatted as currency. * @param currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, * such as `USD` for the US dollar and `EUR` for the euro. The default currency code can be * configured using the `DEFAULT_CURRENCY_CODE` injection token. * @param display The format for the currency indicator. One of the following: * - `code`: Show the code (such as `USD`). * - `symbol`(default): Show the symbol (such as `$`). * - `symbol-narrow`: Use the narrow symbol for locales that have two symbols for their * currency. * For example, the Canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`. If the * locale has no narrow symbol, uses the standard symbol for the locale. * - String: Use the given string value instead of a code or a symbol. * For example, an empty string will suppress the currency & symbol. * - Boolean (marked deprecated in v5): `true` for symbol and false for `code`. * * @param digitsInfo Decimal representation options, specified by a string * in the following format:<br> * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>. * - `minIntegerDigits`: The minimum number of integer digits before the decimal point. * Default is `1`. * - `minFractionDigits`: The minimum number of digits after the decimal point. * Default is `2`. * - `maxFractionDigits`: The maximum number of digits after the decimal point. * Default is `2`. * If not provided, the number will be formatted with the proper amount of digits, * depending on what the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) specifies. * For example, the Canadian dollar has 2 digits, whereas the Chilean peso has none. * @param locale A locale code for the locale format rules to use. * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default. * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app). */ transform(value, currencyCode, display, digitsInfo, locale) { return this.currency.transform(value / 100, currencyCode, display, digitsInfo, locale); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: RxapCurrencyPipe, deps: [{ token: i1.CurrencyPipe }], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: RxapCurrencyPipe, isStandalone: true, name: "currency" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: RxapCurrencyPipe, decorators: [{ type: Pipe, args: [{ name: 'currency', standalone: true, }] }], ctorParameters: () => [{ type: i1.CurrencyPipe }] }); class CurrencyPipeModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: CurrencyPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: CurrencyPipeModule, imports: [RxapCurrencyPipe], exports: [RxapCurrencyPipe] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: CurrencyPipeModule, providers: [CurrencyPipe] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: CurrencyPipeModule, decorators: [{ type: NgModule, args: [{ imports: [RxapCurrencyPipe], exports: [RxapCurrencyPipe], providers: [CurrencyPipe], }] }] }); class DeleteIdentifierPipe { transform(value) { if (!value) { return value; } const copy = clone(value); if (hasIdentifierProperty(copy)) { for (const pk of getIdentifierProperties(copy)) { delete copy[pk]; } } return copy; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: DeleteIdentifierPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: DeleteIdentifierPipe, isStandalone: true, name: "deleteIdentifier" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: DeleteIdentifierPipe, decorators: [{ type: Pipe, args: [{ name: 'deleteIdentifier', standalone: true, }] }] }); class ReplacePipe { transform(value, replace, replaceValue) { return value ? value.replace(replace, replaceValue) : ''; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ReplacePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: ReplacePipe, isStandalone: true, name: "replace" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ReplacePipe, decorators: [{ type: Pipe, args: [{ name: 'replace', standalone: true, }] }] }); class EscapeQuotationMarkPipe { transform(value, reverse = false) { if (reverse) { return new ReplacePipe().transform(value, /\\"/g, '"'); } else { return new ReplacePipe().transform(value, /"/g, '\\"'); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: EscapeQuotationMarkPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: EscapeQuotationMarkPipe, isStandalone: true, name: "escapeQuotationMark" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: EscapeQuotationMarkPipe, decorators: [{ type: Pipe, args: [{ name: 'escapeQuotationMark', standalone: true, }] }] }); class GetFromObjectPipe { transform(value, path) { return getFromObject(value, path); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: GetFromObjectPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: GetFromObjectPipe, isStandalone: true, name: "getFromObject" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: GetFromObjectPipe, decorators: [{ type: Pipe, args: [{ name: 'getFromObject', standalone: true, }] }] }); class JoinPipe { transform(list, separator) { return list.join(separator); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: JoinPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: JoinPipe, isStandalone: true, name: "join" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: JoinPipe, decorators: [{ type: Pipe, args: [{ name: 'join', pure: true, standalone: true, }] }] }); class LimitPipe { transform(value, limit) { return value.slice(0, limit); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: LimitPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: LimitPipe, isStandalone: true, name: "limit" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: LimitPipe, decorators: [{ type: Pipe, args: [{ name: 'limit', standalone: true, }] }] }); class SlicePipe { transform(value, start, end) { return value.slice(start, end); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: SlicePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: SlicePipe, isStandalone: true, name: "slice" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: SlicePipe, decorators: [{ type: Pipe, args: [{ name: 'slice', standalone: true, }] }] }); class ToDisplayPipe { constructor() { this.jsonPipe = new JsonPipe(); } transform(value, toDisplay = this.jsonPipe.transform) { return toDisplay(value); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ToDisplayPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: ToDisplayPipe, isStandalone: true, name: "toDisplay" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ToDisplayPipe, decorators: [{ type: Pipe, args: [{ name: 'toDisplay', standalone: true, }] }] }); class TruncatePipe { transform(value, length = 64, ellipsis = '...') { if (!value) { return ''; } if (value.length <= length) { return value; } return value.substring(0, length) + ellipsis; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: TruncatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: TruncatePipe, isStandalone: true, name: "truncate" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: TruncatePipe, decorators: [{ type: Pipe, args: [{ name: 'truncate', standalone: true, }] }] }); // region // endregion /** * Generated bundle index. Do not edit. */ export { CurrencyPipeModule, DeleteIdentifierPipe, EscapeQuotationMarkPipe, GetFromObjectPipe, JoinPipe, LimitPipe, ReplacePipe, RxapCurrencyPipe, SlicePipe, ToDisplayPipe, TruncatePipe }; //# sourceMappingURL=rxap-pipes.mjs.map