ng-zorro-antd-pipes.mjs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import * as i0 from '@angular/core';
  2. import { Pipe, NgModule } from '@angular/core';
  3. import { sum, isNumberFinite, toDecimal } from 'ng-zorro-antd/core/util';
  4. import * as i1 from '@angular/platform-browser';
  5. /**
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  8. */
  9. class NzAggregatePipe {
  10. transform(value, method) {
  11. if (!Array.isArray(value)) {
  12. return value;
  13. }
  14. if (value.length === 0) {
  15. return undefined;
  16. }
  17. switch (method) {
  18. case 'sum':
  19. return sum(value);
  20. case 'avg':
  21. return sum(value) / value.length;
  22. case 'max':
  23. return Math.max(...value);
  24. case 'min':
  25. return Math.min(...value);
  26. default:
  27. throw Error(`Invalid Pipe Arguments: Aggregate pipe doesn't support this type`);
  28. }
  29. }
  30. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzAggregatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  31. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzAggregatePipe, isStandalone: true, name: "nzAggregate" });
  32. }
  33. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzAggregatePipe, decorators: [{
  34. type: Pipe,
  35. args: [{
  36. name: 'nzAggregate'
  37. }]
  38. }] });
  39. /**
  40. * Use of this source code is governed by an MIT-style license that can be
  41. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  42. */
  43. class NzBytesPipe {
  44. static formats = {
  45. B: { max: 1024 },
  46. kB: { max: Math.pow(1024, 2), prev: 'B' },
  47. KB: { max: Math.pow(1024, 2), prev: 'B' },
  48. MB: { max: Math.pow(1024, 3), prev: 'kB' },
  49. GB: { max: Math.pow(1024, 4), prev: 'MB' },
  50. TB: { max: Number.MAX_SAFE_INTEGER, prev: 'GB' }
  51. };
  52. transform(input, decimal = 0, from = 'B', to) {
  53. if (!(isNumberFinite(input) && isNumberFinite(decimal) && decimal % 1 === 0 && decimal >= 0)) {
  54. return input;
  55. }
  56. let bytes = input;
  57. let unit = from;
  58. while (unit !== 'B') {
  59. bytes *= 1024;
  60. unit = NzBytesPipe.formats[unit].prev;
  61. }
  62. if (to) {
  63. const format = NzBytesPipe.formats[to];
  64. const result = toDecimal(NzBytesPipe.calculateResult(format, bytes), decimal);
  65. return NzBytesPipe.formatResult(result, to);
  66. }
  67. for (const key in NzBytesPipe.formats) {
  68. if (NzBytesPipe.formats.hasOwnProperty(key)) {
  69. const format = NzBytesPipe.formats[key];
  70. if (bytes < format.max) {
  71. const result = toDecimal(NzBytesPipe.calculateResult(format, bytes), decimal);
  72. return NzBytesPipe.formatResult(result, key);
  73. }
  74. }
  75. }
  76. }
  77. static formatResult(result, unit) {
  78. return `${result} ${unit}`;
  79. }
  80. static calculateResult(format, bytes) {
  81. const prev = format.prev ? NzBytesPipe.formats[format.prev] : undefined;
  82. return prev ? bytes / prev.max : bytes;
  83. }
  84. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzBytesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  85. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzBytesPipe, isStandalone: true, name: "nzBytes" });
  86. }
  87. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzBytesPipe, decorators: [{
  88. type: Pipe,
  89. args: [{
  90. name: 'nzBytes'
  91. }]
  92. }] });
  93. /**
  94. * Use of this source code is governed by an MIT-style license that can be
  95. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  96. */
  97. class NzToCssUnitPipe {
  98. transform(value, defaultUnit = 'px') {
  99. return typeof value === 'number' ? `${value}${defaultUnit}` : value;
  100. }
  101. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzToCssUnitPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  102. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzToCssUnitPipe, isStandalone: true, name: "nzToCssUnit" });
  103. }
  104. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzToCssUnitPipe, decorators: [{
  105. type: Pipe,
  106. args: [{
  107. name: 'nzToCssUnit'
  108. }]
  109. }] });
  110. /**
  111. * Use of this source code is governed by an MIT-style license that can be
  112. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  113. */
  114. class NzEllipsisPipe {
  115. transform(value, length, suffix = '') {
  116. if (typeof value !== 'string') {
  117. return value;
  118. }
  119. const len = typeof length === 'undefined' ? value.length : length;
  120. if (value.length <= len) {
  121. return value;
  122. }
  123. return value.substring(0, len) + suffix;
  124. }
  125. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzEllipsisPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  126. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzEllipsisPipe, isStandalone: true, name: "nzEllipsis" });
  127. }
  128. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzEllipsisPipe, decorators: [{
  129. type: Pipe,
  130. args: [{
  131. name: 'nzEllipsis'
  132. }]
  133. }] });
  134. /**
  135. * Use of this source code is governed by an MIT-style license that can be
  136. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  137. */
  138. class NzSanitizerPipe {
  139. sanitizer;
  140. constructor(sanitizer) {
  141. this.sanitizer = sanitizer;
  142. }
  143. transform(value, type = 'html') {
  144. switch (type) {
  145. case 'html':
  146. return this.sanitizer.bypassSecurityTrustHtml(value);
  147. case 'style':
  148. return this.sanitizer.bypassSecurityTrustStyle(value);
  149. case 'url':
  150. return this.sanitizer.bypassSecurityTrustUrl(value);
  151. case 'resourceUrl':
  152. return this.sanitizer.bypassSecurityTrustResourceUrl(value);
  153. default:
  154. throw new Error(`Invalid safe type specified`);
  155. }
  156. }
  157. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSanitizerPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
  158. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzSanitizerPipe, isStandalone: true, name: "nzSanitizer" });
  159. }
  160. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSanitizerPipe, decorators: [{
  161. type: Pipe,
  162. args: [{
  163. name: 'nzSanitizer'
  164. }]
  165. }], ctorParameters: () => [{ type: i1.DomSanitizer }] });
  166. /**
  167. * Use of this source code is governed by an MIT-style license that can be
  168. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  169. */
  170. class NzTrimPipe {
  171. // TODO(chensimeng) trimEnd, trimStart
  172. transform(text) {
  173. return text.trim();
  174. }
  175. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTrimPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
  176. static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzTrimPipe, isStandalone: true, name: "nzTrim" });
  177. }
  178. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzTrimPipe, decorators: [{
  179. type: Pipe,
  180. args: [{
  181. name: 'nzTrim'
  182. }]
  183. }] });
  184. /**
  185. * Use of this source code is governed by an MIT-style license that can be
  186. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  187. */
  188. const pipes = [NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe];
  189. class NzPipesModule {
  190. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  191. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzPipesModule, imports: [NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe], exports: [NzToCssUnitPipe, NzSanitizerPipe, NzTrimPipe, NzBytesPipe, NzAggregatePipe, NzEllipsisPipe] });
  192. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzPipesModule });
  193. }
  194. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzPipesModule, decorators: [{
  195. type: NgModule,
  196. args: [{
  197. imports: [pipes],
  198. exports: [pipes]
  199. }]
  200. }] });
  201. /**
  202. * Use of this source code is governed by an MIT-style license that can be
  203. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  204. */
  205. /**
  206. * Generated bundle index. Do not edit.
  207. */
  208. export { NzAggregatePipe, NzBytesPipe, NzEllipsisPipe, NzPipesModule, NzSanitizerPipe, NzToCssUnitPipe, NzTrimPipe };
  209. //# sourceMappingURL=ng-zorro-antd-pipes.mjs.map