@elyukai/utils 0.1.2 → 0.1.4
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 +11 -0
- package/README.md +16 -0
- package/dist/array/filters.d.ts +4 -0
- package/dist/array/filters.js +4 -0
- package/dist/array/generators.d.ts +4 -0
- package/dist/array/generators.js +4 -0
- package/dist/array/groups.d.ts +4 -0
- package/dist/array/groups.js +4 -0
- package/dist/array/modify.d.ts +4 -0
- package/dist/array/modify.js +4 -0
- package/dist/array/nonEmpty.d.ts +1 -0
- package/dist/array/nonEmpty.js +1 -0
- package/dist/array/reductions.d.ts +4 -0
- package/dist/array/reductions.js +4 -0
- package/dist/array/sets.d.ts +4 -0
- package/dist/array/sets.js +4 -0
- package/dist/async.d.ts +12 -0
- package/dist/async.js +39 -0
- package/dist/classList.d.ts +4 -0
- package/dist/classList.js +4 -0
- package/dist/dictionary/native.d.ts +1 -0
- package/dist/dictionary/native.js +1 -0
- package/dist/dictionary.d.ts +2 -2
- package/dist/dictionary.js +2 -2
- package/dist/equality.d.ts +4 -0
- package/dist/equality.js +4 -0
- package/dist/function.d.ts +4 -0
- package/dist/function.js +4 -0
- package/dist/lazy.d.ts +4 -0
- package/dist/lazy.js +4 -0
- package/dist/maybe.d.ts +8 -0
- package/dist/maybe.js +8 -0
- package/dist/nullable.d.ts +4 -0
- package/dist/nullable.js +4 -0
- package/dist/number.d.ts +4 -0
- package/dist/number.js +4 -0
- package/dist/object.d.ts +4 -0
- package/dist/object.js +4 -0
- package/dist/ordering.d.ts +4 -0
- package/dist/ordering.js +4 -0
- package/dist/range.d.ts +4 -0
- package/dist/range.js +4 -0
- package/dist/result.d.ts +16 -2
- package/dist/result.js +10 -2
- package/dist/roman.d.ts +4 -0
- package/dist/roman.js +4 -0
- package/dist/string/number.d.ts +4 -0
- package/dist/string/number.js +4 -0
- package/dist/string/regex.d.ts +4 -0
- package/dist/string/regex.js +4 -0
- package/dist/string.d.ts +4 -0
- package/dist/string.js +4 -0
- package/dist/typeSafety.d.ts +4 -0
- package/dist/typeSafety.js +4 -0
- package/package.json +2 -1
- package/dist/array.d.ts +0 -4
- package/dist/array.js +0 -5
- package/dist/compare.d.ts +0 -44
- package/dist/compare.js +0 -73
- package/dist/date.d.ts +0 -5
- package/dist/date.js +0 -5
- package/dist/math.d.ts +0 -47
- package/dist/math.js +0 -56
- package/dist/regex.d.ts +0 -28
- package/dist/regex.js +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.1.4](https://github.com/elyukai/ts-utils/compare/v0.1.3...v0.1.4) (2026-01-24)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add `then` function to Maybe and Result ([d6fea69](https://github.com/elyukai/ts-utils/commit/d6fea6979ce0bf687b0e377207483ca151e789d2))
|
|
11
|
+
* add mapAsync function ([55077cd](https://github.com/elyukai/ts-utils/commit/55077cd097faf43d56827399d45011ef079a5206))
|
|
12
|
+
* **result:** constructor with no argument ([f65e830](https://github.com/elyukai/ts-utils/commit/f65e8308158b37d7afca3a5f1059bb93f0db072c))
|
|
13
|
+
|
|
14
|
+
## [0.1.3](https://github.com/elyukai/ts-utils/compare/v0.1.2...v0.1.3) (2026-01-24)
|
|
15
|
+
|
|
5
16
|
## [0.1.2](https://github.com/elyukai/ts-utils/compare/v0.1.1...v0.1.2) (2026-01-24)
|
|
6
17
|
|
|
7
18
|
|
package/README.md
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
# General TypeScript Helpers
|
|
2
|
+
|
|
3
|
+
  [](https://jsr.io/@elyukai/utils) [](https://jsr.io/@elyukai/utils)
|
|
4
|
+
|
|
5
|
+
This package provides a range of utility functions that I personally often need, which is why I bundled them in a package.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { isNotEmpty } from "@elyukai/utils/array/nonEmpty"
|
|
9
|
+
|
|
10
|
+
const extractFirstNumberDoubled = (arr: number[]): number | undefined => {
|
|
11
|
+
if (isNotEmpty(arr)) {
|
|
12
|
+
return arr[0] * 2 // accessing index 0 is safe!
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
```
|
package/dist/array/filters.d.ts
CHANGED
package/dist/array/filters.js
CHANGED
package/dist/array/generators.js
CHANGED
package/dist/array/groups.d.ts
CHANGED
package/dist/array/groups.js
CHANGED
package/dist/array/modify.d.ts
CHANGED
package/dist/array/modify.js
CHANGED
package/dist/array/nonEmpty.d.ts
CHANGED
package/dist/array/nonEmpty.js
CHANGED
package/dist/array/reductions.js
CHANGED
package/dist/array/sets.d.ts
CHANGED
package/dist/array/sets.js
CHANGED
package/dist/async.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for asynchronous operations.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Returns a promise that resolves after a specified delay in milliseconds.
|
|
3
7
|
* @param delay The delay in milliseconds.
|
|
@@ -9,3 +13,11 @@
|
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
11
15
|
export declare const wait: (delay: number) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* A simple async map to process tasks with a concurrency limit.
|
|
18
|
+
* @param tasks The list of tasks to process.
|
|
19
|
+
* @param worker The async function to process each task.
|
|
20
|
+
* @param concurrency The maximum number of concurrent tasks.
|
|
21
|
+
* @returns A promise that resolves to the list of results.
|
|
22
|
+
*/
|
|
23
|
+
export declare const mapAsync: <T, R>(tasks: readonly T[], worker: (task: T) => Promise<R>, concurrency: number) => Promise<R[]>;
|
package/dist/async.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for asynchronous operations.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Returns a promise that resolves after a specified delay in milliseconds.
|
|
3
7
|
* @param delay The delay in milliseconds.
|
|
@@ -9,3 +13,38 @@
|
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
11
15
|
export const wait = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
|
|
16
|
+
/**
|
|
17
|
+
* A simple async map to process tasks with a concurrency limit.
|
|
18
|
+
* @param tasks The list of tasks to process.
|
|
19
|
+
* @param worker The async function to process each task.
|
|
20
|
+
* @param concurrency The maximum number of concurrent tasks.
|
|
21
|
+
* @returns A promise that resolves to the list of results.
|
|
22
|
+
*/
|
|
23
|
+
export const mapAsync = (tasks, worker, concurrency) => new Promise((resolve, reject) => {
|
|
24
|
+
const results = [];
|
|
25
|
+
let activeIndex = 0;
|
|
26
|
+
let activeCount = 0;
|
|
27
|
+
let resolvedCount = 0;
|
|
28
|
+
const totalCount = tasks.length;
|
|
29
|
+
const runNext = () => {
|
|
30
|
+
if (resolvedCount === totalCount) {
|
|
31
|
+
resolve(results);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
while (activeCount < concurrency && activeIndex < totalCount) {
|
|
35
|
+
const currentIndex = activeIndex++;
|
|
36
|
+
const task = tasks[currentIndex];
|
|
37
|
+
activeCount++;
|
|
38
|
+
worker(task)
|
|
39
|
+
.then((result) => {
|
|
40
|
+
results[currentIndex] = result;
|
|
41
|
+
resolvedCount++;
|
|
42
|
+
activeCount--;
|
|
43
|
+
runNext();
|
|
44
|
+
})
|
|
45
|
+
.catch(reject);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
runNext();
|
|
50
|
+
});
|
package/dist/classList.d.ts
CHANGED
package/dist/classList.js
CHANGED
package/dist/dictionary.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Introduces a Dictionary class that represents an immutable mapping from
|
|
3
|
-
*
|
|
2
|
+
* Introduces a Dictionary class that represents an immutable mapping from strings to values.
|
|
3
|
+
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { AnyNonNullish } from "./nullable.js";
|
|
6
6
|
/**
|
package/dist/dictionary.js
CHANGED
package/dist/equality.d.ts
CHANGED
package/dist/equality.js
CHANGED
package/dist/function.d.ts
CHANGED
package/dist/function.js
CHANGED
package/dist/lazy.d.ts
CHANGED
package/dist/lazy.js
CHANGED
package/dist/maybe.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nullable values as a structure.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* A maybe can contain a value or nothing.
|
|
3
7
|
*/
|
|
@@ -43,6 +47,10 @@ export declare const reduce: <T, R>(maybe: Maybe<T>, def: R, f: (value: T) => R)
|
|
|
43
47
|
* Maps the value of a maybe to a new value.
|
|
44
48
|
*/
|
|
45
49
|
export declare const map: <T, U>(maybe: Maybe<T>, f: (value: T) => U) => Maybe<U>;
|
|
50
|
+
/**
|
|
51
|
+
* Chains a result to a new result.
|
|
52
|
+
*/
|
|
53
|
+
export declare const then: <T, U>(maybe: Maybe<T>, f: (value: T) => Maybe<U>) => Maybe<U>;
|
|
46
54
|
/**
|
|
47
55
|
* Combines two maybes into one maybe. If both maybes contain a value, the
|
|
48
56
|
* values are combined using the provided function. If at least one maybe
|
package/dist/maybe.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nullable values as a structure.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Creates a maybe that contains a value.
|
|
3
7
|
*/
|
|
@@ -26,6 +30,10 @@ export const reduce = (maybe, def, f) => isJust(maybe) ? f(maybe.value) : def;
|
|
|
26
30
|
* Maps the value of a maybe to a new value.
|
|
27
31
|
*/
|
|
28
32
|
export const map = (maybe, f) => isJust(maybe) ? Just(f(maybe.value)) : Nothing;
|
|
33
|
+
/**
|
|
34
|
+
* Chains a result to a new result.
|
|
35
|
+
*/
|
|
36
|
+
export const then = (maybe, f) => (isJust(maybe) ? f(maybe.value) : maybe);
|
|
29
37
|
/**
|
|
30
38
|
* Combines two maybes into one maybe. If both maybes contain a value, the
|
|
31
39
|
* values are combined using the provided function. If at least one maybe
|
package/dist/nullable.d.ts
CHANGED
package/dist/nullable.js
CHANGED
package/dist/number.d.ts
CHANGED
package/dist/number.js
CHANGED
package/dist/object.d.ts
CHANGED
package/dist/object.js
CHANGED
package/dist/ordering.d.ts
CHANGED
package/dist/ordering.js
CHANGED
package/dist/range.d.ts
CHANGED
package/dist/range.js
CHANGED
package/dist/result.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implementation of a `Result` type that can structurally represent success or failure.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* A result is either a value or an error.
|
|
3
7
|
*/
|
|
@@ -19,7 +23,10 @@ export interface Error<E> {
|
|
|
19
23
|
/**
|
|
20
24
|
* Creates a result that contains a value.
|
|
21
25
|
*/
|
|
22
|
-
export declare const ok:
|
|
26
|
+
export declare const ok: {
|
|
27
|
+
(): Result<void, never>;
|
|
28
|
+
<T>(value: T): Result<T, never>;
|
|
29
|
+
};
|
|
23
30
|
/**
|
|
24
31
|
* Checks if a result contains a value.
|
|
25
32
|
*/
|
|
@@ -27,7 +34,10 @@ export declare const isOk: <T, E>(result: Result<T, E>) => result is Ok<T>;
|
|
|
27
34
|
/**
|
|
28
35
|
* Creates a result that contains an error.
|
|
29
36
|
*/
|
|
30
|
-
export declare const error:
|
|
37
|
+
export declare const error: {
|
|
38
|
+
(): Result<never, void>;
|
|
39
|
+
<E>(error: E): Result<never, E>;
|
|
40
|
+
};
|
|
31
41
|
/**
|
|
32
42
|
* Checks if a result contains an error.
|
|
33
43
|
*/
|
|
@@ -44,6 +54,10 @@ export declare const map: <T, U, E>(result: Result<T, E>, f: (value: T) => U) =>
|
|
|
44
54
|
* Maps an error to a new error.
|
|
45
55
|
*/
|
|
46
56
|
export declare const mapError: <T, E, F>(result: Result<T, E>, f: (value: E) => F) => Result<T, F>;
|
|
57
|
+
/**
|
|
58
|
+
* Chains a result to a new result.
|
|
59
|
+
*/
|
|
60
|
+
export declare const then: <T, U, E>(result: Result<T, E>, f: (value: T) => Result<U, E>) => Result<U, E>;
|
|
47
61
|
/**
|
|
48
62
|
* Combines two results into one.
|
|
49
63
|
*
|
package/dist/result.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implementation of a `Result` type that can structurally represent success or failure.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Creates a result that contains a value.
|
|
3
7
|
*/
|
|
4
|
-
export const ok = (value) => ({ tag: "Ok", value });
|
|
8
|
+
export const ok = (value) => ({ tag: "Ok", value: value });
|
|
5
9
|
/**
|
|
6
10
|
* Checks if a result contains a value.
|
|
7
11
|
*/
|
|
@@ -11,7 +15,7 @@ export const isOk = (result) => result.tag === "Ok";
|
|
|
11
15
|
*/
|
|
12
16
|
export const error = (error) => ({
|
|
13
17
|
tag: "Error",
|
|
14
|
-
error,
|
|
18
|
+
error: error,
|
|
15
19
|
});
|
|
16
20
|
/**
|
|
17
21
|
* Checks if a result contains an error.
|
|
@@ -29,6 +33,10 @@ export const map = (result, f) => (isOk(result) ? ok(f(result.value)) : result);
|
|
|
29
33
|
* Maps an error to a new error.
|
|
30
34
|
*/
|
|
31
35
|
export const mapError = (result, f) => (isError(result) ? error(f(result.error)) : result);
|
|
36
|
+
/**
|
|
37
|
+
* Chains a result to a new result.
|
|
38
|
+
*/
|
|
39
|
+
export const then = (result, f) => (isOk(result) ? f(result.value) : result);
|
|
32
40
|
/**
|
|
33
41
|
* Combines two results into one.
|
|
34
42
|
*
|
package/dist/roman.d.ts
CHANGED
package/dist/roman.js
CHANGED
package/dist/string/number.d.ts
CHANGED
package/dist/string/number.js
CHANGED
package/dist/string/regex.d.ts
CHANGED
package/dist/string/regex.js
CHANGED
package/dist/string.d.ts
CHANGED
package/dist/string.js
CHANGED
package/dist/typeSafety.d.ts
CHANGED
package/dist/typeSafety.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyukai/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A set of JavaScript helper functions.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/node": "^25.0.10",
|
|
37
37
|
"commit-and-tag-version": "^12.6.1",
|
|
38
38
|
"eslint": "^9.39.2",
|
|
39
|
+
"eslint-plugin-jsdoc": "^62.4.1",
|
|
39
40
|
"glob": "^13.0.0",
|
|
40
41
|
"prettier": "^3.8.1",
|
|
41
42
|
"tsx": "^4.21.0",
|
package/dist/array.d.ts
DELETED
package/dist/array.js
DELETED
package/dist/compare.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The type of a compare function that can be used to sort values.
|
|
3
|
-
* @returns A negative number if `a` should be sorted before `b`, a positive
|
|
4
|
-
* number if `a` should be sorted after `b`, or zero if `a` and `b` are equal.
|
|
5
|
-
*/
|
|
6
|
-
export type Compare<T> = (a: T, b: T) => number;
|
|
7
|
-
/**
|
|
8
|
-
* Build a compare function for values that are nested inside other values. The
|
|
9
|
-
* nested value is getting extracted by the provided accessor function and then
|
|
10
|
-
* compared using the provided compare function. An optional `reverse` parameter
|
|
11
|
-
* can be used to reverse the sort order.
|
|
12
|
-
*/
|
|
13
|
-
export declare const compareAt: <T, U>(accessor: (value: T) => U, compare: (a: U, b: U) => number, reverse?: boolean) => Compare<T>;
|
|
14
|
-
/**
|
|
15
|
-
* Build a compare function that nests multiple compare functions. The functions
|
|
16
|
-
* are applied in order, so the first function is the primary sort key, the
|
|
17
|
-
* second function is the secondary sort key, and so on.
|
|
18
|
-
*/
|
|
19
|
-
export declare const reduceCompare: <T>(...compares: Compare<T>[]) => Compare<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Compare function for numbers that sorts them in ascending order.
|
|
22
|
-
*/
|
|
23
|
-
export declare const numAsc: Compare<number>;
|
|
24
|
-
/**
|
|
25
|
-
* Higher-order compare function that extends a compare function to also handle
|
|
26
|
-
* `null` and `undefined` values. Nullish values are always sorted first.
|
|
27
|
-
*/
|
|
28
|
-
export declare const compareNullish: <T extends NonNullable<unknown>>(compare: Compare<T>) => (a: T | null | undefined, b: T | null | undefined) => number;
|
|
29
|
-
/**
|
|
30
|
-
* A function that compares two values for equality.
|
|
31
|
-
*/
|
|
32
|
-
export type Equality<T> = (a: T, b: T) => boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Build an equality function for values that are nested inside other values.
|
|
35
|
-
* The nested value is getting extracted by the provided accessor function and
|
|
36
|
-
* then compared using the provided equality function.
|
|
37
|
-
*/
|
|
38
|
-
export declare const equalityAt: <T, U>(accessor: (value: T) => U, equality: Equality<U>) => Equality<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Checks two values for value equality. This is a deep equality check that
|
|
41
|
-
* works for all types, including objects and arrays. For objects, it only
|
|
42
|
-
* compares all enumerable keys, no other properties or the prototype chain.
|
|
43
|
-
*/
|
|
44
|
-
export declare const deepEqual: <T>(a: T, b: T) => boolean;
|
package/dist/compare.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { isNullish } from "./nullable.js";
|
|
2
|
-
/**
|
|
3
|
-
* Build a compare function for values that are nested inside other values. The
|
|
4
|
-
* nested value is getting extracted by the provided accessor function and then
|
|
5
|
-
* compared using the provided compare function. An optional `reverse` parameter
|
|
6
|
-
* can be used to reverse the sort order.
|
|
7
|
-
*/
|
|
8
|
-
export const compareAt = (accessor, compare, reverse = false) => (a, b) => {
|
|
9
|
-
const result = compare(accessor(a), accessor(b));
|
|
10
|
-
return reverse ? -result : result;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Build a compare function that nests multiple compare functions. The functions
|
|
14
|
-
* are applied in order, so the first function is the primary sort key, the
|
|
15
|
-
* second function is the secondary sort key, and so on.
|
|
16
|
-
*/
|
|
17
|
-
export const reduceCompare = (...compares) => (a, b) => {
|
|
18
|
-
for (const compare of compares) {
|
|
19
|
-
const result = compare(a, b);
|
|
20
|
-
if (result !== 0) {
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return 0;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Compare function for numbers that sorts them in ascending order.
|
|
28
|
-
*/
|
|
29
|
-
export const numAsc = (a, b) => a - b;
|
|
30
|
-
/**
|
|
31
|
-
* Higher-order compare function that extends a compare function to also handle
|
|
32
|
-
* `null` and `undefined` values. Nullish values are always sorted first.
|
|
33
|
-
*/
|
|
34
|
-
export const compareNullish = (compare) => (a, b) => {
|
|
35
|
-
if (isNullish(a) && isNullish(b)) {
|
|
36
|
-
return 0;
|
|
37
|
-
}
|
|
38
|
-
if (isNullish(a)) {
|
|
39
|
-
return -1;
|
|
40
|
-
}
|
|
41
|
-
if (isNullish(b)) {
|
|
42
|
-
return 1;
|
|
43
|
-
}
|
|
44
|
-
return compare(a, b);
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Build an equality function for values that are nested inside other values.
|
|
48
|
-
* The nested value is getting extracted by the provided accessor function and
|
|
49
|
-
* then compared using the provided equality function.
|
|
50
|
-
*/
|
|
51
|
-
export const equalityAt = (accessor, equality) => (a, b) => equality(accessor(a), accessor(b));
|
|
52
|
-
/**
|
|
53
|
-
* Checks two values for value equality. This is a deep equality check that
|
|
54
|
-
* works for all types, including objects and arrays. For objects, it only
|
|
55
|
-
* compares all enumerable keys, no other properties or the prototype chain.
|
|
56
|
-
*/
|
|
57
|
-
export const deepEqual = (a, b) => {
|
|
58
|
-
if (a === b) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (typeof a === "object" &&
|
|
62
|
-
typeof b === "object" &&
|
|
63
|
-
a !== null &&
|
|
64
|
-
b !== null) {
|
|
65
|
-
const keys = Object.keys(a);
|
|
66
|
-
if (keys.length !== Object.keys(b).length) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return keys.every((key) => key in b &&
|
|
70
|
-
deepEqual(a[key], b[key]));
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
};
|
package/dist/date.d.ts
DELETED
package/dist/date.js
DELETED
package/dist/math.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The minus sign.
|
|
3
|
-
*/
|
|
4
|
-
export declare const minus = "\u2212";
|
|
5
|
-
/**
|
|
6
|
-
* The plus/minus sign.
|
|
7
|
-
*/
|
|
8
|
-
export declare const plusMinus = "\u00B1";
|
|
9
|
-
/**
|
|
10
|
-
* Forces signing on the given number, returning `undefined` on zero.
|
|
11
|
-
*/
|
|
12
|
-
export declare const signIgnoreZero: (x: number) => string | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* Forces signing on the given number.
|
|
15
|
-
*/
|
|
16
|
-
export declare const sign: (x: number) => string;
|
|
17
|
-
/**
|
|
18
|
-
* Returns the sign of the given number. Returns `undefined` if the number is
|
|
19
|
-
* zero.
|
|
20
|
-
*/
|
|
21
|
-
export declare const signStr: (x: number) => string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Converts a string to an integer. If the string is not a valid integer, it
|
|
24
|
-
* returns `undefined`.
|
|
25
|
-
*/
|
|
26
|
-
export declare const parseInt: (str: string) => number | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Converts a string to a natural number. If the string is not a valid natural
|
|
29
|
-
* number, it returns `undefined`.
|
|
30
|
-
*/
|
|
31
|
-
export declare const parseNat: (str: string) => number | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Returns a random integer between `0` and `max` (inclusive).
|
|
34
|
-
*/
|
|
35
|
-
export declare const randomInt: (max: number) => number;
|
|
36
|
-
/**
|
|
37
|
-
* Returns a random integer between `min` and `max` (inclusive).
|
|
38
|
-
*/
|
|
39
|
-
export declare const randomIntRange: (min: number, max: number) => number;
|
|
40
|
-
/**
|
|
41
|
-
* Returns if the given number is even.
|
|
42
|
-
*/
|
|
43
|
-
export declare const even: (x: number) => boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Returns if the given number is odd.
|
|
46
|
-
*/
|
|
47
|
-
export declare const odd: (x: number) => boolean;
|
package/dist/math.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { isInteger, isNaturalNumber } from "./regex.js";
|
|
2
|
-
/**
|
|
3
|
-
* The minus sign.
|
|
4
|
-
*/
|
|
5
|
-
export const minus = "−";
|
|
6
|
-
/**
|
|
7
|
-
* The plus/minus sign.
|
|
8
|
-
*/
|
|
9
|
-
export const plusMinus = "\xB1";
|
|
10
|
-
/**
|
|
11
|
-
* Forces signing on the given number, returning `undefined` on zero.
|
|
12
|
-
*/
|
|
13
|
-
export const signIgnoreZero = (x) => x > 0
|
|
14
|
-
? `+${x.toString()}`
|
|
15
|
-
: x < 0
|
|
16
|
-
? `${minus}\u2060${Math.abs(x).toString()}`
|
|
17
|
-
: undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Forces signing on the given number.
|
|
20
|
-
*/
|
|
21
|
-
export const sign = (x) => x > 0
|
|
22
|
-
? `+${x.toString()}`
|
|
23
|
-
: x < 0
|
|
24
|
-
? `${minus}\u2060${Math.abs(x).toString()}`
|
|
25
|
-
: "0";
|
|
26
|
-
/**
|
|
27
|
-
* Returns the sign of the given number. Returns `undefined` if the number is
|
|
28
|
-
* zero.
|
|
29
|
-
*/
|
|
30
|
-
export const signStr = (x) => x > 0 ? "+" : x < 0 ? minus : undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Converts a string to an integer. If the string is not a valid integer, it
|
|
33
|
-
* returns `undefined`.
|
|
34
|
-
*/
|
|
35
|
-
export const parseInt = (str) => str.length > 0 && isInteger(str) ? Number.parseInt(str, 10) : undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Converts a string to a natural number. If the string is not a valid natural
|
|
38
|
-
* number, it returns `undefined`.
|
|
39
|
-
*/
|
|
40
|
-
export const parseNat = (str) => str.length > 0 && isNaturalNumber(str) ? Number.parseInt(str, 10) : undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Returns a random integer between `0` and `max` (inclusive).
|
|
43
|
-
*/
|
|
44
|
-
export const randomInt = (max) => Math.floor(Math.random() * (max + 1));
|
|
45
|
-
/**
|
|
46
|
-
* Returns a random integer between `min` and `max` (inclusive).
|
|
47
|
-
*/
|
|
48
|
-
export const randomIntRange = (min, max) => Math.floor(Math.random() * (max + 1 - min)) + min;
|
|
49
|
-
/**
|
|
50
|
-
* Returns if the given number is even.
|
|
51
|
-
*/
|
|
52
|
-
export const even = (x) => x % 2 === 0;
|
|
53
|
-
/**
|
|
54
|
-
* Returns if the given number is odd.
|
|
55
|
-
*/
|
|
56
|
-
export const odd = (x) => x % 2 !== 0;
|
package/dist/regex.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the provided string is a string representation of a natural number.
|
|
3
|
-
* @param test The string to test.
|
|
4
|
-
*/
|
|
5
|
-
export declare const isNaturalNumber: (test: string) => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Checks if the provided string is a string representation of an integer.
|
|
8
|
-
* @param test The string to test.
|
|
9
|
-
*/
|
|
10
|
-
export declare const isInteger: (test: string) => boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Checks if the provided string is a string representation of a floating-point
|
|
13
|
-
* number. Both `.` and `,` are accepted as decimal separators.
|
|
14
|
-
* @param test The string to test.
|
|
15
|
-
*/
|
|
16
|
-
export declare const isFloat: (test: string) => boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Checks if the provided string either is an empty string or passes the given
|
|
19
|
-
* test function.
|
|
20
|
-
* @param check The test function to apply if the string is not empty.
|
|
21
|
-
* @param test The string to test.
|
|
22
|
-
*/
|
|
23
|
-
export declare const isEmptyOr: (check: (test: string) => boolean, test: string) => boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the provided string is a valid URL.
|
|
26
|
-
* @param test The string to test.
|
|
27
|
-
*/
|
|
28
|
-
export declare const isUrl: (test: string) => boolean;
|
package/dist/regex.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the provided string is a string representation of a natural number.
|
|
3
|
-
* @param test The string to test.
|
|
4
|
-
*/
|
|
5
|
-
export const isNaturalNumber = (test) => /^(?:0|[1-9][0-9]*)$/u.test(test);
|
|
6
|
-
/**
|
|
7
|
-
* Checks if the provided string is a string representation of an integer.
|
|
8
|
-
* @param test The string to test.
|
|
9
|
-
*/
|
|
10
|
-
export const isInteger = (test) => /^(?:0|-?[1-9][0-9]*)$/u.test(test);
|
|
11
|
-
/**
|
|
12
|
-
* Checks if the provided string is a string representation of a floating-point
|
|
13
|
-
* number. Both `.` and `,` are accepted as decimal separators.
|
|
14
|
-
* @param test The string to test.
|
|
15
|
-
*/
|
|
16
|
-
export const isFloat = (test) => /^(?:(?:0|-?[1-9][0-9]*)(?:[.,][0-9]+)?)$/u.test(test);
|
|
17
|
-
/**
|
|
18
|
-
* Checks if the provided string either is an empty string or passes the given
|
|
19
|
-
* test function.
|
|
20
|
-
* @param check The test function to apply if the string is not empty.
|
|
21
|
-
* @param test The string to test.
|
|
22
|
-
*/
|
|
23
|
-
export const isEmptyOr = (check, test) => test === "" || check(test);
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the provided string is a valid URL.
|
|
26
|
-
* @param test The string to test.
|
|
27
|
-
*/
|
|
28
|
-
export const isUrl = (test) => {
|
|
29
|
-
try {
|
|
30
|
-
return typeof new URL(test) === "object";
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
};
|