@terrygonguet/utils 0.0.8 → 0.0.9
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/dist/functional.js +4 -0
- package/dist/main.js +45 -12
- package/package.json +1 -1
- package/src/functional/index.ts +4 -0
- package/src/main.ts +38 -0
- package/types/functional/index.d.ts +1 -0
- package/types/main.d.ts +5 -0
package/dist/functional.js
CHANGED
package/dist/main.js
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { constant as r } from "./functional.js";
|
|
2
|
+
function s(n, t, e) {
|
|
3
|
+
return Math.min(Math.max(n, t), e);
|
|
3
4
|
}
|
|
4
|
-
function
|
|
5
|
+
function a(n, t, e) {
|
|
5
6
|
try {
|
|
6
|
-
return JSON.parse(n,
|
|
7
|
+
return JSON.parse(n, e);
|
|
7
8
|
} catch {
|
|
8
9
|
return t;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return function(t,
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
return
|
|
12
|
+
function i(...n) {
|
|
13
|
+
return function(t, e) {
|
|
14
|
+
for (const o of n)
|
|
15
|
+
e = o(t, e);
|
|
16
|
+
return e;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
function u() {
|
|
20
|
+
const n = () => o, t = r(!1), e = r(!0), o = new Proxy(() => {
|
|
21
|
+
}, {
|
|
22
|
+
get: n,
|
|
23
|
+
set: n,
|
|
24
|
+
apply: n,
|
|
25
|
+
construct: n,
|
|
26
|
+
deleteProperty: e,
|
|
27
|
+
has: e,
|
|
28
|
+
preventExtensions: t,
|
|
29
|
+
defineProperty: t
|
|
30
|
+
});
|
|
31
|
+
return o;
|
|
32
|
+
}
|
|
33
|
+
function f() {
|
|
34
|
+
}
|
|
35
|
+
function p(n) {
|
|
36
|
+
throw new Error("This should never be called");
|
|
37
|
+
}
|
|
38
|
+
async function h(n) {
|
|
39
|
+
const e = new TextEncoder().encode(n);
|
|
40
|
+
return await crypto.subtle.digest("SHA-1", e);
|
|
41
|
+
}
|
|
42
|
+
function* d(n, t, e = 1) {
|
|
43
|
+
for (let o = n; o < t; o += e)
|
|
44
|
+
yield o;
|
|
45
|
+
}
|
|
18
46
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
s as clamp,
|
|
48
|
+
i as composeJSONRevivers,
|
|
49
|
+
u as createNoopProxy,
|
|
50
|
+
p as exhaustive,
|
|
51
|
+
h as hash,
|
|
52
|
+
f as noop,
|
|
53
|
+
d as range,
|
|
54
|
+
a as safeParse
|
|
22
55
|
};
|
package/package.json
CHANGED
package/src/functional/index.ts
CHANGED
package/src/main.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { constant } from "./functional/index.ts"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Behaviour is undefined when max < min
|
|
3
5
|
*/
|
|
@@ -23,3 +25,39 @@ export function composeJSONRevivers(...revivers: JSONReviver[]): JSONReviver {
|
|
|
23
25
|
return value
|
|
24
26
|
}
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
export function createNoopProxy<T>() {
|
|
30
|
+
const noop = () => proxy
|
|
31
|
+
const no = constant(false)
|
|
32
|
+
const yes = constant(true)
|
|
33
|
+
const proxy: any = new Proxy(() => {}, {
|
|
34
|
+
get: noop,
|
|
35
|
+
set: noop,
|
|
36
|
+
apply: noop,
|
|
37
|
+
construct: noop,
|
|
38
|
+
deleteProperty: yes,
|
|
39
|
+
has: yes,
|
|
40
|
+
preventExtensions: no,
|
|
41
|
+
defineProperty: no,
|
|
42
|
+
})
|
|
43
|
+
return proxy as T
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function noop() {}
|
|
47
|
+
|
|
48
|
+
export function exhaustive(_: never): never {
|
|
49
|
+
throw new Error("This should never be called")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function hash(message: string) {
|
|
53
|
+
const encoder = new TextEncoder()
|
|
54
|
+
const data = encoder.encode(message)
|
|
55
|
+
const hash = await crypto.subtle.digest("SHA-1", data)
|
|
56
|
+
return hash
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function* range(start: number, end: number, step = 1) {
|
|
60
|
+
for (let i = start; i < end; i += step) {
|
|
61
|
+
yield i
|
|
62
|
+
}
|
|
63
|
+
}
|
package/types/main.d.ts
CHANGED
|
@@ -5,4 +5,9 @@ export declare function clamp(value: number, min: number, max: number): number;
|
|
|
5
5
|
type JSONReviver = (key: string, value: any) => any;
|
|
6
6
|
export declare function safeParse<T>(str: string, defaultValue: T, reviver?: JSONReviver): any;
|
|
7
7
|
export declare function composeJSONRevivers(...revivers: JSONReviver[]): JSONReviver;
|
|
8
|
+
export declare function createNoopProxy<T>(): T;
|
|
9
|
+
export declare function noop(): void;
|
|
10
|
+
export declare function exhaustive(_: never): never;
|
|
11
|
+
export declare function hash(message: string): Promise<ArrayBuffer>;
|
|
12
|
+
export declare function range(start: number, end: number, step?: number): Generator<number, void, unknown>;
|
|
8
13
|
export {};
|