@tempots/std 0.9.2 → 0.9.5
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/README.md +3 -0
- package/package.json +2 -2
- package/dist/arrays.d.ts +0 -49
- package/dist/arrays.js +0 -249
- package/dist/async-result.d.ts +0 -37
- package/dist/async-result.js +0 -75
- package/dist/bigint.d.ts +0 -18
- package/dist/bigint.js +0 -110
- package/dist/booleans.d.ts +0 -23
- package/dist/booleans.js +0 -68
- package/dist/colors/cmyk.d.ts +0 -21
- package/dist/colors/cmyk.js +0 -54
- package/dist/colors/convert.d.ts +0 -283
- package/dist/colors/convert.js +0 -742
- package/dist/colors/hsl.d.ts +0 -24
- package/dist/colors/hsl.js +0 -56
- package/dist/colors/hsla.d.ts +0 -18
- package/dist/colors/hsla.js +0 -35
- package/dist/colors/hsluv.d.ts +0 -24
- package/dist/colors/hsluv.js +0 -56
- package/dist/colors/hsv.d.ts +0 -24
- package/dist/colors/hsv.js +0 -54
- package/dist/colors/lab.d.ts +0 -24
- package/dist/colors/lab.js +0 -54
- package/dist/colors/lch.d.ts +0 -19
- package/dist/colors/lch.js +0 -44
- package/dist/colors/luv.d.ts +0 -19
- package/dist/colors/luv.js +0 -45
- package/dist/colors/rgb.d.ts +0 -13
- package/dist/colors/rgb.js +0 -47
- package/dist/colors/rgba.d.ts +0 -12
- package/dist/colors/rgba.js +0 -44
- package/dist/colors/srgb.d.ts +0 -24
- package/dist/colors/srgb.js +0 -51
- package/dist/colors/xyz.d.ts +0 -19
- package/dist/colors/xyz.js +0 -41
- package/dist/edit.d.ts +0 -20
- package/dist/edit.js +0 -29
- package/dist/equals.d.ts +0 -3
- package/dist/equals.js +0 -122
- package/dist/functions.d.ts +0 -20
- package/dist/functions.js +0 -38
- package/dist/json.d.ts +0 -14
- package/dist/json.js +0 -33
- package/dist/match.d.ts +0 -16
- package/dist/match.js +0 -45
- package/dist/maybe.d.ts +0 -9
- package/dist/maybe.js +0 -25
- package/dist/memoize.d.ts +0 -1
- package/dist/memoize.js +0 -9
- package/dist/newtype.d.ts +0 -28
- package/dist/newtype.js +0 -29
- package/dist/numbers.d.ts +0 -104
- package/dist/numbers.js +0 -183
- package/dist/objects.d.ts +0 -9
- package/dist/objects.js +0 -33
- package/dist/ord.d.ts +0 -19
- package/dist/ord.js +0 -73
- package/dist/reg-exps.d.ts +0 -10
- package/dist/reg-exps.js +0 -43
- package/dist/result.d.ts +0 -31
- package/dist/result.js +0 -95
- package/dist/strings.d.ts +0 -314
- package/dist/strings.js +0 -685
- package/dist/types/assert.d.ts +0 -12
- package/dist/types/assert.js +0 -13
- package/dist/types/differentiate.d.ts +0 -13
- package/dist/types/differentiate.js +0 -14
- package/dist/types/functions.d.ts +0 -22
- package/dist/types/functions.js +0 -13
- package/dist/types/generic.d.ts +0 -9
- package/dist/types/generic.js +0 -13
- package/dist/types/objects.d.ts +0 -50
- package/dist/types/objects.js +0 -13
- package/dist/types/tuples.d.ts +0 -44
- package/dist/types/tuples.js +0 -24
- package/dist/types/utility.d.ts +0 -2
- package/dist/types/utility.js +0 -1
- package/dist/uuid.d.ts +0 -13
- package/dist/uuid.js +0 -56
- package/dist/validation.d.ts +0 -23
- package/dist/validation.js +0 -44
package/dist/colors/srgb.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers';
|
|
2
|
-
const TOLLERANCE = 0.001;
|
|
3
|
-
export class SRGB {
|
|
4
|
-
static fromString(s) {
|
|
5
|
-
const m = s.match(/^rgb\((\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%\)$/);
|
|
6
|
-
if (m != null) {
|
|
7
|
-
const [, red, blue, green] = m;
|
|
8
|
-
return new SRGB(parseFloat(red), parseFloat(blue), parseFloat(green));
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
throw new Error(`Invalid RGB string: ${s}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
static ofChannels([red, blue, green]) {
|
|
15
|
-
return new SRGB(clamp(red * 100, 0, 100), clamp(blue * 100, 0, 100), clamp(green * 100, 0, 100));
|
|
16
|
-
}
|
|
17
|
-
red;
|
|
18
|
-
blue;
|
|
19
|
-
green;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @param red Percentage (0-100)
|
|
23
|
-
* @param blue Percentage (0-100)
|
|
24
|
-
* @param green Percentage (0-100)
|
|
25
|
-
*/
|
|
26
|
-
constructor(red, blue, green) {
|
|
27
|
-
this.red = clamp(red, 0, 100);
|
|
28
|
-
this.blue = clamp(blue, 0, 100);
|
|
29
|
-
this.green = clamp(green, 0, 100);
|
|
30
|
-
}
|
|
31
|
-
withRed(red) {
|
|
32
|
-
return new SRGB(red, this.blue, this.green);
|
|
33
|
-
}
|
|
34
|
-
withBlue(blue) {
|
|
35
|
-
return new SRGB(this.red, blue, this.green);
|
|
36
|
-
}
|
|
37
|
-
withGreen(green) {
|
|
38
|
-
return new SRGB(this.red, this.blue, green);
|
|
39
|
-
}
|
|
40
|
-
toString() {
|
|
41
|
-
return `rgb(${this.red}%, ${this.blue}%, ${this.green}%)`;
|
|
42
|
-
}
|
|
43
|
-
toChannels() {
|
|
44
|
-
return [this.red / 100, this.blue / 100, this.green / 100];
|
|
45
|
-
}
|
|
46
|
-
equals(other, tollerance = TOLLERANCE) {
|
|
47
|
-
return (nearEquals(this.red, other.red, tollerance) &&
|
|
48
|
-
nearEquals(this.blue, other.blue, tollerance) &&
|
|
49
|
-
nearEquals(this.green, other.green, tollerance));
|
|
50
|
-
}
|
|
51
|
-
}
|
package/dist/colors/xyz.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare class XYZ {
|
|
2
|
-
static ofChannels([x, y, z]: [x: number, y: number, z: number]): XYZ;
|
|
3
|
-
readonly x: number;
|
|
4
|
-
readonly y: number;
|
|
5
|
-
readonly z: number;
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param x
|
|
9
|
-
* @param y 100 is the brightest white
|
|
10
|
-
* @param z
|
|
11
|
-
*/
|
|
12
|
-
constructor(x: number, y: number, z: number);
|
|
13
|
-
withX(x: number): XYZ;
|
|
14
|
-
withY(y: number): XYZ;
|
|
15
|
-
withZ(z: number): XYZ;
|
|
16
|
-
toString(): string;
|
|
17
|
-
toChannels(): [number, number, number];
|
|
18
|
-
equals(other: XYZ, tollerance?: number): boolean;
|
|
19
|
-
}
|
package/dist/colors/xyz.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { nearEquals } from '../numbers';
|
|
2
|
-
const TOLLERANCE = 0.0001;
|
|
3
|
-
export class XYZ {
|
|
4
|
-
static ofChannels([x, y, z]) {
|
|
5
|
-
return new XYZ(x, y, z);
|
|
6
|
-
}
|
|
7
|
-
x;
|
|
8
|
-
y;
|
|
9
|
-
z;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param x
|
|
13
|
-
* @param y 100 is the brightest white
|
|
14
|
-
* @param z
|
|
15
|
-
*/
|
|
16
|
-
constructor(x, y, z) {
|
|
17
|
-
this.x = x;
|
|
18
|
-
this.y = y;
|
|
19
|
-
this.z = z;
|
|
20
|
-
}
|
|
21
|
-
withX(x) {
|
|
22
|
-
return new XYZ(x, this.y, this.z);
|
|
23
|
-
}
|
|
24
|
-
withY(y) {
|
|
25
|
-
return new XYZ(this.x, y, this.z);
|
|
26
|
-
}
|
|
27
|
-
withZ(z) {
|
|
28
|
-
return new XYZ(this.x, this.y, z);
|
|
29
|
-
}
|
|
30
|
-
toString() {
|
|
31
|
-
return `XYZ(${this.x}, ${this.y}, ${this.z})`;
|
|
32
|
-
}
|
|
33
|
-
toChannels() {
|
|
34
|
-
return [this.x, this.y, this.z];
|
|
35
|
-
}
|
|
36
|
-
equals(other, tollerance = TOLLERANCE) {
|
|
37
|
-
return (nearEquals(this.x, other.x, tollerance) &&
|
|
38
|
-
nearEquals(this.y, other.y, tollerance) &&
|
|
39
|
-
nearEquals(this.z, other.z, tollerance));
|
|
40
|
-
}
|
|
41
|
-
}
|
package/dist/edit.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare abstract class Edit<V, I, E> {
|
|
2
|
-
abstract readonly type: 'Input' | 'Error' | 'Value';
|
|
3
|
-
}
|
|
4
|
-
export declare class Input<I> extends Edit<never, I, never> {
|
|
5
|
-
readonly input: I;
|
|
6
|
-
readonly type: "Input";
|
|
7
|
-
constructor(input: I);
|
|
8
|
-
}
|
|
9
|
-
export declare class Error<I, E> extends Edit<never, I, E> {
|
|
10
|
-
readonly input: I;
|
|
11
|
-
readonly error: E;
|
|
12
|
-
readonly type: "Error";
|
|
13
|
-
constructor(input: I, error: E);
|
|
14
|
-
}
|
|
15
|
-
export declare class Value<V> extends Edit<V, never, never> {
|
|
16
|
-
readonly value: V;
|
|
17
|
-
readonly type: "Value";
|
|
18
|
-
constructor(value: V);
|
|
19
|
-
}
|
|
20
|
-
export type Validate<V, I, E> = (input: Input<I> | Error<I, E>) => Error<I, E> | Value<V>;
|
package/dist/edit.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
export class Edit {
|
|
3
|
-
}
|
|
4
|
-
export class Input extends Edit {
|
|
5
|
-
input;
|
|
6
|
-
type = 'Input';
|
|
7
|
-
constructor(input) {
|
|
8
|
-
super();
|
|
9
|
-
this.input = input;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export class Error extends Edit {
|
|
13
|
-
input;
|
|
14
|
-
error;
|
|
15
|
-
type = 'Error';
|
|
16
|
-
constructor(input, error) {
|
|
17
|
-
super();
|
|
18
|
-
this.input = input;
|
|
19
|
-
this.error = error;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export class Value extends Edit {
|
|
23
|
-
value;
|
|
24
|
-
type = 'Value';
|
|
25
|
-
constructor(value) {
|
|
26
|
-
super();
|
|
27
|
-
this.value = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
package/dist/equals.d.ts
DELETED
package/dist/equals.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
export function strictEqual(a, b) {
|
|
14
|
-
// eslint-disable-next-line no-self-compare
|
|
15
|
-
return a === b || (a !== a && b !== b);
|
|
16
|
-
}
|
|
17
|
-
export function deepEqual(a, b) {
|
|
18
|
-
if (strictEqual(a, b))
|
|
19
|
-
return true;
|
|
20
|
-
if (a == null || b == null)
|
|
21
|
-
return false;
|
|
22
|
-
const aIsArr = Array.isArray(a);
|
|
23
|
-
const bIsArr = Array.isArray(b);
|
|
24
|
-
if (aIsArr !== bIsArr)
|
|
25
|
-
return false;
|
|
26
|
-
if (aIsArr) {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
const aArr = a;
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
const bArr = b;
|
|
31
|
-
const aLength = aArr.length;
|
|
32
|
-
if (aLength !== bArr.length)
|
|
33
|
-
return false;
|
|
34
|
-
for (let i = 0; i < aLength; i++) {
|
|
35
|
-
if (!deepEqual(aArr[i], bArr[i]))
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const aIsDate = a instanceof Date;
|
|
41
|
-
const bIsDate = b instanceof Date;
|
|
42
|
-
if (aIsDate !== bIsDate)
|
|
43
|
-
return false;
|
|
44
|
-
if (aIsDate) {
|
|
45
|
-
const aDate = a;
|
|
46
|
-
const bDate = b;
|
|
47
|
-
return +aDate === +bDate;
|
|
48
|
-
}
|
|
49
|
-
const aIsSet = a instanceof Set;
|
|
50
|
-
const bIsSet = b instanceof Set;
|
|
51
|
-
if (aIsSet !== bIsSet)
|
|
52
|
-
return false;
|
|
53
|
-
if (aIsSet) {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
const aSet = a;
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
const bSet = b;
|
|
58
|
-
if (aSet.size !== bSet.size)
|
|
59
|
-
return false;
|
|
60
|
-
const it = aSet.keys();
|
|
61
|
-
// eslint-disable-next-line no-constant-condition
|
|
62
|
-
while (true) {
|
|
63
|
-
const curr = it.next();
|
|
64
|
-
if (curr.done ?? false)
|
|
65
|
-
break;
|
|
66
|
-
if (!bSet.has(curr.value))
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
const aIsMap = a instanceof Map;
|
|
72
|
-
const bIsMap = b instanceof Map;
|
|
73
|
-
if (aIsMap !== bIsMap)
|
|
74
|
-
return false;
|
|
75
|
-
if (aIsMap) {
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
-
const aMap = a;
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
const bMap = b;
|
|
80
|
-
const aMapLength = aMap.size;
|
|
81
|
-
if (aMapLength !== bMap.size)
|
|
82
|
-
return false;
|
|
83
|
-
const it = aMap.keys();
|
|
84
|
-
// eslint-disable-next-line no-constant-condition
|
|
85
|
-
while (true) {
|
|
86
|
-
const curr = it.next();
|
|
87
|
-
if (curr.done ?? false)
|
|
88
|
-
break;
|
|
89
|
-
if (!deepEqual(aMap.get(curr.value), bMap.get(curr.value)))
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
const aIsObj = typeof a === 'object';
|
|
95
|
-
const bIsObj = typeof b === 'object';
|
|
96
|
-
if (aIsObj !== bIsObj)
|
|
97
|
-
return false;
|
|
98
|
-
if (aIsObj) {
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
const aObj = a;
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
-
const bObj = b;
|
|
103
|
-
const aFields = Object.keys(aObj);
|
|
104
|
-
const bFields = Object.keys(bObj);
|
|
105
|
-
const aLength = aFields.length;
|
|
106
|
-
if (aLength !== bFields.length)
|
|
107
|
-
return false;
|
|
108
|
-
for (let i = 0; i < aLength; i++) {
|
|
109
|
-
const field = aFields[i];
|
|
110
|
-
if (!Object.prototype.hasOwnProperty.call(bObj, field))
|
|
111
|
-
return false;
|
|
112
|
-
if (!deepEqual(aObj[field], bObj[field]))
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
export function looseEqual(a, b) {
|
|
120
|
-
// eslint-disable-next-line eqeqeq
|
|
121
|
-
return a == b;
|
|
122
|
-
}
|
package/dist/functions.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare function compose<A>(): (a: A) => A;
|
|
2
|
-
export declare function compose<A, B>(f1: (a: A) => B): (a: A) => B;
|
|
3
|
-
export declare function compose<A, B, C>(f1: (a: A) => B, f2: (b: B) => C): (a: A) => C;
|
|
4
|
-
export declare function compose<A, B, C, D>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D): (a: A) => D;
|
|
5
|
-
export declare function compose<A, B, C, D, E>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E): (a: A) => E;
|
|
6
|
-
export declare function compose<A, B, C, D, E, F>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E, f5: (e: E) => F): (a: A) => F;
|
|
7
|
-
export declare function compose<A, B, C, D, E, F, G>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E, f5: (e: E) => F, f6: (f: F) => G): (a: A) => G;
|
|
8
|
-
export declare function identity<T>(v: T): T;
|
|
9
|
-
export declare function curryLeft<A, Rest extends any[], Ret>(f: (a: A, ...rest: Rest) => Ret): (a: A) => (...rest: Rest) => Ret;
|
|
10
|
-
export declare function curryRight<A, B, C, D>(f: (a: A, b: B, c: C) => D): (a: A, b: B) => (c: C) => D;
|
|
11
|
-
export declare function curryRight<A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E): (a: A, b: B, c: C) => (d: D) => E;
|
|
12
|
-
export declare function curryRight<A, B, C, D, E, F>(f: (a: A, b: B, c: C, d: D, e: E) => F): (a: A, b: B, c: C, d: D) => (e: E) => F;
|
|
13
|
-
export declare function curryRight<A, B, C, D, E, F, G>(f: (a: A, b: B, c: C, d: D, e: E, f: F) => G): (a: A, b: B, c: C, d: D, e: E) => (f: F) => G;
|
|
14
|
-
export declare function flip<A, B, C>(f: (a: A, b: B) => C): (b: B, a: A) => C;
|
|
15
|
-
export declare function flip<A, B, C, D>(f: (a: A, b: B, c: C) => D): (c: C, b: B, a: A) => D;
|
|
16
|
-
export declare function flip<A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E): (d: D, c: C, b: B, a: A) => E;
|
|
17
|
-
export declare function flip<A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E): (d: D, c: C, b: B, a: A) => E;
|
|
18
|
-
export declare function flip<A, B, C, D, E, F>(f: (a: A, b: B, c: C, d: D, e: E) => F): (e: E, d: D, c: C, b: B, a: A) => F;
|
|
19
|
-
export declare function flip<A, B, C, D, E, F, G>(f: (a: A, b: B, c: C, d: D, e: E, f: F) => G): (f: F, e: E, d: D, c: C, b: B, a: A) => G;
|
|
20
|
-
export declare function id<T>(v: T): T;
|
package/dist/functions.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
export function compose(...args) {
|
|
15
|
-
return (a) => args.reduce((acc, f) => f(acc), a);
|
|
16
|
-
}
|
|
17
|
-
export function identity(v) {
|
|
18
|
-
return v;
|
|
19
|
-
}
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
export function curryLeft(f) {
|
|
22
|
-
return (a) => (...rest) => f(a, ...rest);
|
|
23
|
-
}
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
export function curryRight(f) {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
return (...args) =>
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
(a) => f(...args.concat([a]));
|
|
30
|
-
}
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
export function flip(f) {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
return (...args) => f(...args.reverse());
|
|
35
|
-
}
|
|
36
|
-
export function id(v) {
|
|
37
|
-
return v;
|
|
38
|
-
}
|
package/dist/json.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Result } from './result';
|
|
2
|
-
export type JSONPrimitive = string | boolean | number | null;
|
|
3
|
-
export interface JSONObject {
|
|
4
|
-
[k: string]: JSONValue;
|
|
5
|
-
}
|
|
6
|
-
export type JSONArray = JSONValue[];
|
|
7
|
-
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
8
|
-
export declare function deserialize(s: string): Result<JSONValue, string>;
|
|
9
|
-
export declare function makeSerializer(options: {
|
|
10
|
-
minified?: boolean;
|
|
11
|
-
whitelist?: string[];
|
|
12
|
-
}): (v: JSONValue) => string;
|
|
13
|
-
export declare function serialize(v: JSONValue): string;
|
|
14
|
-
export declare function serializeMinified(v: JSONValue): string;
|
package/dist/json.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
import { Result } from './result';
|
|
14
|
-
export function deserialize(s) {
|
|
15
|
-
try {
|
|
16
|
-
return Result.success(JSON.parse(s));
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
return Result.failure(e.message);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export function makeSerializer(options) {
|
|
24
|
-
return function serialize(v) {
|
|
25
|
-
return JSON.stringify(v, options.whitelist, options.minified === false ? undefined : 2);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export function serialize(v) {
|
|
29
|
-
return JSON.stringify(v, null, 2);
|
|
30
|
-
}
|
|
31
|
-
export function serializeMinified(v) {
|
|
32
|
-
return JSON.stringify(v);
|
|
33
|
-
}
|
package/dist/match.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Differentiate, type DifferentiateAt } from './types/differentiate';
|
|
2
|
-
import { type AnyKey } from './types/utility';
|
|
3
|
-
import { type ObjectWithField, type ObjectWithPath, type TypeAtPath } from './types/objects';
|
|
4
|
-
export declare function matchLiteral<A extends AnyKey, B>(input: A, matcher: {
|
|
5
|
-
[k in A]: B;
|
|
6
|
-
}): B;
|
|
7
|
-
export declare function match<F extends AnyKey, T extends ObjectWithField<F, any>, B>(input: T, field: F, matcher: {
|
|
8
|
-
[k in T[F]]: (arg: Differentiate<F, T, k>) => B;
|
|
9
|
-
}): B;
|
|
10
|
-
export declare function deepMatch<Path extends AnyKey[], T extends ObjectWithPath<Path, any>, B>(input: T, path: Path, matcher: {
|
|
11
|
-
[k in TypeAtPath<Path, T>]: (arg: DifferentiateAt<Path, T, k>) => B;
|
|
12
|
-
}): B;
|
|
13
|
-
export declare function createMatch<F extends AnyKey>(field: F): <T extends ObjectWithField<F, any>, B>(input: T, matcher: { [k in T[F]]: (arg: Differentiate<F, T, k>) => B; }) => B;
|
|
14
|
-
export declare const createDeepMatch: <Path extends AnyKey[]>(...path: Path) => <T extends ObjectWithPath<Path, any>, B>(input: T, matcher: { [k in TypeAtPath<Path, T>]: (arg: DifferentiateAt<Path, T, k>) => B; }) => B;
|
|
15
|
-
export declare const matchKind: <T extends ObjectWithField<"kind", any>, B>(input: T, matcher: { [k in T["kind"]]: (arg: Differentiate<"kind", T, k>) => B; }) => B;
|
|
16
|
-
export declare const matchType: <T extends ObjectWithField<"type", any>, B>(input: T, matcher: { [k in T["type"]]: (arg: Differentiate<"type", T, k>) => B; }) => B;
|
package/dist/match.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
export function matchLiteral(input, matcher) {
|
|
14
|
-
return matcher[input];
|
|
15
|
-
}
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
export function match(input, field, matcher) {
|
|
18
|
-
const k = input[field];
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
return matcher[k](input);
|
|
21
|
-
}
|
|
22
|
-
export function deepMatch(input, path, matcher) {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
const k = path.reduce((res, key) => res[key], input);
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
return matcher[k](input);
|
|
27
|
-
}
|
|
28
|
-
export function createMatch(field) {
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
return (input, matcher) => {
|
|
31
|
-
const k = input[field];
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
return matcher[k](input);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export const createDeepMatch = (...path) =>
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
(input, matcher) => {
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
const k = path.reduce((res, key) => res[key], input);
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
-
return matcher[k](input);
|
|
43
|
-
};
|
|
44
|
-
export const matchKind = createMatch('kind');
|
|
45
|
-
export const matchType = createMatch('type');
|
package/dist/maybe.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type Maybe<T> = Just<T> | Nothing;
|
|
2
|
-
export type Nothing = undefined | null;
|
|
3
|
-
export type Just<T> = T;
|
|
4
|
-
export declare const Maybe: {
|
|
5
|
-
nothing: Maybe<never>;
|
|
6
|
-
just: <T>(value: T) => Maybe<T>;
|
|
7
|
-
isNothing: <T_1>(maybe: Maybe<T_1>) => maybe is Nothing;
|
|
8
|
-
isJust: <T_2>(maybe: Maybe<T_2>) => maybe is T_2;
|
|
9
|
-
};
|
package/dist/maybe.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
14
|
-
export const Maybe = {
|
|
15
|
-
nothing: undefined,
|
|
16
|
-
just: (value) => {
|
|
17
|
-
return value;
|
|
18
|
-
},
|
|
19
|
-
isNothing: (maybe) => {
|
|
20
|
-
return maybe == null;
|
|
21
|
-
},
|
|
22
|
-
isJust: (maybe) => {
|
|
23
|
-
return maybe != null;
|
|
24
|
-
}
|
|
25
|
-
};
|
package/dist/memoize.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function memoize<T>(f: () => T): () => T;
|
package/dist/memoize.js
DELETED
package/dist/newtype.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Usage:
|
|
3
|
-
*
|
|
4
|
-
* ```ts
|
|
5
|
-
* export interface Int extends Newtype<
|
|
6
|
-
* number,
|
|
7
|
-
* { readonly Int: unique symbol }
|
|
8
|
-
* > {}
|
|
9
|
-
*
|
|
10
|
-
* export const Int = new class extends NewtypeClass<Int> {
|
|
11
|
-
* isValid(v: number) { return Number.isInteger(v) }
|
|
12
|
-
* }()
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
import { type Maybe } from './maybe';
|
|
16
|
-
export type TypeOfN<T extends Newtype<unknown, unknown>> = T['_T'];
|
|
17
|
-
export interface Newtype<V, S> {
|
|
18
|
-
readonly _T: V;
|
|
19
|
-
readonly _S: S;
|
|
20
|
-
}
|
|
21
|
-
export declare abstract class NewtypeClass<T extends Newtype<unknown, unknown>> {
|
|
22
|
-
abstract isValid(v: TypeOfN<T>): boolean;
|
|
23
|
-
unsafeOf(v: TypeOfN<T>): T;
|
|
24
|
-
of(v: TypeOfN<T>): Maybe<T>;
|
|
25
|
-
get(v: T): TypeOfN<T>;
|
|
26
|
-
modify(f: (v: TypeOfN<T>) => TypeOfN<T>): (value: T) => Maybe<T>;
|
|
27
|
-
unsafeModify(f: (v: TypeOfN<T>) => TypeOfN<T>): (value: T) => T;
|
|
28
|
-
}
|
package/dist/newtype.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
export class NewtypeClass {
|
|
14
|
-
unsafeOf(v) {
|
|
15
|
-
return v;
|
|
16
|
-
}
|
|
17
|
-
of(v) {
|
|
18
|
-
return this.isValid(v) ? v : undefined;
|
|
19
|
-
}
|
|
20
|
-
get(v) {
|
|
21
|
-
return v;
|
|
22
|
-
}
|
|
23
|
-
modify(f) {
|
|
24
|
-
return (value) => this.of(f(this.get(value)));
|
|
25
|
-
}
|
|
26
|
-
unsafeModify(f) {
|
|
27
|
-
return (value) => this.unsafeOf(f(this.get(value)));
|
|
28
|
-
}
|
|
29
|
-
}
|