@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.
@@ -159,9 +159,13 @@ function w(t, e) {
159
159
  function $(t) {
160
160
  return t;
161
161
  }
162
+ function O(t) {
163
+ return () => t;
164
+ }
162
165
  export {
163
166
  y as Maybe,
164
167
  v as Result,
165
168
  N as compose,
169
+ O as constant,
166
170
  $ as identity
167
171
  };
package/dist/main.js CHANGED
@@ -1,22 +1,55 @@
1
- function o(n, t, r) {
2
- return Math.min(Math.max(n, t), r);
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 c(n, t, r) {
5
+ function a(n, t, e) {
5
6
  try {
6
- return JSON.parse(n, r);
7
+ return JSON.parse(n, e);
7
8
  } catch {
8
9
  return t;
9
10
  }
10
11
  }
11
- function f(...n) {
12
- return function(t, r) {
13
- for (const e of n)
14
- r = e(t, r);
15
- return r;
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
- o as clamp,
20
- f as composeJSONRevivers,
21
- c as safeParse
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrygonguet/utils",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "module": "./dist/main.js",
6
6
  "author": {
@@ -5,3 +5,7 @@ export { default as compose } from "just-compose"
5
5
  export function identity<T>(value: T) {
6
6
  return value
7
7
  }
8
+
9
+ export function constant<T>(value: T) {
10
+ return () => value
11
+ }
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
+ }
@@ -2,3 +2,4 @@ export * from "./maybe.ts";
2
2
  export * from "./result.ts";
3
3
  export { default as compose } from "just-compose";
4
4
  export declare function identity<T>(value: T): T;
5
+ export declare function constant<T>(value: T): () => T;
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 {};