@rainbow-o23/n1 1.0.50 → 1.0.51

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.
Files changed (30) hide show
  1. package/index.cjs +10 -579
  2. package/index.js +9 -539
  3. package/lib/envs.d.ts +1 -1
  4. package/lib/pipeline/index.d.ts +0 -2
  5. package/lib/pipeline/step-helpers-utils.d.ts +1 -1
  6. package/package.json +2 -1
  7. package/rollup.config.base.js +4 -1
  8. package/src/lib/envs.ts +2 -20
  9. package/src/lib/pipeline/index.ts +0 -2
  10. package/src/lib/pipeline/step-helpers-utils.ts +7 -11
  11. package/lib/pipeline/step-helpers-value-operator.d.ts +0 -34
  12. package/lib/pipeline/value-operators/action-types.d.ts +0 -18
  13. package/lib/pipeline/value-operators/index.d.ts +0 -8
  14. package/lib/pipeline/value-operators/test-any-actions.d.ts +0 -10
  15. package/lib/pipeline/value-operators/test-decimal-actions.d.ts +0 -25
  16. package/lib/pipeline/value-operators/test-string-actions.d.ts +0 -2
  17. package/lib/pipeline/value-operators/testers.d.ts +0 -36
  18. package/lib/pipeline/value-operators/transform-decimal-actions.d.ts +0 -21
  19. package/lib/pipeline/value-operators/transform-string-actions.d.ts +0 -10
  20. package/lib/pipeline/value-operators/transformers.d.ts +0 -31
  21. package/src/lib/pipeline/step-helpers-value-operator.ts +0 -307
  22. package/src/lib/pipeline/value-operators/action-types.ts +0 -8
  23. package/src/lib/pipeline/value-operators/index.ts +0 -10
  24. package/src/lib/pipeline/value-operators/test-any-actions.ts +0 -58
  25. package/src/lib/pipeline/value-operators/test-decimal-actions.ts +0 -85
  26. package/src/lib/pipeline/value-operators/test-string-actions.ts +0 -15
  27. package/src/lib/pipeline/value-operators/testers.ts +0 -59
  28. package/src/lib/pipeline/value-operators/transform-decimal-actions.ts +0 -88
  29. package/src/lib/pipeline/value-operators/transform-string-actions.ts +0 -49
  30. package/src/lib/pipeline/value-operators/transformers.ts +0 -34
@@ -1,85 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import {ValueAction} from './action-types';
3
- import {toDecimal} from './transform-decimal-actions';
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export const isDecimal: ValueAction<any, Decimal> = (value?: any) => {
7
- const {test, value: decimal} = toDecimal(value);
8
- return {test, value: test ? decimal : value};
9
- };
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- export const isInteger: ValueAction<any, Decimal> = (value?: any) => {
12
- const {test, value: decimal} = toDecimal(value);
13
- return (test && decimal.isInteger()) ? {test: true, value: decimal} : {test: false, value};
14
- };
15
- export type DecimalInterval = 'closed' | 'c' | 'open' | 'o' | 'left-open' | 'lo' | 'right-open' | 'ro';
16
- export type DecimalInRangeOptions =
17
- & { interval?: DecimalInterval }
18
- & ({ min: Decimal.Value; max?: Decimal.Value; } | { min?: Decimal.Value; max: Decimal.Value; })
19
- /**
20
- * @param options.min value of range, might be included or not
21
- * @param options.max max value of range, might be included or not
22
- * @param options.interval closed, c -> [min, max]; open, o -> (min, max); left-open, lo -> (min, max]; right-open, ro -> [min, max)
23
- */
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- export const isInRange = (options: DecimalInRangeOptions): ValueAction<any, Decimal> => {
26
- const {min, max, interval = 'closed'} = options;
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- return (value?: any) => {
29
- const {test, value: decimal} = toDecimal(value);
30
- if (!test) {
31
- return {test: false, value};
32
- }
33
- let pass = false;
34
- switch (interval) {
35
- case 'open':
36
- case 'o':
37
- pass = (min == null || decimal.gt(min)) && (max == null || decimal.lt(max));
38
- break;
39
- case 'left-open':
40
- case 'lo':
41
- pass = (min == null || decimal.gt(min)) && (max == null || decimal.lte(max));
42
- break;
43
- case 'right-open':
44
- case 'ro':
45
- pass = (min == null || decimal.gte(min)) && (max == null || decimal.lt(max));
46
- break;
47
- case 'closed':
48
- case 'c':
49
- default:
50
- pass = (min == null || decimal.gte(min)) && (max == null || decimal.lte(max));
51
- break;
52
- }
53
- return pass ? {test: true, value: decimal} : {test: false, value};
54
- };
55
- };
56
- export const isPositive = isInRange({min: 0, interval: 'left-open'});
57
- export const isNotPositive = isInRange({max: 0});
58
- export const isNegative = isInRange({max: 0, interval: 'right-open'});
59
- export const isNotNegative = isInRange({min: 0});
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- export const isZero: ValueAction<any, Decimal> = (value?: any) => {
62
- const {test, value: decimal} = toDecimal(value);
63
- return (test && decimal.isZero()) ? {test: true, value: decimal} : {test: false, value};
64
- };
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- export const isNotZero: ValueAction<any, Decimal> = (value?: any) => {
67
- const {test, value: decimal} = toDecimal(value);
68
- return (test && !decimal.isZero()) ? {test: true, value: decimal} : {test: false, value};
69
- };
70
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- export const isGreaterThan = (compare: Decimal.Value): ValueAction<any, Decimal> => {
72
- return isInRange({min: compare, interval: 'left-open'});
73
- };
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- export const isGreaterThanOrEqual = (compare: Decimal.Value): ValueAction<any, Decimal> => {
76
- return isInRange({min: compare});
77
- };
78
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- export const isLessThan = (compare: Decimal.Value): ValueAction<any, Decimal> => {
80
- return isInRange({max: compare, interval: 'right-open'});
81
- };
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- export const isLessThanOrEqual = (compare: Decimal.Value): ValueAction<any, Decimal> => {
84
- return isInRange({max: compare});
85
- };
@@ -1,15 +0,0 @@
1
- import {ValueAction} from './action-types';
2
-
3
- export const regexp = (regexp: RegExp): ValueAction => {
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- return (value?: any) => {
6
- if (value == null) {
7
- return {test: false, value};
8
- }
9
- const type = typeof value;
10
- if (['string', 'number', 'bigint'].includes(type)) {
11
- return {test: regexp.test(value), value};
12
- }
13
- return {test: false, value};
14
- };
15
- };
@@ -1,59 +0,0 @@
1
- import {RegisteredValueAction, RegisteredValueActionWithParams} from './action-types';
2
- import {isBlank, isEmpty, isNotBlank, isNotEmpty, isNotNull, isNull} from './test-any-actions';
3
- import {
4
- isDecimal,
5
- isGreaterThan,
6
- isGreaterThanOrEqual,
7
- isInRange,
8
- isInteger,
9
- isLessThan,
10
- isLessThanOrEqual,
11
- isNegative,
12
- isNotNegative,
13
- isNotPositive,
14
- isNotZero,
15
- isPositive,
16
- isZero
17
- } from './test-decimal-actions';
18
- import {regexp} from './test-string-actions';
19
-
20
- const testers = {
21
- // any
22
- isNull: {type: 'func', func: isNull} as RegisteredValueAction,
23
- isNotNull: {type: 'func', func: isNotNull} as RegisteredValueAction,
24
- isEmpty: {type: 'func', func: isEmpty} as RegisteredValueAction,
25
- isNotEmpty: {type: 'func', func: isNotEmpty} as RegisteredValueAction,
26
- isBlank: {type: 'func', func: isBlank} as RegisteredValueAction,
27
- isNotBlank: {type: 'func', func: isNotBlank} as RegisteredValueAction,
28
- // string
29
- regexp: {type: 'param', func: regexp} as RegisteredValueActionWithParams<typeof regexp>,
30
- regex: {type: 'param', func: regexp} as RegisteredValueActionWithParams<typeof regexp>,
31
- matches: {type: 'param', func: regexp} as RegisteredValueActionWithParams<typeof regexp>,
32
- // decimal, return decimal if test pass
33
- isNumber: {type: 'func', func: isDecimal} as RegisteredValueAction,
34
- isDecimal: {type: 'func', func: isDecimal} as RegisteredValueAction,
35
- isInteger: {type: 'func', func: isInteger} as RegisteredValueAction,
36
- isInt: {type: 'func', func: isInteger} as RegisteredValueAction,
37
- isPositive: {type: 'func', func: isPositive} as RegisteredValueAction,
38
- isNotPositive: {type: 'func', func: isNotPositive} as RegisteredValueAction,
39
- isNegative: {type: 'func', func: isNegative} as RegisteredValueAction,
40
- isNotNegative: {type: 'func', func: isNotNegative} as RegisteredValueAction,
41
- isZero: {type: 'func', func: isZero} as RegisteredValueAction,
42
- isNotZero: {type: 'func', func: isNotZero} as RegisteredValueAction,
43
- // decimal with params, return decimal if test pass
44
- isGreaterThan: {type: 'param', func: isGreaterThan} as RegisteredValueActionWithParams<typeof isGreaterThan>,
45
- gt: {type: 'param', func: isGreaterThan} as RegisteredValueActionWithParams<typeof isGreaterThan>,
46
- isGreaterThanOrEqual: {
47
- type: 'param', func: isGreaterThanOrEqual
48
- } as RegisteredValueActionWithParams<typeof isGreaterThanOrEqual>,
49
- gte: {type: 'param', func: isGreaterThanOrEqual} as RegisteredValueActionWithParams<typeof isGreaterThanOrEqual>,
50
- isLessThan: {type: 'param', func: isLessThan} as RegisteredValueActionWithParams<typeof isLessThan>,
51
- lt: {type: 'param', func: isLessThan} as RegisteredValueActionWithParams<typeof isLessThan>,
52
- isLessThanOrEqual: {
53
- type: 'param', func: isLessThanOrEqual
54
- } as RegisteredValueActionWithParams<typeof isLessThanOrEqual>,
55
- lte: {type: 'param', func: isLessThanOrEqual} as RegisteredValueActionWithParams<typeof isLessThanOrEqual>,
56
- isInRange: {type: 'param', func: isInRange} as RegisteredValueActionWithParams<typeof isInRange>,
57
- within: {type: 'param', func: isInRange} as RegisteredValueActionWithParams<typeof isInRange>
58
- };
59
- export const AllTesters: Readonly<typeof testers> = testers;
@@ -1,88 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import {ValueAction} from './action-types';
3
-
4
- export enum Rounding {
5
- ROUND_UP = 'up',
6
- ROUND_DOWN = 'down',
7
- ROUND_CEIL = 'ceil',
8
- ROUND_FLOOR = 'floor',
9
- ROUND_HALF_UP = 'half-up',
10
- ROUND_HALF_DOWN = 'half-down',
11
- ROUND_HALF_EVEN = 'half-even',
12
- ROUND_HALF_CEIL = 'half-ceil',
13
- ROUND_HALF_FLOOR = 'half-floor'
14
- }
15
-
16
- const ToDecimalJsRounding = {
17
- [Rounding.ROUND_UP]: Decimal.ROUND_UP,
18
- [Rounding.ROUND_DOWN]: Decimal.ROUND_DOWN,
19
- [Rounding.ROUND_CEIL]: Decimal.ROUND_CEIL,
20
- [Rounding.ROUND_FLOOR]: Decimal.ROUND_FLOOR,
21
- [Rounding.ROUND_HALF_UP]: Decimal.ROUND_HALF_UP,
22
- [Rounding.ROUND_HALF_DOWN]: Decimal.ROUND_HALF_DOWN,
23
- [Rounding.ROUND_HALF_EVEN]: Decimal.ROUND_HALF_EVEN,
24
- [Rounding.ROUND_HALF_CEIL]: Decimal.ROUND_HALF_CEIL,
25
- [Rounding.ROUND_HALF_FLOOR]: Decimal.ROUND_HALF_FLOOR
26
- };
27
-
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- export const toDecimal: ValueAction<any, Decimal> = (value?: any) => {
30
- if (value == null) {
31
- return {test: false, value};
32
- } else if (value instanceof Decimal) {
33
- return {test: true, value};
34
- } else if (['string', 'number'].includes(typeof value)) {
35
- try {
36
- return {test: true, value: new Decimal(value)};
37
- } catch {
38
- return {test: false, value};
39
- }
40
- } else {
41
- return {test: false, value};
42
- }
43
- };
44
- /**
45
- * May cause precision loss or value truncation.
46
- */
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- export const toNumber: ValueAction<any, number> = (value?: any) => {
49
- const {test, value: parsed} = toDecimal(value);
50
- if (!test) {
51
- return {test: false, value};
52
- }
53
- return {test: true, value: parsed.toNumber()};
54
- };
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- export const toFixed = (fractionDigits: number, rounding: Rounding = Rounding.ROUND_HALF_UP): ValueAction<any, string> => {
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
- return (value?: any) => {
59
- const {test, value: parsed} = toDecimal(value);
60
- if (!test) {
61
- return {test: false, value};
62
- }
63
- return {test: true, value: parsed.toFixed(fractionDigits, ToDecimalJsRounding[rounding])};
64
- };
65
- };
66
- const baseRound = (rounding: Rounding = Rounding.ROUND_HALF_UP) => {
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- return (fractionDigits: number): ValueAction<any, Decimal> => {
69
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- return (value?: any) => {
71
- const {test, value: parsed} = toDecimal(value);
72
- if (!test) {
73
- return {test: false, value};
74
- }
75
- return {test: true, value: parsed.toDecimalPlaces(fractionDigits, ToDecimalJsRounding[rounding])};
76
- };
77
- };
78
- };
79
- /** half up */
80
- export const roundUp = baseRound(Rounding.ROUND_HALF_UP);
81
- /** half down */
82
- export const roundDown = baseRound(Rounding.ROUND_HALF_DOWN);
83
- export const floor = baseRound(Rounding.ROUND_FLOOR);
84
- export const ceil = baseRound(Rounding.ROUND_CEIL);
85
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
- export const roundBy = (fractionDigits: number, rounding: Rounding = Rounding.ROUND_HALF_UP): ValueAction<any, Decimal> => {
87
- return baseRound(rounding)(fractionDigits);
88
- };
@@ -1,49 +0,0 @@
1
- import {ValueAction} from './action-types';
2
-
3
- /**
4
- * always pass, and trim if given value is string
5
- */
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- export const trim: ValueAction = (value?: any) => {
8
- if (value == null) {
9
- return {test: true, value};
10
- } else if (typeof value === 'string') {
11
- return {test: true, value: value.trim()};
12
- } else {
13
- return {test: true, value};
14
- }
15
- };
16
- export type PadOptions = {
17
- length: number;
18
- char?: string;
19
- direction?: 'left' | 'right';
20
- }
21
- /**
22
- * return value must be a string if padding could perform, otherwise return given value itself no matter what it is.
23
- * could perform means performed, or not performed when length of given value is greater than or equal to given length.
24
- */
25
- export const pad = (options: PadOptions): ValueAction => {
26
- const {length, char = ' ', direction = 'right'} = options;
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- return (value?: any) => {
29
- if (value == null) {
30
- return {test: false, value};
31
- }
32
- const type = typeof value;
33
- if (['string', 'number', 'bigint', 'boolean'].includes(type)) {
34
- const stringified = `${value}`;
35
- const len = stringified.length;
36
- if (len >= length) {
37
- return {test: true, value: stringified};
38
- }
39
- return {
40
- test: true,
41
- value: direction === 'left' ? stringified.padStart(length, char) : stringified.padEnd(length, char)
42
- };
43
- } else {
44
- return {test: false, value};
45
- }
46
- };
47
- };
48
- export const padStart = (options: Omit<PadOptions, 'direction'>): ValueAction => pad({...options, direction: 'left'});
49
- export const padEnd = (options: Omit<PadOptions, 'direction'>): ValueAction => pad({...options, direction: 'right'});
@@ -1,34 +0,0 @@
1
- import {RegisteredValueAction, RegisteredValueActionWithParams} from './action-types';
2
- import {ceil, floor, roundBy, roundDown, roundUp, toDecimal, toFixed, toNumber} from './transform-decimal-actions';
3
- import {pad, padEnd, padStart, trim} from './transform-string-actions';
4
-
5
- const transformers = {
6
- // string
7
- trim: {type: 'func', func: trim} as RegisteredValueAction,
8
- pad: {type: 'param', func: pad} as RegisteredValueActionWithParams<typeof pad>,
9
- padStart: {type: 'param', func: padStart} as RegisteredValueActionWithParams<typeof padStart>,
10
- padLeft: {type: 'param', func: padStart} as RegisteredValueActionWithParams<typeof padStart>,
11
- lpad: {type: 'param', func: padStart} as RegisteredValueActionWithParams<typeof padStart>,
12
- padEnd: {type: 'param', func: padEnd} as RegisteredValueActionWithParams<typeof padEnd>,
13
- padRight: {type: 'param', func: padEnd} as RegisteredValueActionWithParams<typeof padEnd>,
14
- rpad: {type: 'param', func: padEnd} as RegisteredValueActionWithParams<typeof padEnd>,
15
- // decimal
16
- toDecimal: {type: 'func', func: toDecimal} as RegisteredValueAction,
17
- toNumber: {type: 'func', func: toNumber} as RegisteredValueAction,
18
- toFixed0: {type: 'func', func: toFixed(0)} as RegisteredValueAction,
19
- toFixed1: {type: 'func', func: toFixed(1)} as RegisteredValueAction,
20
- toFixed2: {type: 'func', func: toFixed(2)} as RegisteredValueAction,
21
- toFixed3: {type: 'func', func: toFixed(3)} as RegisteredValueAction,
22
- toFixed4: {type: 'func', func: toFixed(4)} as RegisteredValueAction,
23
- toFixed5: {type: 'func', func: toFixed(5)} as RegisteredValueAction,
24
- toFixed6: {type: 'func', func: toFixed(6)} as RegisteredValueAction,
25
- // decimal with params
26
- toFixed: {type: 'param', func: toFixed} as RegisteredValueActionWithParams<typeof toFixed>,
27
- round: {type: 'param', func: roundUp} as RegisteredValueActionWithParams<typeof roundUp>,
28
- roundUp: {type: 'param', func: roundUp} as RegisteredValueActionWithParams<typeof roundUp>,
29
- roundDown: {type: 'param', func: roundDown} as RegisteredValueActionWithParams<typeof roundDown>,
30
- floor: {type: 'param', func: floor} as RegisteredValueActionWithParams<typeof floor>,
31
- ceil: {type: 'param', func: ceil} as RegisteredValueActionWithParams<typeof ceil>,
32
- roundBy: {type: 'param', func: roundBy} as RegisteredValueActionWithParams<typeof roundBy>
33
- };
34
- export const AllTransformers: Readonly<typeof transformers> = transformers;