@ixfx/process 0.43.0 → 0.56.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.
package/bundle/index.d.ts DELETED
@@ -1,172 +0,0 @@
1
- //#region src/types.d.ts
2
- type Process<TIn, TOut> = (value: TIn) => TOut;
3
- type ProcessFactory<TIn, TOut> = () => Process<TIn, TOut>;
4
- type Processors1<T1, T2> = [Process<T1, T2>];
5
- type Processors2<T1, T2, T3> = [Process<T1, T2>, Process<T2, T3>];
6
- type Processors3<T1, T2, T3, T4> = [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>];
7
- type Processors4<T1, T2, T3, T4, T5> = [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>];
8
- type Processors5<T1, T2, T3, T4, T5, T6> = [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>, Process<T5, T6>];
9
- type Processors<T1, T2, T3, T4, T5, T6> = Processors1<T1, T2> | Processors2<T1, T2, T3> | Processors3<T1, T2, T3, T4> | Processors4<T1, T2, T3, T4, T5> | Processors5<T1, T2, T3, T4, T5, T6>;
10
- /**
11
- * A rank function that compares A and B.
12
- * Returns the highest value, 'a' or 'b'.
13
- * Returns 'eq' if values are equal
14
- */
15
- type RankFunction<T> = (a: T, b: T) => `a` | `b` | `eq`;
16
- type RankOptions = {
17
- /**
18
- * If set, only values with this JS type are included
19
- */
20
- includeType?: `string` | `number` | `object` | `boolean`;
21
- /**
22
- * If _true_, also emits values when they rank equal with current highest.
23
- * _false_ by default
24
- */
25
- emitEqualRanked?: boolean;
26
- /**
27
- * If _true_, emits the current highest value even if it hasn't changed.
28
- * This means it will match the tempo of the incoming stream.
29
- */
30
- emitRepeatHighest?: boolean;
31
- };
32
- //# sourceMappingURL=types.d.ts.map
33
- //#endregion
34
- //#region src/basic.d.ts
35
- /**
36
- * Outputs the current largest-seen value
37
- * @returns
38
- */
39
- declare const max: () => Process<number | number[], number>;
40
- /**
41
- * Outputs the current smallest-seen value
42
- * @returns
43
- */
44
- declare const min: () => Process<number | number[], number>;
45
- /**
46
- * Returns a sum of values
47
- * @returns
48
- */
49
- declare const sum: () => Process<number | number[], number>;
50
- /**
51
- * Returns the current average of input values
52
- * @returns
53
- */
54
- declare const average: () => Process<number | number[], number>;
55
- /**
56
- * Returns the tally (ie number of) values
57
- * @param countArrayItems
58
- * @returns
59
- */
60
- declare const tally: (countArrayItems: boolean) => Process<any, number>;
61
- /**
62
- * Returns the 'best' value seen so far as determined by a ranking function.
63
- * This is similar to min/max but usable for objects.
64
- * @param r
65
- * @param options
66
- * @returns
67
- */
68
- declare function rank<In>(r: RankFunction<In>, options?: Partial<RankOptions>): (value: In) => In | undefined;
69
- //# sourceMappingURL=basic.d.ts.map
70
- //#endregion
71
- //#region src/cancel-error.d.ts
72
- declare class CancelError extends Error {
73
- constructor(message: any);
74
- }
75
- //# sourceMappingURL=cancel-error.d.ts.map
76
- //#endregion
77
- //#region src/flow.d.ts
78
- declare function flow<T1, T2>(...processors: [Process<T1, T2>]): (value: T1) => T2;
79
- declare function flow<T1, T2, T3>(...processors: [Process<T1, T2>, Process<T2, T3>]): (value: T1) => T3;
80
- declare function flow<T1, T2, T3, T4>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>]): (value: T1) => T4;
81
- declare function flow<T1, T2, T3, T4, T5>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>]): (value: T1) => T5;
82
- declare function flow<T1, T2, T3, T4, T5, T6>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>, Process<T5, T6>]): (value: T1) => T6;
83
- //# sourceMappingURL=flow.d.ts.map
84
-
85
- //#endregion
86
- //#region src/if-undefined.d.ts
87
- /**
88
- * Calls a function if the input value is not undefined.
89
- * Return value from function is passed to next function in flow.
90
- *
91
- * ```js
92
- * const flow = Process.flow(
93
- * Process.max(),
94
- * Process.seenLastToUndefined(),
95
- * Process.ifNotUndefined(v => {
96
- * console.log(`v:`, v);
97
- * })
98
- * );
99
- * flow(100); // Prints 'v:100'
100
- * flow(90); // Nothing happens max value has not changed
101
- * flow(110); // Prints 'v:110'
102
- * ```
103
- * @param fn
104
- * @returns
105
- */
106
- declare function ifNotUndefined<TIn, TOut>(fn: (value: Exclude<TIn, undefined>) => TOut): (value: TIn) => TIn | TOut;
107
- /**
108
- * Cancels the remaining flow operations if _undefined_ is an input.
109
- * See also {@link ifUndefined} or {@link ifNotUndefined}.
110
- *
111
- * ```js
112
- * const c3 = Process.flow(
113
- * Basic.max(),
114
- * Process.seenLastToUndefined(),
115
- * Process.cancelIfUndefined(),
116
- * (v => {
117
- * console.log(v);
118
- * })
119
- * );
120
- * c3(100); // Prints '100'
121
- * c3(90); // Doesn't print anything since max does not change
122
- * c3(110); // Prints '110'
123
- * ```
124
- * @returns
125
- */
126
- declare function cancelIfUndefined<TIn>(): (value: TIn | undefined) => TIn;
127
- /**
128
- * Returns the output of `fn` if the input value is _undefined_.
129
- * See also: {@link ifNotUndefined} and {@link cancelIfUndefined}.
130
- * @param fn
131
- * @returns
132
- */
133
- declare function ifUndefined<TIn, TOut>(fn: () => TOut): (value: TIn) => TOut | (TIn & ({} | null));
134
- //# sourceMappingURL=if-undefined.d.ts.map
135
- //#endregion
136
- //#region src/seen.d.ts
137
- /**
138
- * If a value is same as the previous value, _undefined_ is emitted instead.
139
- *
140
- * @param eq Equality function. If not specified, === semantics are used.
141
- * @returns
142
- */
143
- declare function seenLastToUndefined<TIn>(eq?: (a: TIn, b: TIn) => boolean): Process<TIn, TIn | undefined>;
144
- /**
145
- * If a value is same as any previously-seen value, _undefined_ is emitted instead.
146
- *
147
- * It stores all previous values and compares against them for each new value.
148
- * This would likely be not very efficient compared to {@link seenToUndefinedByKey} which uses a one-time computed
149
- * key and efficient storage of only the keys (using a Set).
150
- *
151
- * @param eq Equality function. If not specified, === semantics are used.
152
- * @returns
153
- */
154
- declare function seenToUndefined<TIn>(eq?: (a: TIn, b: TIn) => boolean): Process<TIn, TIn | undefined>;
155
- /**
156
- * If a value is the same as any previously-seen value, _undefined_ is emitted instead.
157
- *
158
- * This version uses a function to create a string key of the object, by default JSON.stringify.
159
- * Thus we don't need to store all previously seen objects, just their keys.
160
- *
161
- * Alternatively, if a key function doesn't make sense for the value, use
162
- * {@link seenToUndefined}, which stores the values (less efficient).
163
- *
164
- * @param toString
165
- * @returns
166
- */
167
- declare function seenToUndefinedByKey<TIn>(toString?: (value: TIn) => string): Process<TIn, TIn | undefined>;
168
- //# sourceMappingURL=seen.d.ts.map
169
-
170
- //#endregion
171
- export { CancelError, type Process, ProcessFactory, Processors, Processors1, Processors2, Processors3, Processors4, Processors5, RankFunction, RankOptions, average, cancelIfUndefined, flow, ifNotUndefined, ifUndefined, max, min, rank, seenLastToUndefined, seenToUndefined, seenToUndefinedByKey, sum, tally };
172
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/basic.ts","../src/cancel-error.ts","../src/flow.ts","../src/if-undefined.ts","../src/seen.ts"],"sourcesContent":[],"mappings":";KAAY,6BAA6B,QAAQ;AAArC,KACA,cADO,CAAA,GAAA,EAAA,IAAA,CAAA,GAAA,GAAA,GAC2B,OAD3B,CACmC,GADnC,EACwC,IADxC,CAAA;AAAA,KAGP,WAHO,CAAA,EAAA,EAAA,EAAA,CAAA,GAAA,CAIjB,OAJuC,CAI/B,EAJ+B,EAI3B,EAJ2B,CAAA,CAAG;AAAS,KAOzC,WAPyC,CAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA,GAAA,CAQnD,OAPU,CAOF,EAPE,EAOE,EAPF,CAAA,EAQV,OARwB,CAQhB,EARgB,EAQZ,EARY,CAAA,CAAA;AAAiC,KAW/C,WAX+C,CAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA,GAAA,CAYzD,OAZ4C,CAYpC,EAZoC,EAYh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;;;;AAA2B;AAErD;;;;;AACS;AAGG,iBKwBI,eLxBO,CAAA,GAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,EKwBuB,GLxBvB,EAAA,CAAA,EKwB+B,GLxB/B,EAAA,GAAA,OAAA,CAAA,EKwBiD,OLxBjD,CKwByD,GLxBzD,EKwB8D,GLxB9D,GAAA,SAAA,CAAA;;;;;;;;AAEd;AAGT;;;;AACE,iBK2Cc,oBL3Cd,CAAA,GAAA,CAAA,CAAA,QAAA,CAAA,EAAA,CAAA,KAAA,EK2C2D,GL3C3D,EAAA,GAAA,MAAA,CAAA,EK2C4E,OL3C5E,CK2CoF,GL3CpF,EK2CyF,GL3CzF,GAAA,SAAA,CAAA"}
package/bundle/index.js DELETED
@@ -1,2 +0,0 @@
1
- const e=()=>{let e=-(2**53-1),t=t=>{let n=Array.isArray(t)?t:[t];for(let t of n){if(typeof t!=`number`)break;e=Math.max(t,e)}return e};return t},t=()=>{let e=2**53-1,t=t=>{let n=Array.isArray(t)?t:[t];for(let t of n){if(typeof t!=`number`)break;e=Math.min(t,e)}return e};return t},n=()=>{let e=0,t=t=>{let n=Array.isArray(t)?t:[t];for(let t of n){if(typeof t!=`number`)continue;e+=t}return e};return t},r=()=>{let e=0,t=0,n=n=>{let r=Array.isArray(n)?n:[n];for(let n of r){if(typeof n!=`number`)continue;t++,e+=n}return e/t};return n},i=e=>{let t=0,n=n=>(e&&Array.isArray(n)?t+=n.length:t++,t);return n};function a(e,t={}){let n=t.includeType,r=t.emitEqualRanked??!1,i=t.emitRepeatHighest??!1,a;return t=>{if(!(n&&typeof t!==n)){if(a===void 0)return a=t,a;{let n=e(t,a);if(n==`a`)return a=t,a;if(n===`eq`&&r||i)return a}}}}var o=class extends Error{constructor(e){super(e),this.name=`CancelError`}};function s(...e){return t=>{let n=t;for(let t of e)try{n=t(n)}catch(e){if(e instanceof o)break;throw e}return n}}function c(e){return t=>{if(t===void 0)return t;let n=e(t);return n}}function l(){return e=>{if(e===void 0)throw new o(`cancel`);return e}}function u(e){return t=>t===void 0?e():t}const d=(e,t)=>e===t,f=e=>typeof e==`string`?e:JSON.stringify(e);function p(e){e===void 0&&(e=d);let t;return e=>{if(e!==t)return t=e,e}}function m(e){let t=[];return e===void 0&&(e=d),n=>{if(n!==void 0){for(let r of t)if(e(r,n))return;return t.push(n),n}}}function h(e){let t=new Set;return e===void 0&&(e=f),n=>{if(n===void 0)return;let r=e(n);if(!t.has(r))return t.add(r),n}}export{o as CancelError,r as average,l as cancelIfUndefined,s as flow,c as ifNotUndefined,u as ifUndefined,e as max,t as min,a as rank,p as seenLastToUndefined,m as seenToUndefined,h as seenToUndefinedByKey,n as sum,i as tally};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["max","value: number | number[]","min","tally","countArrayItems: boolean","r: RankFunction<In>","options: Partial<RankOptions>","best: In | undefined","value: In","message: any","value: T1","fn: (value: Exclude<TIn, undefined>) => TOut","value: TIn","value: TIn | undefined","fn: () => TOut","a: T","b: T","itemToMakeStringFor: V","eq?: (a: TIn, b: TIn) => boolean","lastValue: TIn | undefined","value: TIn","seen: TIn[]","toString?: (value: TIn) => string"],"sources":["../src/basic.ts","../src/cancel-error.ts","../src/flow.ts","../src/if-undefined.ts","../src/util.ts","../src/seen.ts"],"sourcesContent":["import type { Process, RankFunction, RankOptions } from \"./types.js\";\nexport type { Process } from \"./types.js\";\n/**\n * Outputs the current largest-seen value\n * @returns \n */\nexport const max = (): Process<number | number[], number> => {\n let max = Number.MIN_SAFE_INTEGER;\n const compute = (value: number | number[]) => {\n const valueArray = Array.isArray(value) ? value : [ value ];\n for (const subValue of valueArray) {\n if (typeof subValue !== `number`) break;\n max = Math.max(subValue, max);\n }\n return max;\n }\n return compute;\n}\n\n/**\n * Outputs the current smallest-seen value\n * @returns\n */\nexport const min = (): Process<number | number[], number> => {\n let min = Number.MAX_SAFE_INTEGER;\n const compute = (value: number | number[]) => {\n const valueArray = Array.isArray(value) ? value : [ value ];\n for (const subValue of valueArray) {\n if (typeof subValue !== `number`) break;\n min = Math.min(subValue, min);\n }\n return min;\n }\n return compute;\n}\n\n/**\n * Returns a sum of values\n * @returns \n */\nexport const sum = (): Process<number | number[], number> => {\n let t = 0;\n const compute = (value: number | number[]) => {\n const valueArray = Array.isArray(value) ? value : [ value ];\n for (const subValue of valueArray) {\n if (typeof subValue !== `number`) continue;\n t += subValue;\n }\n return t;\n }\n return compute;\n}\n\n/**\n * Returns the current average of input values\n * @returns \n */\nexport const average = (): Process<number | number[], number> => {\n let total = 0;\n let tally = 0;\n const compute = (value: number | number[]) => {\n const valueArray = Array.isArray(value) ? value : [ value ];\n for (const subValue of valueArray) {\n if (typeof subValue !== `number`) continue;\n tally++;\n total += subValue;\n }\n return total / tally;\n }\n return compute;\n}\n\n/**\n * Returns the tally (ie number of) values\n * @param countArrayItems \n * @returns \n */\nexport const tally = (countArrayItems: boolean): Process<any, number> => {\n let t = 0;\n const compute = (value: number | number[]) => {\n if (countArrayItems) {\n if (Array.isArray(value)) t += value.length;\n else t++;\n } else {\n t++;\n }\n return t;\n }\n return compute;\n}\n\n\n\n/**\n * Returns the 'best' value seen so far as determined by a ranking function.\n * This is similar to min/max but usable for objects.\n * @param r \n * @param options \n * @returns \n */\nexport function rank<In>(r: RankFunction<In>, options: Partial<RankOptions> = {}) {\n const includeType = options.includeType;\n const emitEqualRanked = options.emitEqualRanked ?? false;\n const emitRepeatHighest = options.emitRepeatHighest ?? false;\n let best: In | undefined;\n return (value: In) => {\n if (includeType && typeof value !== includeType) return;\n if (best === undefined) {\n best = value;\n return best;\n } else {\n const result = r(value, best);\n //console.log(`result: ${ result } value: ${ JSON.stringify(value) } best: ${ JSON.stringify(best) }`);\n if (result == `a`) {\n // New value is the current best\n best = value;\n return best;\n } else if (result === `eq` && emitEqualRanked) {\n // New value is same rank as previous, but we have flag on\n return best;\n } else if (emitRepeatHighest) {\n // Emit current highest due to flag\n return best;\n }\n }\n }\n}\n\n\n","export class CancelError extends Error {\n constructor(message: any) {\n super(message);\n this.name = `CancelError`;\n }\n}","import { CancelError } from \"./cancel-error.js\";\nimport type { Process, Processors } from \"./types.js\";\nexport function flow<T1, T2>(...processors: [ Process<T1, T2> ]): (value: T1) => T2;\nexport function flow<T1, T2, T3>(...processors: [ Process<T1, T2>, Process<T2, T3> ]): (value: T1) => T3;\nexport function flow<T1, T2, T3, T4>(...processors: [ Process<T1, T2>, Process<T2, T3>, Process<T3, T4> ]): (value: T1) => T4;\nexport function flow<T1, T2, T3, T4, T5>(...processors: [ Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5> ]): (value: T1) => T5;\nexport function flow<T1, T2, T3, T4, T5, T6>(...processors: [ Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>, Process<T5, T6> ]): (value: T1) => T6;\n\n/**\n * Creates a flow of data processors (up to 5 are supported).\n * The flow is encapsulated in a function that accepts an input value an returns an output.\n * \n * ```js\n * const p = flow(\n * (value:string) => value.toUpperCase(), // Convert to uppercase\n * (value:string) => value.at(0) === 'A') // If first letter is an A, return true\n * );\n * p('apple'); // True\n * ```\n * \n * Each processing function is expected to take in one input value and return one value.\n * @param processors \n * @returns \n */\nexport function flow<T1, T2, T3, T4, T5, T6>(...processors: Processors<T1, T2, T3, T4, T5, T6>): (value: T1) => T2 | T3 | T4 | T5 | T6 {\n return (value: T1) => {\n let v = value;\n for (const p of processors) {\n try {\n // @ts-expect-error\n v = p(v) as T1;\n } catch (err) {\n if (err instanceof CancelError) {\n break;\n } else {\n throw err;\n }\n }\n }\n return v as T2 | T3 | T4 | T5 | T6;\n }\n}\n","import { CancelError } from \"./cancel-error.js\";\n\n\n/**\n * Calls a function if the input value is not undefined.\n * Return value from function is passed to next function in flow.\n * \n * ```js\n * const flow = Process.flow(\n * Process.max(),\n * Process.seenLastToUndefined(),\n * Process.ifNotUndefined(v => {\n * console.log(`v:`, v);\n * })\n * );\n * flow(100); // Prints 'v:100'\n * flow(90); // Nothing happens max value has not changed\n * flow(110); // Prints 'v:110'\n * ```\n * @param fn \n * @returns \n */\nexport function ifNotUndefined<TIn, TOut>(fn: (value: Exclude<TIn, undefined>) => TOut) {\n return (value: TIn) => {\n if (value === undefined) return value;\n const v = fn(value as Exclude<TIn, undefined>);\n return v;\n }\n}\n\n\n\n/**\n * Cancels the remaining flow operations if _undefined_ is an input.\n * See also {@link ifUndefined} or {@link ifNotUndefined}.\n * \n * ```js\n * const c3 = Process.flow(\n * Basic.max(),\n * Process.seenLastToUndefined(),\n * Process.cancelIfUndefined(),\n * (v => {\n * console.log(v);\n * })\n * );\n * c3(100); // Prints '100'\n * c3(90); // Doesn't print anything since max does not change\n * c3(110); // Prints '110'\n * ```\n * @returns \n */\nexport function cancelIfUndefined<TIn>() {\n return (value: TIn | undefined) => {\n if (value === undefined) throw new CancelError(`cancel`);\n return value as TIn;\n }\n}\n/**\n * Returns the output of `fn` if the input value is _undefined_.\n * See also: {@link ifNotUndefined} and {@link cancelIfUndefined}.\n * @param fn \n * @returns \n */\nexport function ifUndefined<TIn, TOut>(fn: () => TOut) {\n return (value: TIn) => {\n if (value === undefined) return fn();\n else return value;\n }\n}","/**\n * Default comparer function is equiv to checking `a === b`.\n * Use {@link isEqualValueDefault} to compare by value, via comparing JSON string representation.\n */\nexport const isEqualDefault = <T>(a: T, b: T): boolean => a === b;\n\n/**\n * A default converter to string that uses JSON.stringify if its an object, or the thing itself if it's a string\n */\nexport const toStringDefault = <V>(itemToMakeStringFor: V): string =>\n typeof itemToMakeStringFor === `string`\n ? itemToMakeStringFor\n : JSON.stringify(itemToMakeStringFor);","import type { Process } from \"./types.js\";\nimport { isEqualDefault, toStringDefault } from \"./util.js\";\n\n/**\n * If a value is same as the previous value, _undefined_ is emitted instead.\n * \n * @param eq Equality function. If not specified, === semantics are used.\n * @returns \n */\nexport function seenLastToUndefined<TIn>(eq?: (a: TIn, b: TIn) => boolean): Process<TIn, TIn | undefined> {\n if (typeof eq === `undefined`) eq = isEqualDefault;\n let lastValue: TIn | undefined;\n return (value: TIn) => {\n if (value !== lastValue) {\n lastValue = value;\n return value;\n }\n return undefined;\n }\n}\n\n/**\n * If a value is same as any previously-seen value, _undefined_ is emitted instead.\n * \n * It stores all previous values and compares against them for each new value. \n * This would likely be not very efficient compared to {@link seenToUndefinedByKey} which uses a one-time computed\n * key and efficient storage of only the keys (using a Set).\n * \n * @param eq Equality function. If not specified, === semantics are used.\n * @returns \n */\nexport function seenToUndefined<TIn>(eq?: (a: TIn, b: TIn) => boolean): Process<TIn, TIn | undefined> {\n const seen: TIn[] = [];\n if (typeof eq === `undefined`) eq = isEqualDefault;\n return (value: TIn) => {\n if (value === undefined) return;\n for (const s of seen) {\n if (eq(s, value)) return;\n }\n seen.push(value);\n return value;\n }\n}\n\n/**\n * If a value is the same as any previously-seen value, _undefined_ is emitted instead.\n * \n * This version uses a function to create a string key of the object, by default JSON.stringify.\n * Thus we don't need to store all previously seen objects, just their keys.\n * \n * Alternatively, if a key function doesn't make sense for the value, use\n * {@link seenToUndefined}, which stores the values (less efficient).\n * \n * @param toString \n * @returns \n */\nexport function seenToUndefinedByKey<TIn>(toString?: (value: TIn) => string): Process<TIn, TIn | undefined> {\n const seen = new Set<string>();\n if (typeof toString === `undefined`) toString = toStringDefault;\n return (value: TIn) => {\n if (value === undefined) return;\n const key = toString(value);\n if (seen.has(key)) return;\n seen.add(key);\n return value;\n }\n}"],"mappings":"AAMA,MAAa,EAAM,IAA0C,CAC3D,IAAIA,EAAM,WACJ,EAAU,AAACC,GAA6B,CAC5C,IAAM,EAAa,MAAM,QAAQ,EAAM,CAAG,EAAQ,CAAE,CAAO,EAC3D,IAAK,IAAM,KAAY,EAAY,CACjC,GAAI,OAAO,GAAa,SAAU,MAClCD,EAAM,KAAK,IAAI,EAAUA,EAAI,AAC9B,CACD,OAAOA,CACR,EACD,OAAO,CACR,EAMY,EAAM,IAA0C,CAC3D,IAAIE,UACE,EAAU,AAACD,GAA6B,CAC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ACrB,GAAI,IAAU,IAAA,GAAW,OACzB,IAAM,EAAM,EAAS,EAAM,CACvB,MAAK,IAAI,EAAI,CAEjB,OADA,EAAK,IAAI,EAAI,CACN,CACR,CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=process.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process.test.d.ts","sourceRoot":"","sources":["../../__tests__/process.test.ts"],"names":[],"mappings":""}
@@ -1,85 +0,0 @@
1
- import { test, expect } from 'vitest';
2
- import * as Basic from '../src/basic.js';
3
- import * as Process from '../src/index.js';
4
- test('seen', () => {
5
- const c1Results = [];
6
- const c1 = Process.flow(Process.seenToUndefined(), v => {
7
- c1Results.push(v);
8
- });
9
- c1('hello');
10
- c1('hello');
11
- c1('bye');
12
- expect(c1Results).toEqual([`hello`, undefined, `bye`]);
13
- const c2Results = [];
14
- const c2 = Process.flow(Process.seenToUndefinedByKey(), v => {
15
- c2Results.push(v);
16
- });
17
- c2({ name: `a` });
18
- c2({ name: `b` });
19
- c2({ name: `a` });
20
- expect(c2Results).toEqual([{ name: 'a' }, { name: 'b' }, undefined]);
21
- const c3 = Process.flow(Process.seenLastToUndefined);
22
- });
23
- test(`basic`, () => {
24
- const c1 = Process.flow(Basic.max(), Process.seenLastToUndefined());
25
- expect(c1(100)).toBe(100);
26
- expect(c1(90)).toBeFalsy();
27
- // @ts-expect-error
28
- expect(c1(null)).toBeFalsy();
29
- expect(c1(110)).toBe(110);
30
- const c2Results = [];
31
- const c2 = Process.flow(Basic.max(), Process.seenLastToUndefined(), Process.ifNotUndefined(v => {
32
- c2Results.push(v);
33
- }));
34
- c2(100);
35
- c2(90);
36
- c2(110);
37
- expect(c2Results).toEqual([100, 110]);
38
- const c3Results = [];
39
- const c3 = Process.flow(Basic.max(), Process.seenLastToUndefined(), Process.cancelIfUndefined(), (v => {
40
- c3Results.push(v);
41
- }));
42
- c3(100);
43
- c3(90);
44
- c3(110);
45
- expect(c3Results).toEqual([100, 110]);
46
- });
47
- test(`math`, () => {
48
- const c1 = Process.flow(Basic.max());
49
- expect(c1(100)).toBe(100);
50
- expect(c1(110)).toBe(110);
51
- expect(c1(90)).toBe(110);
52
- // @ts-expect-error
53
- expect(c1(undefined)).toBe(110);
54
- // @ts-expect-error
55
- expect(c1(null)).toBe(110);
56
- // @ts-expect-error
57
- expect(c1(`hello`)).toBe(110);
58
- const c2 = Process.flow(Basic.min());
59
- expect(c2(100)).toBe(100);
60
- expect(c2(110)).toBe(100);
61
- expect(c2(90)).toBe(90);
62
- // @ts-expect-error
63
- expect(c2(undefined)).toBe(90);
64
- // @ts-expect-error
65
- expect(c2(null)).toBe(90);
66
- // @ts-expect-error
67
- expect(c2(`hello`)).toBe(90);
68
- const c3 = Process.flow(Basic.sum());
69
- expect(c3(10)).toBe(10);
70
- expect(c3(20)).toBe(30);
71
- expect(c3(30)).toBe(60);
72
- // @ts-expect-error
73
- expect(c3(undefined)).toBe(60);
74
- // @ts-expect-error
75
- expect(c3(null)).toBe(60);
76
- // @ts-expect-error
77
- expect(c3(`hello`)).toBe(60);
78
- const c4 = Process.flow(Basic.tally(false));
79
- expect(c4(100)).toBe(1);
80
- expect(c4(110)).toBe(2);
81
- expect(c4(90)).toBe(3);
82
- expect(c4(undefined)).toBe(4);
83
- expect(c4(null)).toBe(5);
84
- expect(c4(`hello`)).toBe(6);
85
- });
@@ -1,37 +0,0 @@
1
- import type { Process, RankFunction, RankOptions } from "./types.js";
2
- export type { Process } from "./types.js";
3
- /**
4
- * Outputs the current largest-seen value
5
- * @returns
6
- */
7
- export declare const max: () => Process<number | number[], number>;
8
- /**
9
- * Outputs the current smallest-seen value
10
- * @returns
11
- */
12
- export declare const min: () => Process<number | number[], number>;
13
- /**
14
- * Returns a sum of values
15
- * @returns
16
- */
17
- export declare const sum: () => Process<number | number[], number>;
18
- /**
19
- * Returns the current average of input values
20
- * @returns
21
- */
22
- export declare const average: () => Process<number | number[], number>;
23
- /**
24
- * Returns the tally (ie number of) values
25
- * @param countArrayItems
26
- * @returns
27
- */
28
- export declare const tally: (countArrayItems: boolean) => Process<any, number>;
29
- /**
30
- * Returns the 'best' value seen so far as determined by a ranking function.
31
- * This is similar to min/max but usable for objects.
32
- * @param r
33
- * @param options
34
- * @returns
35
- */
36
- export declare function rank<In>(r: RankFunction<In>, options?: Partial<RankOptions>): (value: In) => In | undefined;
37
- //# sourceMappingURL=basic.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/basic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C;;;GAGG;AACH,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,CAWvD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,CAWvD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,CAWvD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,QAAO,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,CAa3D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,iBAAiB,OAAO,KAAG,OAAO,CAAC,GAAG,EAAE,MAAM,CAYnE,CAAA;AAID;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,OAAO,GAAE,OAAO,CAAC,WAAW,CAAM,IAKtE,OAAO,EAAE,oBAqBlB"}
package/dist/src/basic.js DELETED
@@ -1,129 +0,0 @@
1
- /**
2
- * Outputs the current largest-seen value
3
- * @returns
4
- */
5
- export const max = () => {
6
- let max = Number.MIN_SAFE_INTEGER;
7
- const compute = (value) => {
8
- const valueArray = Array.isArray(value) ? value : [value];
9
- for (const subValue of valueArray) {
10
- if (typeof subValue !== `number`)
11
- break;
12
- max = Math.max(subValue, max);
13
- }
14
- return max;
15
- };
16
- return compute;
17
- };
18
- /**
19
- * Outputs the current smallest-seen value
20
- * @returns
21
- */
22
- export const min = () => {
23
- let min = Number.MAX_SAFE_INTEGER;
24
- const compute = (value) => {
25
- const valueArray = Array.isArray(value) ? value : [value];
26
- for (const subValue of valueArray) {
27
- if (typeof subValue !== `number`)
28
- break;
29
- min = Math.min(subValue, min);
30
- }
31
- return min;
32
- };
33
- return compute;
34
- };
35
- /**
36
- * Returns a sum of values
37
- * @returns
38
- */
39
- export const sum = () => {
40
- let t = 0;
41
- const compute = (value) => {
42
- const valueArray = Array.isArray(value) ? value : [value];
43
- for (const subValue of valueArray) {
44
- if (typeof subValue !== `number`)
45
- continue;
46
- t += subValue;
47
- }
48
- return t;
49
- };
50
- return compute;
51
- };
52
- /**
53
- * Returns the current average of input values
54
- * @returns
55
- */
56
- export const average = () => {
57
- let total = 0;
58
- let tally = 0;
59
- const compute = (value) => {
60
- const valueArray = Array.isArray(value) ? value : [value];
61
- for (const subValue of valueArray) {
62
- if (typeof subValue !== `number`)
63
- continue;
64
- tally++;
65
- total += subValue;
66
- }
67
- return total / tally;
68
- };
69
- return compute;
70
- };
71
- /**
72
- * Returns the tally (ie number of) values
73
- * @param countArrayItems
74
- * @returns
75
- */
76
- export const tally = (countArrayItems) => {
77
- let t = 0;
78
- const compute = (value) => {
79
- if (countArrayItems) {
80
- if (Array.isArray(value))
81
- t += value.length;
82
- else
83
- t++;
84
- }
85
- else {
86
- t++;
87
- }
88
- return t;
89
- };
90
- return compute;
91
- };
92
- /**
93
- * Returns the 'best' value seen so far as determined by a ranking function.
94
- * This is similar to min/max but usable for objects.
95
- * @param r
96
- * @param options
97
- * @returns
98
- */
99
- export function rank(r, options = {}) {
100
- const includeType = options.includeType;
101
- const emitEqualRanked = options.emitEqualRanked ?? false;
102
- const emitRepeatHighest = options.emitRepeatHighest ?? false;
103
- let best;
104
- return (value) => {
105
- if (includeType && typeof value !== includeType)
106
- return;
107
- if (best === undefined) {
108
- best = value;
109
- return best;
110
- }
111
- else {
112
- const result = r(value, best);
113
- //console.log(`result: ${ result } value: ${ JSON.stringify(value) } best: ${ JSON.stringify(best) }`);
114
- if (result == `a`) {
115
- // New value is the current best
116
- best = value;
117
- return best;
118
- }
119
- else if (result === `eq` && emitEqualRanked) {
120
- // New value is same rank as previous, but we have flag on
121
- return best;
122
- }
123
- else if (emitRepeatHighest) {
124
- // Emit current highest due to flag
125
- return best;
126
- }
127
- }
128
- };
129
- }
@@ -1,4 +0,0 @@
1
- export declare class CancelError extends Error {
2
- constructor(message: any);
3
- }
4
- //# sourceMappingURL=cancel-error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancel-error.d.ts","sourceRoot":"","sources":["../../src/cancel-error.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,GAAG;CAIzB"}
@@ -1,6 +0,0 @@
1
- export class CancelError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = `CancelError`;
5
- }
6
- }
@@ -1,7 +0,0 @@
1
- import type { Process } from "./types.js";
2
- export declare function flow<T1, T2>(...processors: [Process<T1, T2>]): (value: T1) => T2;
3
- export declare function flow<T1, T2, T3>(...processors: [Process<T1, T2>, Process<T2, T3>]): (value: T1) => T3;
4
- export declare function flow<T1, T2, T3, T4>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>]): (value: T1) => T4;
5
- export declare function flow<T1, T2, T3, T4, T5>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4>, Process<T4, T5>]): (value: T1) => T5;
6
- export declare function flow<T1, T2, T3, T4, T5, T6>(...processors: [Process<T1, T2>, Process<T2, T3>, Process<T3, T4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EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAE,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC"}
package/dist/src/flow.js DELETED
@@ -1,37 +0,0 @@
1
- import { CancelError } from "./cancel-error.js";
2
- /**
3
- * Creates a flow of data processors (up to 5 are supported).
4
- * The flow is encapsulated in a function that accepts an input value an returns an output.
5
- *
6
- * ```js
7
- * const p = flow(
8
- * (value:string) => value.toUpperCase(), // Convert to uppercase
9
- * (value:string) => value.at(0) === 'A') // If first letter is an A, return true
10
- * );
11
- * p('apple'); // True
12
- * ```
13
- *
14
- * Each processing function is expected to take in one input value and return one value.
15
- * @param processors
16
- * @returns
17
- */
18
- export function flow(...processors) {
19
- return (value) => {
20
- let v = value;
21
- for (const p of processors) {
22
- try {
23
- // @ts-expect-error
24
- v = p(v);
25
- }
26
- catch (err) {
27
- if (err instanceof CancelError) {
28
- break;
29
- }
30
- else {
31
- throw err;
32
- }
33
- }
34
- }
35
- return v;
36
- };
37
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Calls a function if the input value is not undefined.
3
- * Return value from function is passed to next function in flow.
4
- *
5
- * ```js
6
- * const flow = Process.flow(
7
- * Process.max(),
8
- * Process.seenLastToUndefined(),
9
- * Process.ifNotUndefined(v => {
10
- * console.log(`v:`, v);
11
- * })
12
- * );
13
- * flow(100); // Prints 'v:100'
14
- * flow(90); // Nothing happens max value has not changed
15
- * flow(110); // Prints 'v:110'
16
- * ```
17
- * @param fn
18
- * @returns
19
- */
20
- export declare function ifNotUndefined<TIn, TOut>(fn: (value: Exclude<TIn, undefined>) => TOut): (value: TIn) => TIn | TOut;
21
- /**
22
- * Cancels the remaining flow operations if _undefined_ is an input.
23
- * See also {@link ifUndefined} or {@link ifNotUndefined}.
24
- *
25
- * ```js
26
- * const c3 = Process.flow(
27
- * Basic.max(),
28
- * Process.seenLastToUndefined(),
29
- * Process.cancelIfUndefined(),
30
- * (v => {
31
- * console.log(v);
32
- * })
33
- * );
34
- * c3(100); // Prints '100'
35
- * c3(90); // Doesn't print anything since max does not change
36
- * c3(110); // Prints '110'
37
- * ```
38
- * @returns
39
- */
40
- export declare function cancelIfUndefined<TIn>(): (value: TIn | undefined) => TIn;
41
- /**
42
- * Returns the output of `fn` if the input value is _undefined_.
43
- * See also: {@link ifNotUndefined} and {@link cancelIfUndefined}.
44
- * @param fn
45
- * @returns
46
- */
47
- export declare function ifUndefined<TIn, TOut>(fn: () => TOut): (value: TIn) => TOut | (TIn & ({} | null));
48
- //# sourceMappingURL=if-undefined.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"if-undefined.d.ts","sourceRoot":"","sources":["../../src/if-undefined.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,IAAI,IAC5E,OAAO,GAAG,gBAKnB;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,MAC3B,OAAO,GAAG,GAAG,SAAS,KAEZ,GAAG,CAEtB;AACD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,IAAI,IAC3C,OAAO,GAAG,gCAInB"}