@obliczeniowo/elementary
Version:
Library made in Angular version 20
552 lines (538 loc) • 15.5 kB
JavaScript
import * as i0 from '@angular/core';
import { Pipe } from '@angular/core';
import { TranslationPipe } from '@obliczeniowo/elementary/text-pipes';
import { ElementaryMath } from '@obliczeniowo/elementary/math';
const units = {
basic: [
{
unit: '',
max: 0,
},
{
unit: '',
max: 1e3,
},
{
unit: 'k',
max: 1e6,
},
{
unit: 'M',
max: 1e9,
},
{
unit: 'G',
max: 1e12,
},
{
unit: 'T',
max: 1e15,
},
{
unit: 'P',
max: 1e18,
},
{
unit: 'E',
max: 1e21,
},
{
unit: 'Z',
max: 1e24,
},
{
unit: 'Y',
max: 1e27,
},
{
unit: 'R',
max: 1e30,
},
{
unit: 'Q',
max: Infinity,
},
],
fullInteger: [
{
unit: '',
max: 0,
},
{
unit: '',
max: 10,
},
{
unit: 'da',
max: 1e2,
},
{
unit: 'h',
max: 1e3,
},
{
unit: 'k',
max: 1e6,
},
{
unit: 'M',
max: 1e9,
},
{
unit: 'G',
max: 1e12,
},
{
unit: 'T',
max: 1e15,
},
{
unit: 'P',
max: 1e18,
},
{
unit: 'E',
max: 1e21,
},
{
unit: 'Z',
max: 1e24,
},
{
unit: 'Y',
max: 1e27,
},
{
unit: 'R',
max: 1e30,
},
{
unit: 'Q',
max: Infinity,
},
],
decimal: [
{
unit: 'none',
max: 1e-30,
},
{
unit: 'q',
max: 1e-27,
},
{
unit: 'r',
max: 1e-24,
},
{
unit: 'y',
max: 1e-21,
},
{
unit: 'z',
max: 1e-18,
},
{
unit: 'a',
max: 1e-15,
},
{
unit: 'f',
max: 1e-12,
},
{
unit: 'p',
max: 1e-9,
},
{
unit: 'n',
max: 1e-6,
},
{
unit: 'µ',
max: 1e-3,
},
{
unit: 'm',
max: 1,
},
{
unit: '',
max: 1e3,
},
{
unit: 'k',
max: 1e6,
},
{
unit: 'M',
max: 1e9,
},
{
unit: 'G',
max: 1e12,
},
{
unit: 'T',
max: 1e15,
},
{
unit: 'P',
max: 1e18,
},
{
unit: 'E',
max: 1e21,
},
{
unit: 'Z',
max: 1e24,
},
{
unit: 'Y',
max: 1e27,
},
{
unit: 'R',
max: 1e30,
},
{
unit: 'Q',
max: Infinity,
},
],
fullDecimal: [
{
unit: 'none',
max: 1e-30,
},
{
unit: 'q',
max: 1e-27,
},
{
unit: 'r',
max: 1e-24,
},
{
unit: 'y',
max: 1e-21,
},
{
unit: 'z',
max: 1e-18,
},
{
unit: 'a',
max: 1e-15,
},
{
unit: 'f',
max: 1e-12,
},
{
unit: 'p',
max: 1e-9,
},
{
unit: 'n',
max: 1e-6,
},
{
unit: 'µ',
max: 1e-3,
},
{
unit: 'm',
max: 0.01,
},
{
unit: 'c',
max: 0.1,
},
{
unit: 'd',
max: 1,
},
{
unit: '',
max: 10,
},
{
unit: 'da',
max: 1e2,
},
{
unit: 'h',
max: 1e3,
},
{
unit: 'k',
max: 1e6,
},
{
unit: 'M',
max: 1e9,
},
{
unit: 'G',
max: 1e12,
},
{
unit: 'T',
max: 1e15,
},
{
unit: 'P',
max: 1e18,
},
{
unit: 'E',
max: 1e21,
},
{
unit: 'Z',
max: 1e24,
},
{
unit: 'Y',
max: 1e27,
},
{
unit: 'R',
max: 1e30,
},
{
unit: 'Q',
max: Infinity,
},
],
};
const phonetic = {
q: 'quecto',
r: 'ronto',
y: 'jokto',
z: 'zepto',
a: 'atto',
f: 'femto',
p: 'piko',
n: 'nano',
µ: 'mikro',
m: 'mili',
c: 'centy',
d: 'decy',
da: 'deka',
h: 'hekta',
k: 'kilo',
M: 'mega',
G: 'giga',
T: 'tera',
P: 'peta',
E: 'eksa',
Z: 'zetta',
Y: 'jotta',
R: 'roanna',
Q: 'quetta',
};
/**
* Transform number from '12345' to '12.35 k'
* Can use basic units: [k, M, G, ...]
* Or in fullInteger type: [da, h, k, M, ...]
* Ot in decimal type: [..., m, , k, ...]
* Ot in fullDecimal type: [..., m, c, d, , da, h, k, ...]
*/
class UnitsPipe {
translate = new TranslationPipe();
transform(value, options) {
const { type, precision, translations } = options || {};
const unitsSet = units[type || 'basic'];
if (value === 0) {
return value.toString();
}
let index = 1;
const v = Math.abs(value);
const max = () => unitsSet[index - 1].max || 1;
const toFixed = () => +(v / max()).toFixed(precision) * max();
while ((toFixed() >= unitsSet[index].max || v / unitsSet[index].max === 1) &&
index < unitsSet.length) {
index += 1;
}
return ((value / max()).toFixed(precision) +
(unitsSet[index].unit !== ''
? ' ' +
this.translate.transform(unitsSet[index].unit, ((translations === 'phonetic' && phonetic) ||
translations ||
{}))
: ''));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: UnitsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: UnitsPipe, isStandalone: true, name: "oblUnits" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: UnitsPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblUnits',
standalone: true,
}]
}] });
class LimitsPipe {
transform(value, options) {
return value.map(value => {
value = ElementaryMath.minmax(value || 0, (options?.min !== undefined && options.min >= 0 && options.min) || 0, options?.max ?? Infinity);
const [type, roundType] = options?.transformTo?.split('-') || [];
return type === 'int' ? this.roundTo(value, roundType) : value;
});
}
roundTo(value, type) {
switch (type) {
case 'floor':
return Math.floor(value);
case 'ceil':
return Math.ceil(value);
case 'round':
return Math.round(value);
default:
return value;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: LimitsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: LimitsPipe, isStandalone: true, name: "oblLimits" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: LimitsPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblLimits',
standalone: true,
}]
}] });
class IntFilterPipe {
transform(value) {
return value.filter(v => v === Math.floor(v));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: IntFilterPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: IntFilterPipe, isStandalone: true, name: "oblIntFilter" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: IntFilterPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblIntFilter',
standalone: true
}]
}] });
class RangeFilterPipe {
transform(value, min, max) {
return value.filter((v) => v >= (min || Number.NEGATIVE_INFINITY) && v <= (max || Infinity));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: RangeFilterPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: RangeFilterPipe, isStandalone: true, name: "oblRangeFilter" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: RangeFilterPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblRangeFilter',
standalone: true,
}]
}] });
class AbsPipe {
transform(value) {
return value.map(v => Math.abs(v));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: AbsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: AbsPipe, isStandalone: true, name: "oblAbs" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: AbsPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblAbs',
standalone: true
}]
}] });
class UIntFilterPipe {
transform(value, max) {
return value.filter(v => v === Math.floor(v) && v >= 0 && v <= (max || Infinity));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: UIntFilterPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: UIntFilterPipe, isStandalone: true, name: "oblUIntFilter" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: UIntFilterPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblUIntFilter',
standalone: true
}]
}] });
class MathPipe {
transform(value, operations) {
return ElementaryMath.calculate(operations, { x: value });
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MathPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: MathPipe, isStandalone: true, name: "oblMath" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MathPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblMath',
standalone: true
}]
}] });
class IsNumericPipe {
transform(value, fully) {
return ElementaryMath.isNumeric(value, fully);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: IsNumericPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: IsNumericPipe, isStandalone: true, name: "oblIsNumeric" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: IsNumericPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblIsNumeric',
standalone: true
}]
}] });
class MinMaxPipe {
transform(numbers) {
return ElementaryMath.getMinMax(numbers);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MinMaxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: MinMaxPipe, isStandalone: true, name: "oblMinMax" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MinMaxPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblMinMax',
standalone: true
}]
}] });
class MinPipe {
transform(value) {
return Math.min(...value);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MinPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: MinPipe, isStandalone: true, name: "oblMin" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MinPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblMin',
standalone: true
}]
}] });
class MaxPipe {
transform(value) {
return Math.max(...value);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MaxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: MaxPipe, isStandalone: true, name: "oblMax" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: MaxPipe, decorators: [{
type: Pipe,
args: [{
name: 'oblMax',
standalone: true
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { AbsPipe, IntFilterPipe, IsNumericPipe, LimitsPipe, MathPipe, MaxPipe, MinMaxPipe, MinPipe, RangeFilterPipe, UIntFilterPipe, UnitsPipe };
//# sourceMappingURL=obliczeniowo-elementary-numeric-pipes.mjs.map