@rainbow-o23/n1 1.0.48 → 1.0.50
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.
- package/README.md +44 -6
- package/index.cjs +641 -78
- package/index.d.ts +1 -0
- package/index.js +598 -54
- package/lib/pipeline/index.d.ts +2 -1
- package/lib/pipeline/step-helpers-utils.d.ts +28 -3
- package/lib/pipeline/step-helpers-value-operator.d.ts +34 -0
- package/lib/pipeline/step-helpers.d.ts +9 -23
- package/lib/pipeline/types.d.ts +1 -0
- package/lib/pipeline/value-operators/action-types.d.ts +18 -0
- package/lib/pipeline/value-operators/index.d.ts +8 -0
- package/lib/pipeline/value-operators/test-any-actions.d.ts +10 -0
- package/lib/pipeline/value-operators/test-decimal-actions.d.ts +25 -0
- package/lib/pipeline/value-operators/test-string-actions.d.ts +2 -0
- package/lib/pipeline/value-operators/testers.d.ts +36 -0
- package/lib/pipeline/value-operators/transform-decimal-actions.d.ts +21 -0
- package/lib/pipeline/value-operators/transform-string-actions.d.ts +10 -0
- package/lib/pipeline/value-operators/transformers.d.ts +31 -0
- package/package.json +25 -3
- package/rollup.config.base.js +1 -2
- package/src/index.ts +3 -0
- package/src/lib/pipeline/index.ts +2 -1
- package/src/lib/pipeline/step-helpers-utils.ts +105 -29
- package/src/lib/pipeline/step-helpers-value-operator.ts +307 -0
- package/src/lib/pipeline/step-helpers.ts +24 -50
- package/src/lib/pipeline/types.ts +7 -0
- package/src/lib/pipeline/value-operators/action-types.ts +8 -0
- package/src/lib/pipeline/value-operators/index.ts +10 -0
- package/src/lib/pipeline/value-operators/test-any-actions.ts +58 -0
- package/src/lib/pipeline/value-operators/test-decimal-actions.ts +85 -0
- package/src/lib/pipeline/value-operators/test-string-actions.ts +15 -0
- package/src/lib/pipeline/value-operators/testers.ts +59 -0
- package/src/lib/pipeline/value-operators/transform-decimal-actions.ts +88 -0
- package/src/lib/pipeline/value-operators/transform-string-actions.ts +49 -0
- package/src/lib/pipeline/value-operators/transformers.ts +34 -0
- package/test/value-test.test.ts +55 -0
- /package/lib/{pipeline/envs.d.ts → envs.d.ts} +0 -0
- /package/src/lib/{pipeline/envs.ts → envs.ts} +0 -0
package/README.md
CHANGED
|
@@ -125,7 +125,8 @@ Pipeline steps provide rich function support, and all the following functions or
|
|
|
125
125
|
| $logger | Get logger instance. |
|
|
126
126
|
| $date.now() | Get current datetime, as string. |
|
|
127
127
|
| $date.dayjs | Get [Day.js](https://day.js.org/). |
|
|
128
|
-
| $math | Get [Math.js](https://mathjs.org)
|
|
128
|
+
| $math | Get [Math.js](https://mathjs.org). |
|
|
129
|
+
| $decimal(value: string \| number \| Decimal.value) | Create a decimal value by [Decimal.js](https://mikemcl.github.io/decimal.js/). |
|
|
129
130
|
| $nano(size?: number) | Create a nano string. |
|
|
130
131
|
| $ascii(size?: number) | Create a nano string, only contains ascii characters (0-9, a-z, A-Z, _). |
|
|
131
132
|
| $error(options: PipelineStepErrorOptions) | Throw an exposed uncatchable error. |
|
|
@@ -138,11 +139,14 @@ Pipeline steps provide rich function support, and all the following functions or
|
|
|
138
139
|
| $errors.isUncatchable(e: any) | Check if given is an uncatchable error. |
|
|
139
140
|
| $file(options: PipelineStepFileOptions) => PipelineStepFile | Create a file instance by given options. |
|
|
140
141
|
| $clearContextData() | If the pipeline step does not return anything or returns null or undefined, the context will continue to be used without any modifications.<br>So returning this semaphore indicates clearing the step content data. |
|
|
141
|
-
| isEmpty: (value: any) |
|
|
142
|
-
| isNotEmpty: (value: any) |
|
|
143
|
-
| isBlank: (value: any) |
|
|
144
|
-
| isNotBlank: (value: any) |
|
|
145
|
-
| trim: (value: any) |
|
|
142
|
+
| isEmpty: (value: any) | **@deprecated**, Use `touch` chain instead. |
|
|
143
|
+
| isNotEmpty: (value: any) | **@deprecated**, Use `touch` chain instead. |
|
|
144
|
+
| isBlank: (value: any) | **@deprecated**, Use `touch` chain instead. |
|
|
145
|
+
| isNotBlank: (value: any) | **@deprecated**, Use `touch` chain instead. |
|
|
146
|
+
| trim: (value: any) | **@deprecated**, Use `touch` chain instead. |
|
|
147
|
+
| touch: (value: any): IValueOperator | Operate given value, do test, transform. |
|
|
148
|
+
| noop: () => void | Noop function. |
|
|
149
|
+
| asyncNoop: () => Promise<void> | Async noop function. |
|
|
146
150
|
|
|
147
151
|
For example:
|
|
148
152
|
|
|
@@ -248,3 +252,37 @@ includes an additional field called `status`, which represents the HTTP response
|
|
|
248
252
|
| `format.datetime` | string | YYYY-MM-DD HH:mm:ss | Default datetime format, follows [Day.js](https://day.js.org/) |
|
|
249
253
|
| `pipeline.debug.log.enabled` | boolean | false | Enable the pipeline debug log. |
|
|
250
254
|
| `pipeline.performance.log.enabled` | boolean | false | Enable the pipeline performance log, spent time of pipeline and pipeline step.<br>Translation: If `pipeline.debug.log.enabled` is true, this log output will also be enabled. |
|
|
255
|
+
|
|
256
|
+
## Value Operator
|
|
257
|
+
|
|
258
|
+
`o23/n1` provides a value operator to operate given value, do test, transform. The value operator is a chainable operation. For example,
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
// chainable operation, do test, transform, or default value
|
|
262
|
+
$.touch('abc').isNotBlank().orUseDefault('default').value(); // 'abc'
|
|
263
|
+
$.touch('').isNotBlank.withDefault('default').value(); // 'default'
|
|
264
|
+
$.touch('123').isNumber().toFixed(2).value(); // '123.00'
|
|
265
|
+
$.touch(void 0).isNumber.useDefault(100).value(); // 100
|
|
266
|
+
$.touch(123).isInt.toFixed2.value(); // '123.00'
|
|
267
|
+
$.touch('123.45').within({min: 100, max: 200}).toFixed3().orElse(150).value(); // '123.450'
|
|
268
|
+
|
|
269
|
+
// success and failure callback
|
|
270
|
+
$.touch(123).isPositive // isPositive 123
|
|
271
|
+
.success((value: number) => console.log('isPositive', value))
|
|
272
|
+
.failure((value: number) => console.log('isNotPositive', value));
|
|
273
|
+
$.touch(-123).isPositive // isNotPositive -123
|
|
274
|
+
.success((value: number) => console.log('isPositive', value))
|
|
275
|
+
.failure((value: number) => console.log('isNotPositive', value));
|
|
276
|
+
|
|
277
|
+
// check
|
|
278
|
+
$.touch(123).isPositive.ok(); // true
|
|
279
|
+
$.touch(-123).isPositive.ok(); // false
|
|
280
|
+
|
|
281
|
+
// promisify
|
|
282
|
+
try {
|
|
283
|
+
const v = await $.touch(123).isPositive.toNumber.promise(); // resolved 123
|
|
284
|
+
await VO.of(-123).isPositive.promise(); // rejected, -123 can be caught in catch block
|
|
285
|
+
} catch (v) {
|
|
286
|
+
console.log(v); // -123
|
|
287
|
+
}
|
|
288
|
+
```
|