@ezez/utils 1.6.0 → 1.8.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/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/formatDate.d.ts +3 -0
- package/dist/formatDate.d.ts.map +1 -0
- package/dist/formatDate.js +55 -0
- package/dist/formatDate.js.map +1 -0
- package/dist/getMultiple.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/isNumericString.js.map +1 -1
- package/dist/later.d.ts +9 -0
- package/dist/later.d.ts.map +1 -0
- package/dist/later.js +13 -0
- package/dist/later.js.map +1 -0
- package/dist/mapAsync.js.map +1 -1
- package/dist/mostFrequent.d.ts.map +1 -1
- package/dist/mostFrequent.js.map +1 -1
- package/dist/pull.js.map +1 -1
- package/dist/remove.js.map +1 -1
- package/dist/replace.js.map +1 -1
- package/dist/set.js.map +1 -1
- package/dist/setImmutable.js.map +1 -1
- package/dist/throttle.js.map +1 -1
- package/docs/assets/highlight.css +7 -0
- package/docs/assets/search.js +1 -1
- package/docs/functions/cap.html +9 -6
- package/docs/functions/capitalize.html +9 -6
- package/docs/functions/coalesce.html +9 -6
- package/docs/functions/compareArrays.html +9 -6
- package/docs/functions/compareProps.html +9 -6
- package/docs/functions/ensureArray.html +9 -6
- package/docs/functions/ensureDate.html +9 -6
- package/docs/functions/ensureError.html +9 -6
- package/docs/functions/ensurePrefix.html +9 -6
- package/docs/functions/ensureSuffix.html +9 -6
- package/docs/functions/ensureTimestamp.html +9 -6
- package/docs/functions/escapeRegExp.html +9 -6
- package/docs/functions/formatDate.html +136 -0
- package/docs/functions/get.html +9 -6
- package/docs/functions/getMultiple.html +9 -6
- package/docs/functions/insertSeparator.html +9 -6
- package/docs/functions/isEmpty.html +9 -6
- package/docs/functions/isNumericString.html +9 -6
- package/docs/functions/isPlainObject.html +9 -6
- package/docs/functions/last.html +9 -6
- package/docs/functions/later-1.html +133 -0
- package/docs/functions/mapAsync.html +9 -6
- package/docs/functions/mapValues.html +9 -6
- package/docs/functions/match.html +9 -6
- package/docs/functions/merge.html +17 -14
- package/docs/functions/mostFrequent.html +9 -6
- package/docs/functions/noop.html +9 -6
- package/docs/functions/occurrences.html +9 -6
- package/docs/functions/omit.html +9 -6
- package/docs/functions/pick.html +9 -6
- package/docs/functions/pull.html +9 -6
- package/docs/functions/remove.html +9 -6
- package/docs/functions/replace.html +9 -6
- package/docs/functions/rethrow.html +9 -6
- package/docs/functions/safe.html +10 -7
- package/docs/functions/scale.html +9 -6
- package/docs/functions/seq.html +9 -6
- package/docs/functions/seqEarlyBreak.html +9 -6
- package/docs/functions/set.html +9 -6
- package/docs/functions/setImmutable.html +9 -6
- package/docs/functions/sortBy.html +9 -6
- package/docs/functions/sortProps.html +9 -6
- package/docs/functions/stripPrefix.html +9 -6
- package/docs/functions/stripSuffix.html +9 -6
- package/docs/functions/throttle.html +9 -6
- package/docs/functions/truthy.html +9 -6
- package/docs/functions/unique.html +9 -6
- package/docs/functions/wait.html +9 -6
- package/docs/functions/waitFor.html +9 -6
- package/docs/functions/waitSync.html +9 -6
- package/docs/index.html +10 -5
- package/docs/interfaces/ComparePropsOptions.html +6 -6
- package/docs/interfaces/GetMultipleSource.html +9 -6
- package/docs/interfaces/GetSource.html +9 -6
- package/docs/interfaces/IsNumericStringOptions.html +9 -9
- package/docs/interfaces/OccurencesOptions.html +6 -6
- package/docs/interfaces/SetImmutableSource.html +9 -6
- package/docs/interfaces/SetSource.html +9 -6
- package/docs/interfaces/ThrottleOptions.html +7 -7
- package/docs/interfaces/ThrottledFunctionExtras.html +7 -7
- package/docs/modules.html +11 -5
- package/docs/pages/CHANGELOG.html +70 -38
- package/docs/pages/Introduction.html +8 -5
- package/docs/types/Later.html +159 -0
- package/docs/types/MapValuesFn.html +9 -6
- package/docs/types/MatchCallback.html +9 -6
- package/docs/types/SeqEarlyBreaker.html +9 -6
- package/docs/types/SeqFn.html +9 -6
- package/docs/types/SeqFunctions.html +9 -6
- package/docs/types/SetImmutablePath.html +9 -6
- package/docs/types/ThrottledFunction.html +9 -6
- package/docs/variables/mapValuesUNSET.html +9 -6
- package/docs/variables/mergeUNSET.html +9 -6
- package/esm/formatDate.d.ts +3 -0
- package/esm/formatDate.d.ts.map +1 -0
- package/esm/formatDate.js +52 -0
- package/esm/formatDate.js.map +1 -0
- package/esm/getMultiple.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/isNumericString.js.map +1 -1
- package/esm/later.d.ts +9 -0
- package/esm/later.d.ts.map +1 -0
- package/esm/later.js +10 -0
- package/esm/later.js.map +1 -0
- package/esm/mapAsync.js.map +1 -1
- package/esm/mostFrequent.d.ts.map +1 -1
- package/esm/mostFrequent.js.map +1 -1
- package/esm/pull.js.map +1 -1
- package/esm/remove.js.map +1 -1
- package/esm/replace.js.map +1 -1
- package/esm/set.js.map +1 -1
- package/esm/setImmutable.js.map +1 -1
- package/esm/throttle.js.map +1 -1
- package/package.json +9 -8
- package/src/formatDate.spec.ts +199 -0
- package/src/formatDate.ts +73 -0
- package/src/getMultiple.ts +1 -1
- package/src/index.ts +2 -0
- package/src/isNumericString.ts +1 -1
- package/src/later.spec.ts +33 -0
- package/src/later.ts +42 -0
- package/src/mapAsync.ts +1 -1
- package/src/mostFrequent.ts +1 -0
- package/src/pull.ts +1 -1
- package/src/remove.ts +2 -2
- package/src/replace.ts +1 -1
- package/src/safe.spec.ts +0 -1
- package/src/set.ts +1 -1
- package/src/setImmutable.ts +1 -1
- package/src/throttle.ts +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { later } from "./later.js";
|
|
2
|
+
|
|
3
|
+
describe("later", () => {
|
|
4
|
+
it("creates values synchronously", async () => {
|
|
5
|
+
const l = later();
|
|
6
|
+
l.must.have.property("promise");
|
|
7
|
+
l.must.have.property("resolve");
|
|
8
|
+
l.must.have.property("reject");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("creates expected types", async () => {
|
|
12
|
+
const l = later();
|
|
13
|
+
|
|
14
|
+
l.promise.must.be.instanceof(Promise);
|
|
15
|
+
l.resolve.must.be.a.function();
|
|
16
|
+
l.reject.must.be.a.function();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("resolves promise", async () => {
|
|
20
|
+
const l = later();
|
|
21
|
+
l.resolve(42);
|
|
22
|
+
|
|
23
|
+
const r = await l.promise;
|
|
24
|
+
r.must.equal(42);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("rejects promise", async () => {
|
|
28
|
+
const l = later();
|
|
29
|
+
l.reject(new Error("foo"));
|
|
30
|
+
|
|
31
|
+
await l.promise.must.reject.with.error("foo");
|
|
32
|
+
});
|
|
33
|
+
});
|
package/src/later.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
type Later<T> = {
|
|
2
|
+
/**
|
|
3
|
+
* The promise that will be resolved or rejected later.
|
|
4
|
+
*/
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Promise resolver function
|
|
8
|
+
*/
|
|
9
|
+
resolve: (result: T) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Promise rejecter function
|
|
12
|
+
*/
|
|
13
|
+
reject: (reason: Error) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a promise that can be resolved or rejected from outside the promise.
|
|
18
|
+
*
|
|
19
|
+
* @example In this example someFunction will return a promise that's typed to return number and myDependency will
|
|
20
|
+
* resolve it when it's ready.
|
|
21
|
+
* ```
|
|
22
|
+
* function someFunction() {
|
|
23
|
+
* const l = later<number>();
|
|
24
|
+
* myDependency.load(l);
|
|
25
|
+
* return l.promise;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const later = <T>(): Later<T> => {
|
|
30
|
+
// @ts-expect-error This is expected - we fill the values later (no pun intended)
|
|
31
|
+
const res: Later<T> = {};
|
|
32
|
+
|
|
33
|
+
res.promise = new Promise((resolve, reject) => {
|
|
34
|
+
res.resolve = resolve;
|
|
35
|
+
res.reject = reject;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return res;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type { Later };
|
|
42
|
+
export { later };
|
package/src/mapAsync.ts
CHANGED
|
@@ -24,7 +24,7 @@ const mapAsync = async <T, Y>(
|
|
|
24
24
|
const l = context.length;
|
|
25
25
|
|
|
26
26
|
for (let i = 0; i < l; i++) {
|
|
27
|
-
const item = context[i]
|
|
27
|
+
const item = context[i]!;
|
|
28
28
|
// eslint-disable-next-line callback-return
|
|
29
29
|
result.push(callback(item, i, context));
|
|
30
30
|
if (Date.now() - lastWaitMoment >= pauseEvery) {
|
package/src/mostFrequent.ts
CHANGED
package/src/pull.ts
CHANGED
package/src/remove.ts
CHANGED
|
@@ -12,9 +12,9 @@ const remove = <T>(array: T[], fn: (elem: T, num: number, list: T[]) => boolean)
|
|
|
12
12
|
const removedValues = [];
|
|
13
13
|
|
|
14
14
|
for (let counter = 0; counter < len; counter++) {
|
|
15
|
-
if (fn(array[counter]
|
|
15
|
+
if (fn(array[counter]!, counter, array)) {
|
|
16
16
|
idsToRemove.push(counter - idsToRemove.length);
|
|
17
|
-
removedValues.push(array[counter]);
|
|
17
|
+
removedValues.push(array[counter]!);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
package/src/replace.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { escapeRegExp } from "./escapeRegExp.js";
|
|
|
11
11
|
const replace = (source: string, replaceMap: Record<string, string>) => {
|
|
12
12
|
/* eslint-enable max-len */
|
|
13
13
|
const regex = new RegExp(Object.keys(replaceMap).map(escapeRegExp).join("|"), "g");
|
|
14
|
-
return source.replace(regex, (matched) => replaceMap[matched]);
|
|
14
|
+
return source.replace(regex, (matched) => replaceMap[matched]!);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export {
|
package/src/safe.spec.ts
CHANGED
package/src/set.ts
CHANGED
|
@@ -39,7 +39,7 @@ const set = (source: Source, path: string | string[], value: unknown): Source |
|
|
|
39
39
|
let current: Source | unknown = result;
|
|
40
40
|
for (let i = 0; i < len; i++) {
|
|
41
41
|
const isLast = i === len - 1;
|
|
42
|
-
const key = pathParts[i]
|
|
42
|
+
const key = pathParts[i]!;
|
|
43
43
|
if (isLast) {
|
|
44
44
|
(current as Source)[key] = value;
|
|
45
45
|
return result;
|
package/src/setImmutable.ts
CHANGED
|
@@ -80,7 +80,7 @@ const setImmutable = (source: Source, path: Path, value: unknown): Source | unkn
|
|
|
80
80
|
let current: Source | unknown = result;
|
|
81
81
|
for (let i = 0; i < len; i++) {
|
|
82
82
|
const isLast = i === len - 1;
|
|
83
|
-
const key = pathParts[i]
|
|
83
|
+
const key = pathParts[i]!;
|
|
84
84
|
if (isLast) {
|
|
85
85
|
(current as Source)[key] = value;
|
|
86
86
|
return result;
|
package/src/throttle.ts
CHANGED
|
@@ -61,7 +61,7 @@ const throttle = <RT, F extends (...args: any[]) => RT>( // eslint-disable-line
|
|
|
61
61
|
throw new TypeError("`time` must be an array with at least one number.");
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const finalTime = typeof time === "number" ? time : time[time.length - 1]
|
|
64
|
+
const finalTime = typeof time === "number" ? time : time[time.length - 1]!;
|
|
65
65
|
|
|
66
66
|
let lastRun = 0,
|
|
67
67
|
timeoutId: ReturnType<typeof setTimeout> | null = null,
|