ngx-transforms 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2043,6 +2043,522 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
2043
2043
|
}]
|
|
2044
2044
|
}] });
|
|
2045
2045
|
|
|
2046
|
+
/**
|
|
2047
|
+
* MinPipe: Returns the minimum value from an array of numbers or objects.
|
|
2048
|
+
*
|
|
2049
|
+
* Supports primitive number arrays and object arrays by property key with dot notation.
|
|
2050
|
+
*
|
|
2051
|
+
* @param {unknown[]} value - The array to evaluate.
|
|
2052
|
+
* @param {string} [key] - Optional property path for object comparison (supports dot notation).
|
|
2053
|
+
*
|
|
2054
|
+
* @returns {number | undefined} - The minimum value, or undefined if the array is empty/invalid.
|
|
2055
|
+
*
|
|
2056
|
+
* @example
|
|
2057
|
+
* {{ [5, 3, 8, 1, 9] | min }} // 1
|
|
2058
|
+
* {{ products | min:'price' }} // cheapest price
|
|
2059
|
+
* {{ orders | min:'meta.total' }} // lowest order total
|
|
2060
|
+
*/
|
|
2061
|
+
class MinPipe {
|
|
2062
|
+
transform(value, key) {
|
|
2063
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
2064
|
+
return undefined;
|
|
2065
|
+
}
|
|
2066
|
+
if (!key) {
|
|
2067
|
+
const numbers = value.filter((item) => typeof item === 'number' && !isNaN(item));
|
|
2068
|
+
return numbers.length === 0 ? undefined : Math.min(...numbers);
|
|
2069
|
+
}
|
|
2070
|
+
const numbers = value
|
|
2071
|
+
.map(item => this.getNestedValue(item, key))
|
|
2072
|
+
.filter((val) => typeof val === 'number' && !isNaN(val));
|
|
2073
|
+
return numbers.length === 0 ? undefined : Math.min(...numbers);
|
|
2074
|
+
}
|
|
2075
|
+
getNestedValue(obj, path) {
|
|
2076
|
+
return path.split('.').reduce((current, segment) => current?.[segment], obj);
|
|
2077
|
+
}
|
|
2078
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MinPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2079
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: MinPipe, isStandalone: true, name: "min" });
|
|
2080
|
+
}
|
|
2081
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MinPipe, decorators: [{
|
|
2082
|
+
type: Pipe,
|
|
2083
|
+
args: [{
|
|
2084
|
+
name: 'min',
|
|
2085
|
+
standalone: true,
|
|
2086
|
+
}]
|
|
2087
|
+
}] });
|
|
2088
|
+
|
|
2089
|
+
/**
|
|
2090
|
+
* MaxPipe: Returns the maximum value from an array of numbers or objects.
|
|
2091
|
+
*
|
|
2092
|
+
* Supports primitive number arrays and object arrays by property key with dot notation.
|
|
2093
|
+
*
|
|
2094
|
+
* @param {unknown[]} value - The array to evaluate.
|
|
2095
|
+
* @param {string} [key] - Optional property path for object comparison (supports dot notation).
|
|
2096
|
+
*
|
|
2097
|
+
* @returns {number | undefined} - The maximum value, or undefined if the array is empty/invalid.
|
|
2098
|
+
*
|
|
2099
|
+
* @example
|
|
2100
|
+
* {{ [5, 3, 8, 1, 9] | max }} // 9
|
|
2101
|
+
* {{ products | max:'price' }} // highest price
|
|
2102
|
+
* {{ orders | max:'meta.total' }} // largest order total
|
|
2103
|
+
*/
|
|
2104
|
+
class MaxPipe {
|
|
2105
|
+
transform(value, key) {
|
|
2106
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
2107
|
+
return undefined;
|
|
2108
|
+
}
|
|
2109
|
+
if (!key) {
|
|
2110
|
+
const numbers = value.filter((item) => typeof item === 'number' && !isNaN(item));
|
|
2111
|
+
return numbers.length === 0 ? undefined : Math.max(...numbers);
|
|
2112
|
+
}
|
|
2113
|
+
const numbers = value
|
|
2114
|
+
.map(item => this.getNestedValue(item, key))
|
|
2115
|
+
.filter((val) => typeof val === 'number' && !isNaN(val));
|
|
2116
|
+
return numbers.length === 0 ? undefined : Math.max(...numbers);
|
|
2117
|
+
}
|
|
2118
|
+
getNestedValue(obj, path) {
|
|
2119
|
+
return path.split('.').reduce((current, segment) => current?.[segment], obj);
|
|
2120
|
+
}
|
|
2121
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MaxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2122
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: MaxPipe, isStandalone: true, name: "max" });
|
|
2123
|
+
}
|
|
2124
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MaxPipe, decorators: [{
|
|
2125
|
+
type: Pipe,
|
|
2126
|
+
args: [{
|
|
2127
|
+
name: 'max',
|
|
2128
|
+
standalone: true,
|
|
2129
|
+
}]
|
|
2130
|
+
}] });
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* SumPipe: Returns the sum of all numeric values in an array.
|
|
2134
|
+
*
|
|
2135
|
+
* Supports primitive number arrays and object arrays by property key with dot notation.
|
|
2136
|
+
*
|
|
2137
|
+
* @param {unknown[]} value - The array to evaluate.
|
|
2138
|
+
* @param {string} [key] - Optional property path for object summation (supports dot notation).
|
|
2139
|
+
*
|
|
2140
|
+
* @returns {number | undefined} - The total, or undefined if the array is empty/invalid.
|
|
2141
|
+
*
|
|
2142
|
+
* @example
|
|
2143
|
+
* {{ [10, 20, 30] | sum }} // 60
|
|
2144
|
+
* {{ items | sum:'price' }} // total price
|
|
2145
|
+
* {{ orders | sum:'meta.total' }} // grand total
|
|
2146
|
+
*/
|
|
2147
|
+
class SumPipe {
|
|
2148
|
+
transform(value, key) {
|
|
2149
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
2150
|
+
return undefined;
|
|
2151
|
+
}
|
|
2152
|
+
if (!key) {
|
|
2153
|
+
const numbers = value.filter((item) => typeof item === 'number' && !isNaN(item));
|
|
2154
|
+
return numbers.length === 0 ? undefined : numbers.reduce((acc, n) => acc + n, 0);
|
|
2155
|
+
}
|
|
2156
|
+
const numbers = value
|
|
2157
|
+
.map(item => this.getNestedValue(item, key))
|
|
2158
|
+
.filter((val) => typeof val === 'number' && !isNaN(val));
|
|
2159
|
+
return numbers.length === 0 ? undefined : numbers.reduce((acc, n) => acc + n, 0);
|
|
2160
|
+
}
|
|
2161
|
+
getNestedValue(obj, path) {
|
|
2162
|
+
return path.split('.').reduce((current, segment) => current?.[segment], obj);
|
|
2163
|
+
}
|
|
2164
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: SumPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2165
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: SumPipe, isStandalone: true, name: "sum" });
|
|
2166
|
+
}
|
|
2167
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: SumPipe, decorators: [{
|
|
2168
|
+
type: Pipe,
|
|
2169
|
+
args: [{
|
|
2170
|
+
name: 'sum',
|
|
2171
|
+
standalone: true,
|
|
2172
|
+
}]
|
|
2173
|
+
}] });
|
|
2174
|
+
|
|
2175
|
+
/**
|
|
2176
|
+
* AveragePipe: Returns the arithmetic mean of all numeric values in an array.
|
|
2177
|
+
*
|
|
2178
|
+
* Supports primitive number arrays and object arrays by property key with dot notation.
|
|
2179
|
+
*
|
|
2180
|
+
* @param {unknown[]} value - The array to evaluate.
|
|
2181
|
+
* @param {string} [key] - Optional property path for object averaging (supports dot notation).
|
|
2182
|
+
*
|
|
2183
|
+
* @returns {number | undefined} - The average, or undefined if the array is empty/invalid.
|
|
2184
|
+
*
|
|
2185
|
+
* @example
|
|
2186
|
+
* {{ [10, 20, 30] | average }} // 20
|
|
2187
|
+
* {{ students | average:'grade' }} // average grade
|
|
2188
|
+
* {{ reviews | average:'meta.rating' }} // average rating
|
|
2189
|
+
*/
|
|
2190
|
+
class AveragePipe {
|
|
2191
|
+
transform(value, key) {
|
|
2192
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
2193
|
+
return undefined;
|
|
2194
|
+
}
|
|
2195
|
+
if (!key) {
|
|
2196
|
+
const numbers = value.filter((item) => typeof item === 'number' && !isNaN(item));
|
|
2197
|
+
return numbers.length === 0 ? undefined : numbers.reduce((acc, n) => acc + n, 0) / numbers.length;
|
|
2198
|
+
}
|
|
2199
|
+
const numbers = value
|
|
2200
|
+
.map(item => this.getNestedValue(item, key))
|
|
2201
|
+
.filter((val) => typeof val === 'number' && !isNaN(val));
|
|
2202
|
+
return numbers.length === 0 ? undefined : numbers.reduce((acc, n) => acc + n, 0) / numbers.length;
|
|
2203
|
+
}
|
|
2204
|
+
getNestedValue(obj, path) {
|
|
2205
|
+
return path.split('.').reduce((current, segment) => current?.[segment], obj);
|
|
2206
|
+
}
|
|
2207
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: AveragePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2208
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: AveragePipe, isStandalone: true, name: "average" });
|
|
2209
|
+
}
|
|
2210
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: AveragePipe, decorators: [{
|
|
2211
|
+
type: Pipe,
|
|
2212
|
+
args: [{
|
|
2213
|
+
name: 'average',
|
|
2214
|
+
standalone: true,
|
|
2215
|
+
}]
|
|
2216
|
+
}] });
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* PercentagePipe: Calculates what percentage a value represents of a total.
|
|
2220
|
+
*
|
|
2221
|
+
* Returns `(value / total) * 100`, optionally rounded to a given number of decimal places.
|
|
2222
|
+
*
|
|
2223
|
+
* @param {number} value - The partial value.
|
|
2224
|
+
* @param {number} total - The total/whole value.
|
|
2225
|
+
* @param {number} [decimals] - Optional number of decimal places to round to.
|
|
2226
|
+
*
|
|
2227
|
+
* @returns {number | undefined} - The percentage, or undefined if inputs are invalid.
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* {{ 25 | percentage:200 }} // 12.5
|
|
2231
|
+
* {{ 1 | percentage:3:2 }} // 33.33
|
|
2232
|
+
* {{ 750 | percentage:1000 }} // 75
|
|
2233
|
+
*/
|
|
2234
|
+
class PercentagePipe {
|
|
2235
|
+
transform(value, total, decimals) {
|
|
2236
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2237
|
+
return undefined;
|
|
2238
|
+
}
|
|
2239
|
+
if (typeof total !== 'number' || isNaN(total) || total === 0) {
|
|
2240
|
+
return undefined;
|
|
2241
|
+
}
|
|
2242
|
+
const result = (value / total) * 100;
|
|
2243
|
+
if (typeof decimals === 'number' && decimals >= 0) {
|
|
2244
|
+
const factor = Math.pow(10, decimals);
|
|
2245
|
+
return Math.round(result * factor) / factor;
|
|
2246
|
+
}
|
|
2247
|
+
return result;
|
|
2248
|
+
}
|
|
2249
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: PercentagePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2250
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: PercentagePipe, isStandalone: true, name: "percentage" });
|
|
2251
|
+
}
|
|
2252
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: PercentagePipe, decorators: [{
|
|
2253
|
+
type: Pipe,
|
|
2254
|
+
args: [{
|
|
2255
|
+
name: 'percentage',
|
|
2256
|
+
standalone: true,
|
|
2257
|
+
}]
|
|
2258
|
+
}] });
|
|
2259
|
+
|
|
2260
|
+
/**
|
|
2261
|
+
* CeilPipe: Rounds a number up to the specified number of decimal places.
|
|
2262
|
+
*
|
|
2263
|
+
* Uses `Math.ceil` — always rounds toward positive infinity.
|
|
2264
|
+
*
|
|
2265
|
+
* @param {number} value - The number to round up.
|
|
2266
|
+
* @param {number} [precision=0] - Number of decimal places to preserve (defaults to 0 = integer).
|
|
2267
|
+
*
|
|
2268
|
+
* @returns {number | undefined} - The rounded-up value, or undefined if the input is invalid.
|
|
2269
|
+
*
|
|
2270
|
+
* @example
|
|
2271
|
+
* {{ 4.1 | ceil }} // 5
|
|
2272
|
+
* {{ 4.123 | ceil:2 }} // 4.13
|
|
2273
|
+
* {{ 0.001 | ceil:2 }} // 0.01
|
|
2274
|
+
* {{ -4.9 | ceil }} // -4
|
|
2275
|
+
*/
|
|
2276
|
+
class CeilPipe {
|
|
2277
|
+
transform(value, precision = 0) {
|
|
2278
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2279
|
+
return undefined;
|
|
2280
|
+
}
|
|
2281
|
+
if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
|
|
2282
|
+
return undefined;
|
|
2283
|
+
}
|
|
2284
|
+
const factor = Math.pow(10, precision);
|
|
2285
|
+
return Math.ceil(value * factor) / factor;
|
|
2286
|
+
}
|
|
2287
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: CeilPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2288
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: CeilPipe, isStandalone: true, name: "ceil" });
|
|
2289
|
+
}
|
|
2290
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: CeilPipe, decorators: [{
|
|
2291
|
+
type: Pipe,
|
|
2292
|
+
args: [{
|
|
2293
|
+
name: 'ceil',
|
|
2294
|
+
standalone: true,
|
|
2295
|
+
}]
|
|
2296
|
+
}] });
|
|
2297
|
+
|
|
2298
|
+
/**
|
|
2299
|
+
* FloorPipe: Rounds a number down to the specified number of decimal places.
|
|
2300
|
+
*
|
|
2301
|
+
* Uses `Math.floor` — always rounds toward negative infinity.
|
|
2302
|
+
*
|
|
2303
|
+
* @param {number} value - The number to round down.
|
|
2304
|
+
* @param {number} [precision=0] - Number of decimal places to preserve (defaults to 0 = integer).
|
|
2305
|
+
*
|
|
2306
|
+
* @returns {number | undefined} - The rounded-down value, or undefined if the input is invalid.
|
|
2307
|
+
*
|
|
2308
|
+
* @example
|
|
2309
|
+
* {{ 4.9 | floor }} // 4
|
|
2310
|
+
* {{ 4.567 | floor:2 }} // 4.56
|
|
2311
|
+
* {{ 0.999 | floor:1 }} // 0.9
|
|
2312
|
+
* {{ -4.1 | floor }} // -5
|
|
2313
|
+
*/
|
|
2314
|
+
class FloorPipe {
|
|
2315
|
+
transform(value, precision = 0) {
|
|
2316
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2317
|
+
return undefined;
|
|
2318
|
+
}
|
|
2319
|
+
if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
|
|
2320
|
+
return undefined;
|
|
2321
|
+
}
|
|
2322
|
+
const factor = Math.pow(10, precision);
|
|
2323
|
+
return Math.floor(value * factor) / factor;
|
|
2324
|
+
}
|
|
2325
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: FloorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2326
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: FloorPipe, isStandalone: true, name: "floor" });
|
|
2327
|
+
}
|
|
2328
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: FloorPipe, decorators: [{
|
|
2329
|
+
type: Pipe,
|
|
2330
|
+
args: [{
|
|
2331
|
+
name: 'floor',
|
|
2332
|
+
standalone: true,
|
|
2333
|
+
}]
|
|
2334
|
+
}] });
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* RoundPipe: Rounds a number to the nearest value at the specified number of decimal places.
|
|
2338
|
+
*
|
|
2339
|
+
* Uses `Math.round` — rounds half-up (e.g. 2.5 → 3, -2.5 → -2).
|
|
2340
|
+
*
|
|
2341
|
+
* @param {number} value - The number to round.
|
|
2342
|
+
* @param {number} [precision=0] - Number of decimal places to preserve (defaults to 0 = integer).
|
|
2343
|
+
*
|
|
2344
|
+
* @returns {number | undefined} - The rounded value, or undefined if the input is invalid.
|
|
2345
|
+
*
|
|
2346
|
+
* @example
|
|
2347
|
+
* {{ 4.4 | round }} // 4
|
|
2348
|
+
* {{ 4.5 | round }} // 5
|
|
2349
|
+
* {{ 4.567 | round:2 }} // 4.57
|
|
2350
|
+
* {{ 0.125 | round:2 }} // 0.13
|
|
2351
|
+
*/
|
|
2352
|
+
class RoundPipe {
|
|
2353
|
+
transform(value, precision = 0) {
|
|
2354
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2355
|
+
return undefined;
|
|
2356
|
+
}
|
|
2357
|
+
if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
|
|
2358
|
+
return undefined;
|
|
2359
|
+
}
|
|
2360
|
+
const factor = Math.pow(10, precision);
|
|
2361
|
+
return Math.round(value * factor) / factor;
|
|
2362
|
+
}
|
|
2363
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: RoundPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2364
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: RoundPipe, isStandalone: true, name: "round" });
|
|
2365
|
+
}
|
|
2366
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: RoundPipe, decorators: [{
|
|
2367
|
+
type: Pipe,
|
|
2368
|
+
args: [{
|
|
2369
|
+
name: 'round',
|
|
2370
|
+
standalone: true,
|
|
2371
|
+
}]
|
|
2372
|
+
}] });
|
|
2373
|
+
|
|
2374
|
+
/**
|
|
2375
|
+
* SqrtPipe: Returns the square root of a number.
|
|
2376
|
+
*
|
|
2377
|
+
* Uses `Math.sqrt`. Returns undefined for negative numbers.
|
|
2378
|
+
*
|
|
2379
|
+
* @param {number} value - The number to compute the square root of.
|
|
2380
|
+
*
|
|
2381
|
+
* @returns {number | undefined} - The square root, or undefined if the input is invalid or negative.
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* {{ 9 | sqrt }} // 3
|
|
2385
|
+
* {{ 2 | sqrt }} // 1.4142135623730951
|
|
2386
|
+
* {{ 144 | sqrt }} // 12
|
|
2387
|
+
*/
|
|
2388
|
+
class SqrtPipe {
|
|
2389
|
+
transform(value) {
|
|
2390
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2391
|
+
return undefined;
|
|
2392
|
+
}
|
|
2393
|
+
if (value < 0) {
|
|
2394
|
+
return undefined;
|
|
2395
|
+
}
|
|
2396
|
+
return Math.sqrt(value);
|
|
2397
|
+
}
|
|
2398
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: SqrtPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2399
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: SqrtPipe, isStandalone: true, name: "sqrt" });
|
|
2400
|
+
}
|
|
2401
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: SqrtPipe, decorators: [{
|
|
2402
|
+
type: Pipe,
|
|
2403
|
+
args: [{
|
|
2404
|
+
name: 'sqrt',
|
|
2405
|
+
standalone: true,
|
|
2406
|
+
}]
|
|
2407
|
+
}] });
|
|
2408
|
+
|
|
2409
|
+
/**
|
|
2410
|
+
* PowPipe: Raises a number to the specified power.
|
|
2411
|
+
*
|
|
2412
|
+
* Uses `Math.pow`. The exponent defaults to 2 (squaring).
|
|
2413
|
+
*
|
|
2414
|
+
* @param {number} value - The base number.
|
|
2415
|
+
* @param {number} [exponent=2] - The power to raise the base to (defaults to 2).
|
|
2416
|
+
*
|
|
2417
|
+
* @returns {number | undefined} - The result, or undefined if the inputs are invalid.
|
|
2418
|
+
*
|
|
2419
|
+
* @example
|
|
2420
|
+
* {{ 3 | pow }} // 9 (3^2)
|
|
2421
|
+
* {{ 2 | pow:3 }} // 8 (2^3)
|
|
2422
|
+
* {{ 5 | pow:0 }} // 1 (anything^0)
|
|
2423
|
+
*/
|
|
2424
|
+
class PowPipe {
|
|
2425
|
+
transform(value, exponent = 2) {
|
|
2426
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2427
|
+
return undefined;
|
|
2428
|
+
}
|
|
2429
|
+
if (typeof exponent !== 'number' || isNaN(exponent)) {
|
|
2430
|
+
return undefined;
|
|
2431
|
+
}
|
|
2432
|
+
return Math.pow(value, exponent);
|
|
2433
|
+
}
|
|
2434
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: PowPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2435
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: PowPipe, isStandalone: true, name: "pow" });
|
|
2436
|
+
}
|
|
2437
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: PowPipe, decorators: [{
|
|
2438
|
+
type: Pipe,
|
|
2439
|
+
args: [{
|
|
2440
|
+
name: 'pow',
|
|
2441
|
+
standalone: true,
|
|
2442
|
+
}]
|
|
2443
|
+
}] });
|
|
2444
|
+
|
|
2445
|
+
/**
|
|
2446
|
+
* DegreesPipe: Converts a value in radians to degrees.
|
|
2447
|
+
*
|
|
2448
|
+
* Formula: `degrees = radians * (180 / Math.PI)`
|
|
2449
|
+
*
|
|
2450
|
+
* @param {number} value - The angle in radians.
|
|
2451
|
+
*
|
|
2452
|
+
* @returns {number | undefined} - The angle in degrees, or undefined if the input is invalid.
|
|
2453
|
+
*
|
|
2454
|
+
* @example
|
|
2455
|
+
* {{ 3.14159 | degrees }} // ~180
|
|
2456
|
+
* {{ 1.5708 | degrees }} // ~90
|
|
2457
|
+
* {{ 0 | degrees }} // 0
|
|
2458
|
+
*/
|
|
2459
|
+
class DegreesPipe {
|
|
2460
|
+
transform(value) {
|
|
2461
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2462
|
+
return undefined;
|
|
2463
|
+
}
|
|
2464
|
+
return value * (180 / Math.PI);
|
|
2465
|
+
}
|
|
2466
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: DegreesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2467
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: DegreesPipe, isStandalone: true, name: "degrees" });
|
|
2468
|
+
}
|
|
2469
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: DegreesPipe, decorators: [{
|
|
2470
|
+
type: Pipe,
|
|
2471
|
+
args: [{
|
|
2472
|
+
name: 'degrees',
|
|
2473
|
+
standalone: true,
|
|
2474
|
+
}]
|
|
2475
|
+
}] });
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* BytesPipe: Formats a number of bytes into a human-readable string with appropriate units.
|
|
2479
|
+
*
|
|
2480
|
+
* Supports both binary (1024-based: KiB, MiB, GiB) and decimal (1000-based: KB, MB, GB) units.
|
|
2481
|
+
* Defaults to decimal (1000-based) units.
|
|
2482
|
+
*
|
|
2483
|
+
* @param {number} value - The number of bytes.
|
|
2484
|
+
* @param {number} [decimals=1] - Number of decimal places in the output.
|
|
2485
|
+
* @param {string} [base='decimal'] - Unit base: 'decimal' (1000, KB/MB/GB) or 'binary' (1024, KiB/MiB/GiB).
|
|
2486
|
+
*
|
|
2487
|
+
* @returns {string | undefined} - The formatted string, or undefined if the input is invalid.
|
|
2488
|
+
*
|
|
2489
|
+
* @example
|
|
2490
|
+
* {{ 1536 | bytes }} // "1.5 KB"
|
|
2491
|
+
* {{ 1048576 | bytes:2 }} // "1.05 MB"
|
|
2492
|
+
* {{ 1073741824 | bytes:1:'binary' }} // "1.0 GiB"
|
|
2493
|
+
*/
|
|
2494
|
+
class BytesPipe {
|
|
2495
|
+
decimalUnits = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'];
|
|
2496
|
+
binaryUnits = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
|
|
2497
|
+
transform(value, decimals = 1, base = 'decimal') {
|
|
2498
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2499
|
+
return undefined;
|
|
2500
|
+
}
|
|
2501
|
+
if (value < 0) {
|
|
2502
|
+
return undefined;
|
|
2503
|
+
}
|
|
2504
|
+
if (value === 0) {
|
|
2505
|
+
return '0 B';
|
|
2506
|
+
}
|
|
2507
|
+
const isBinary = base === 'binary';
|
|
2508
|
+
const divisor = isBinary ? 1024 : 1000;
|
|
2509
|
+
const units = isBinary ? this.binaryUnits : this.decimalUnits;
|
|
2510
|
+
let unitIndex = 0;
|
|
2511
|
+
let size = value;
|
|
2512
|
+
while (size >= divisor && unitIndex < units.length - 1) {
|
|
2513
|
+
size /= divisor;
|
|
2514
|
+
unitIndex++;
|
|
2515
|
+
}
|
|
2516
|
+
const precision = typeof decimals === 'number' && decimals >= 0 ? decimals : 1;
|
|
2517
|
+
return `${size.toFixed(precision)} ${units[unitIndex]}`;
|
|
2518
|
+
}
|
|
2519
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: BytesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2520
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: BytesPipe, isStandalone: true, name: "bytes" });
|
|
2521
|
+
}
|
|
2522
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: BytesPipe, decorators: [{
|
|
2523
|
+
type: Pipe,
|
|
2524
|
+
args: [{
|
|
2525
|
+
name: 'bytes',
|
|
2526
|
+
standalone: true,
|
|
2527
|
+
}]
|
|
2528
|
+
}] });
|
|
2529
|
+
|
|
2530
|
+
/**
|
|
2531
|
+
* RadiansPipe: Converts a value in degrees to radians.
|
|
2532
|
+
*
|
|
2533
|
+
* Formula: `radians = degrees * (Math.PI / 180)`
|
|
2534
|
+
*
|
|
2535
|
+
* @param {number} value - The angle in degrees.
|
|
2536
|
+
*
|
|
2537
|
+
* @returns {number | undefined} - The angle in radians, or undefined if the input is invalid.
|
|
2538
|
+
*
|
|
2539
|
+
* @example
|
|
2540
|
+
* {{ 180 | radians }} // ~3.14159
|
|
2541
|
+
* {{ 90 | radians }} // ~1.5708
|
|
2542
|
+
* {{ 0 | radians }} // 0
|
|
2543
|
+
*/
|
|
2544
|
+
class RadiansPipe {
|
|
2545
|
+
transform(value) {
|
|
2546
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
2547
|
+
return undefined;
|
|
2548
|
+
}
|
|
2549
|
+
return value * (Math.PI / 180);
|
|
2550
|
+
}
|
|
2551
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: RadiansPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2552
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.3", ngImport: i0, type: RadiansPipe, isStandalone: true, name: "radians" });
|
|
2553
|
+
}
|
|
2554
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: RadiansPipe, decorators: [{
|
|
2555
|
+
type: Pipe,
|
|
2556
|
+
args: [{
|
|
2557
|
+
name: 'radians',
|
|
2558
|
+
standalone: true,
|
|
2559
|
+
}]
|
|
2560
|
+
}] });
|
|
2561
|
+
|
|
2046
2562
|
// Text
|
|
2047
2563
|
const ALL_PIPES = [
|
|
2048
2564
|
// Text
|
|
@@ -2093,7 +2609,21 @@ const ALL_PIPES = [
|
|
|
2093
2609
|
WithoutPipe,
|
|
2094
2610
|
SomePipe,
|
|
2095
2611
|
UnionPipe,
|
|
2096
|
-
FilterByPipe
|
|
2612
|
+
FilterByPipe,
|
|
2613
|
+
// Math
|
|
2614
|
+
MinPipe,
|
|
2615
|
+
MaxPipe,
|
|
2616
|
+
SumPipe,
|
|
2617
|
+
AveragePipe,
|
|
2618
|
+
PercentagePipe,
|
|
2619
|
+
CeilPipe,
|
|
2620
|
+
FloorPipe,
|
|
2621
|
+
RoundPipe,
|
|
2622
|
+
SqrtPipe,
|
|
2623
|
+
PowPipe,
|
|
2624
|
+
DegreesPipe,
|
|
2625
|
+
BytesPipe,
|
|
2626
|
+
RadiansPipe,
|
|
2097
2627
|
];
|
|
2098
2628
|
|
|
2099
2629
|
// Text
|
|
@@ -2102,5 +2632,5 @@ const ALL_PIPES = [
|
|
|
2102
2632
|
* Generated bundle index. Do not edit.
|
|
2103
2633
|
*/
|
|
2104
2634
|
|
|
2105
|
-
export { ALL_PIPES, AsciiArtPipe, BarcodePipe, CamelCasePipe, ChunkPipe, ColorConvertPipe, CountPipe, CreditCardMaskPipe, DeviceTypePipe, DiffPipe, EmailMaskPipe, EveryPipe, FilterByPipe, Flatten, GravatarPipe, GroupByPipe, HighlightPipe, HtmlEscapePipe, HtmlSanitizePipe, InitialPipe, InitialsPipe, IntersectionPipe, IpAddressMaskPipe, JsonPrettyPipe, KebabCasePipe, MorseCodePipe, OrderByPipe, PluckPipe, QrCodePipe, RangePipe, ReplacePipe, ReversePipe, SamplePipe, ShufflePipe, SnakeCasePipe, SomePipe, TailPipe, TextToSpeechPipe, TimeAgoPipePipe, TitleCasePipe, TruncatePipe, TruthifyPipe, UnionPipe, UniquePipe, WithoutPipe };
|
|
2635
|
+
export { ALL_PIPES, AsciiArtPipe, AveragePipe, BarcodePipe, BytesPipe, CamelCasePipe, CeilPipe, ChunkPipe, ColorConvertPipe, CountPipe, CreditCardMaskPipe, DegreesPipe, DeviceTypePipe, DiffPipe, EmailMaskPipe, EveryPipe, FilterByPipe, Flatten, FloorPipe, GravatarPipe, GroupByPipe, HighlightPipe, HtmlEscapePipe, HtmlSanitizePipe, InitialPipe, InitialsPipe, IntersectionPipe, IpAddressMaskPipe, JsonPrettyPipe, KebabCasePipe, MaxPipe, MinPipe, MorseCodePipe, OrderByPipe, PercentagePipe, PluckPipe, PowPipe, QrCodePipe, RadiansPipe, RangePipe, ReplacePipe, ReversePipe, RoundPipe, SamplePipe, ShufflePipe, SnakeCasePipe, SomePipe, SqrtPipe, SumPipe, TailPipe, TextToSpeechPipe, TimeAgoPipePipe, TitleCasePipe, TruncatePipe, TruthifyPipe, UnionPipe, UniquePipe, WithoutPipe };
|
|
2106
2636
|
//# sourceMappingURL=ngx-transforms.mjs.map
|