@tempots/std 0.9.7 → 0.10.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.
Files changed (106) hide show
  1. package/README.md +1 -3
  2. package/array.cjs +1 -0
  3. package/{arrays.d.ts → array.d.ts} +7 -7
  4. package/array.js +223 -0
  5. package/bigint.cjs +1 -0
  6. package/bigint.js +96 -110
  7. package/boolean.cjs +1 -0
  8. package/boolean.js +44 -0
  9. package/domain.cjs +1 -0
  10. package/domain.d.ts +22 -0
  11. package/domain.js +1 -0
  12. package/equal.cjs +1 -0
  13. package/equal.js +68 -0
  14. package/function.cjs +1 -0
  15. package/function.js +29 -0
  16. package/index.cjs +1 -0
  17. package/index.d.ts +0 -0
  18. package/index.js +1 -0
  19. package/maybe.cjs +1 -0
  20. package/maybe.d.ts +3 -3
  21. package/maybe.js +8 -24
  22. package/number.cjs +1 -0
  23. package/{numbers.d.ts → number.d.ts} +2 -5
  24. package/number.js +103 -0
  25. package/object.cjs +1 -0
  26. package/object.d.ts +8 -0
  27. package/object.js +30 -0
  28. package/package.json +95 -25
  29. package/regexp.cjs +1 -0
  30. package/regexp.js +14 -0
  31. package/string.cjs +3 -0
  32. package/{strings.d.ts → string.d.ts} +0 -2
  33. package/string.js +396 -0
  34. package/arrays.js +0 -249
  35. package/async-result.d.ts +0 -37
  36. package/async-result.js +0 -75
  37. package/booleans.js +0 -68
  38. package/colors/cmyk.d.ts +0 -21
  39. package/colors/cmyk.js +0 -54
  40. package/colors/convert.d.ts +0 -283
  41. package/colors/convert.js +0 -742
  42. package/colors/hsl.d.ts +0 -24
  43. package/colors/hsl.js +0 -56
  44. package/colors/hsla.d.ts +0 -18
  45. package/colors/hsla.js +0 -35
  46. package/colors/hsluv.d.ts +0 -24
  47. package/colors/hsluv.js +0 -56
  48. package/colors/hsv.d.ts +0 -24
  49. package/colors/hsv.js +0 -54
  50. package/colors/lab.d.ts +0 -24
  51. package/colors/lab.js +0 -54
  52. package/colors/lch.d.ts +0 -19
  53. package/colors/lch.js +0 -44
  54. package/colors/luv.d.ts +0 -19
  55. package/colors/luv.js +0 -45
  56. package/colors/rgb.d.ts +0 -13
  57. package/colors/rgb.js +0 -47
  58. package/colors/rgba.d.ts +0 -12
  59. package/colors/rgba.js +0 -44
  60. package/colors/srgb.d.ts +0 -24
  61. package/colors/srgb.js +0 -51
  62. package/colors/xyz.d.ts +0 -19
  63. package/colors/xyz.js +0 -41
  64. package/edit.d.ts +0 -20
  65. package/edit.js +0 -29
  66. package/equals.js +0 -122
  67. package/functions.js +0 -38
  68. package/json.d.ts +0 -14
  69. package/json.js +0 -33
  70. package/match.d.ts +0 -16
  71. package/match.js +0 -45
  72. package/memoize.d.ts +0 -1
  73. package/memoize.js +0 -9
  74. package/newtype.d.ts +0 -28
  75. package/newtype.js +0 -29
  76. package/numbers.js +0 -183
  77. package/objects.d.ts +0 -9
  78. package/objects.js +0 -33
  79. package/ord.d.ts +0 -19
  80. package/ord.js +0 -73
  81. package/reg-exps.js +0 -43
  82. package/result.d.ts +0 -31
  83. package/result.js +0 -95
  84. package/strings.js +0 -685
  85. package/types/assert.d.ts +0 -12
  86. package/types/assert.js +0 -13
  87. package/types/differentiate.d.ts +0 -13
  88. package/types/differentiate.js +0 -14
  89. package/types/functions.d.ts +0 -22
  90. package/types/functions.js +0 -13
  91. package/types/generic.d.ts +0 -9
  92. package/types/generic.js +0 -13
  93. package/types/objects.d.ts +0 -50
  94. package/types/objects.js +0 -13
  95. package/types/tuples.d.ts +0 -44
  96. package/types/tuples.js +0 -24
  97. package/types/utility.d.ts +0 -2
  98. package/types/utility.js +0 -1
  99. package/uuid.d.ts +0 -13
  100. package/uuid.js +0 -56
  101. package/validation.d.ts +0 -23
  102. package/validation.js +0 -44
  103. /package/{booleans.d.ts → boolean.d.ts} +0 -0
  104. /package/{equals.d.ts → equal.d.ts} +0 -0
  105. /package/{functions.d.ts → function.d.ts} +0 -0
  106. /package/{reg-exps.d.ts → regexp.d.ts} +0 -0
package/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/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/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/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/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/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/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/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/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/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/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/memoize.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function memoize<T>(f: () => T): () => T;
package/memoize.js DELETED
@@ -1,9 +0,0 @@
1
- export function memoize(f) {
2
- let value;
3
- return () => {
4
- if (value === undefined) {
5
- value = f();
6
- }
7
- return value;
8
- };
9
- }
package/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/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
- }