UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

60 lines (55 loc) 2.43 kB
import { tuiObfuscate, tuiCreateOptions } from '@taiga-ui/cdk/utils'; import * as i0 from '@angular/core'; import { inject, Pipe } from '@angular/core'; const TUI_OBFUSCATE_DEFAULT_OPTIONS = { default: (value, symbol = '*') => tuiObfuscate(value, symbol), recipes: {}, }; /** * Injection token for obfuscation options. */ const [TUI_OBFUSCATE_OPTIONS, tuiObfuscateOptionsProvider] = tuiCreateOptions(TUI_OBFUSCATE_DEFAULT_OPTIONS); class TuiObfuscatePipe { constructor() { this.option = inject(TUI_OBFUSCATE_OPTIONS); } /** * Transforms the input value by obfuscating it according to the specified recipe or symbol. * * @param value The value to be obfuscated should be a string. * @param recipe The name of the recipe to use for obfuscation or a single character symbol for custom obfuscation. * @returns The obfuscated string. * @throws Will throw an error if the specified recipe is not found. */ transform(value, recipe = '') { if (!value) { return value; } if (!recipe) { return this.option.default(value); } const obfuscate = this.option.recipes[recipe]; if (obfuscate) { return obfuscate(value); } if (recipe.length === 1) { return this.option.default(value, recipe[0]); } const availableRecipes = Object.keys(this.option.recipes).sort(); throw new Error(`Obfuscate recipe "${recipe}" not found. Available recipes: [${availableRecipes}]`); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObfuscatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: TuiObfuscatePipe, isStandalone: true, name: "tuiObfuscate" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObfuscatePipe, decorators: [{ type: Pipe, args: [{ standalone: true, name: 'tuiObfuscate', }] }] }); /** * Generated bundle index. Do not edit. */ export { TUI_OBFUSCATE_DEFAULT_OPTIONS, TUI_OBFUSCATE_OPTIONS, TuiObfuscatePipe, tuiObfuscateOptionsProvider }; //# sourceMappingURL=taiga-ui-cdk-pipes-obfuscate.mjs.map