UNPKG

@obliczeniowo/elementary

Version:
155 lines (147 loc) 6.86 kB
import * as i0 from '@angular/core'; import { Pipe, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; class TextFormatPipe { transform(value, ...args) { switch (args[0]) { case 'lower': return value.toLowerCase(); case 'upper': return value.toUpperCase(); case 'upperFirst': return this.firstToUpper(value); case 'allFirstToUpper': return value.split(' ').map(t => this.firstToUpper(t)).join(' '); case 'ellipsis': return (value.length > args[1] ? value.substring(0, args[1] - 1) + '…' : value); case 'css': return value.toLowerCase().replace(/[;:.,?><'"`~@#$%^&*+=!()[\]]/g, '').split(' ').join('-'); case 'noPolishLetters': return value.normalize('NFD').replace(/[\u0142]/g, 'l').replace(/[\u0142-\u036f]/g, '').replace(/[Ł]/g, 'L'); } } firstToUpper(text) { return text.substring(0, 1).toUpperCase() + text.substring(1); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextFormatPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: TextFormatPipe, isStandalone: false, name: "oblTextFormat" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextFormatPipe, decorators: [{ type: Pipe, args: [{ name: 'oblTextFormat', standalone: false }] }] }); class TextSizePipe { div = document.createElement('div'); constructor() { this.div.style.position = 'absolute'; this.div.style.left = '-10000'; this.div.style.top = '-10000'; } transform(value, fontSize) { return this.measureText(value, fontSize || 10); } measureText(text, fontSize) { document.body.appendChild(this.div); this.div.style.fontSize = `${fontSize}px`; this.div.textContent = text; const lResult = { width: this.div.clientWidth, height: this.div.clientHeight }; document.body.removeChild(this.div); return lResult; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextSizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: TextSizePipe, isStandalone: false, name: "textSize" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextSizePipe, decorators: [{ type: Pipe, args: [{ name: 'textSize', standalone: false }] }], ctorParameters: () => [] }); class TranslationPipe { /** * Transforming key by translations mapping object * @param value string key to translate * @param translations translations map * @param params params for translations * @param def override default * @returns translated string */ transform(value, translations, params, def) { return this.setParams(translations[value] || def || value, params); } setParams(translation, params) { if (params) { const reg = /\{([^}]*)\}/mg; const find = translation.match(reg); const clear = (match) => match.replace(/\{|\}/g, ''); find?.forEach(found => translation = translation.replace(new RegExp(found, 'g'), `${params?.[clear(found)] ?? `unknown param ${found}`}`)); } return translation; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TranslationPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: TranslationPipe, isStandalone: false, name: "oblTranslation" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TranslationPipe, decorators: [{ type: Pipe, args: [{ name: 'oblTranslation', standalone: false }] }] }); class TextSplitPipe { transform(value, by = ' ') { return value.split(by); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextSplitPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: TextSplitPipe, isStandalone: false, name: "oblTextSplit" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextSplitPipe, decorators: [{ type: Pipe, args: [{ name: 'oblTextSplit', standalone: false }] }] }); class TextPipesModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: TextPipesModule, declarations: [TextFormatPipe, TextSizePipe, TranslationPipe, TextSplitPipe], imports: [CommonModule], exports: [TextFormatPipe, TextSizePipe, TranslationPipe, TextSplitPipe] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextPipesModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: TextPipesModule, decorators: [{ type: NgModule, args: [{ declarations: [ TextFormatPipe, TextSizePipe, TranslationPipe, TextSplitPipe ], imports: [ CommonModule, ], exports: [ TextFormatPipe, TextSizePipe, TranslationPipe, TextSplitPipe ] }] }] }); /** * Generated bundle index. Do not edit. */ export { TextFormatPipe, TextPipesModule, TextSizePipe, TextSplitPipe, TranslationPipe }; //# sourceMappingURL=obliczeniowo-elementary-text-pipes.mjs.map