UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

318 lines (317 loc) • 7.51 kB
import * as i0 from "@angular/core"; import { NgModule, Pipe, inject } from "@angular/core"; import { isNumberFinite, sum, toDecimal } from "ng-zorro-antd/core/util"; import { DomSanitizer } from "@angular/platform-browser"; var NzAggregatePipe = class NzAggregatePipe { transform(value, method) { if (!Array.isArray(value)) return value; if (value.length === 0) return; switch (method) { case "sum": return sum(value); case "avg": return sum(value) / value.length; case "max": return Math.max(...value); case "min": return Math.min(...value); default: throw Error(`Invalid Pipe Arguments: Aggregate pipe doesn't support this type`); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAggregatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzAggregatePipe, isStandalone: true, name: "nzAggregate" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAggregatePipe, decorators: [{ type: Pipe, args: [{ name: "nzAggregate" }] }] }); var NzBytesPipe = class NzBytesPipe { static formats = { B: { max: 1024 }, kB: { max: Math.pow(1024, 2), prev: "B" }, KB: { max: Math.pow(1024, 2), prev: "B" }, MB: { max: Math.pow(1024, 3), prev: "kB" }, GB: { max: Math.pow(1024, 4), prev: "MB" }, TB: { max: Number.MAX_SAFE_INTEGER, prev: "GB" } }; transform(input, decimal = 0, from = "B", to) { if (!(isNumberFinite(input) && isNumberFinite(decimal) && decimal % 1 === 0 && decimal >= 0)) return input; let bytes = input; let unit = from; while (unit !== "B") { bytes *= 1024; unit = NzBytesPipe.formats[unit].prev; } if (to) { const format = NzBytesPipe.formats[to]; const result = toDecimal(NzBytesPipe.calculateResult(format, bytes), decimal); return NzBytesPipe.formatResult(result, to); } for (const key in NzBytesPipe.formats) if (NzBytesPipe.formats.hasOwnProperty(key)) { const format = NzBytesPipe.formats[key]; if (bytes < format.max) { const result = toDecimal(NzBytesPipe.calculateResult(format, bytes), decimal); return NzBytesPipe.formatResult(result, key); } } } static formatResult(result, unit) { return `${result} ${unit}`; } static calculateResult(format, bytes) { const prev = format.prev ? NzBytesPipe.formats[format.prev] : void 0; return prev ? bytes / prev.max : bytes; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzBytesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzBytesPipe, isStandalone: true, name: "nzBytes" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzBytesPipe, decorators: [{ type: Pipe, args: [{ name: "nzBytes" }] }] }); var NzToCssUnitPipe = class NzToCssUnitPipe { transform(value, defaultUnit = "px") { return typeof value === "number" ? `${value}${defaultUnit}` : value; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzToCssUnitPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzToCssUnitPipe, isStandalone: true, name: "nzToCssUnit" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzToCssUnitPipe, decorators: [{ type: Pipe, args: [{ name: "nzToCssUnit" }] }] }); var NzEllipsisPipe = class NzEllipsisPipe { transform(value, length, suffix = "") { if (typeof value !== "string") return value; const len = typeof length === "undefined" ? value.length : length; if (value.length <= len) return value; return value.substring(0, len) + suffix; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzEllipsisPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzEllipsisPipe, isStandalone: true, name: "nzEllipsis" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzEllipsisPipe, decorators: [{ type: Pipe, args: [{ name: "nzEllipsis" }] }] }); var NzSanitizerPipe = class NzSanitizerPipe { sanitizer = inject(DomSanitizer); transform(value, type = "html") { switch (type) { case "html": return this.sanitizer.bypassSecurityTrustHtml(value); case "style": return this.sanitizer.bypassSecurityTrustStyle(value); case "url": return this.sanitizer.bypassSecurityTrustUrl(value); case "resourceUrl": return this.sanitizer.bypassSecurityTrustResourceUrl(value); default: throw new Error(`Invalid safe type specified`); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSanitizerPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzSanitizerPipe, isStandalone: true, name: "nzSanitizer" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSanitizerPipe, decorators: [{ type: Pipe, args: [{ name: "nzSanitizer" }] }] }); var NzTrimPipe = class NzTrimPipe { transform(text) { return text.trim(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzTrimPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzTrimPipe, isStandalone: true, name: "nzTrim" }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzTrimPipe, decorators: [{ type: Pipe, args: [{ name: "nzTrim" }] }] }); const pipes = [ NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe ]; var NzPipesModule = class NzPipesModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzPipesModule, imports: [ NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe ], exports: [ NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe ] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzPipesModule }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzPipesModule, decorators: [{ type: NgModule, args: [{ imports: [pipes], exports: [pipes] }] }] }); export { NzAggregatePipe, NzBytesPipe, NzEllipsisPipe, NzPipesModule, NzSanitizerPipe, NzToCssUnitPipe, NzTrimPipe }; //# sourceMappingURL=ng-zorro-antd-pipes.mjs.map