@tempots/std 0.9.7 → 0.10.3
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 +1 -3
- package/array.cjs +1 -0
- package/{arrays.d.ts → array.d.ts} +7 -7
- package/array.js +223 -0
- package/bigint.cjs +1 -0
- package/bigint.js +96 -110
- package/boolean.cjs +1 -0
- package/boolean.js +44 -0
- package/domain.cjs +1 -0
- package/domain.d.ts +22 -0
- package/domain.js +1 -0
- package/equal.cjs +1 -0
- package/equal.js +68 -0
- package/function.cjs +1 -0
- package/function.js +29 -0
- package/index.cjs +1 -0
- package/index.d.ts +0 -0
- package/index.js +1 -0
- package/maybe.cjs +1 -0
- package/maybe.d.ts +3 -3
- package/maybe.js +8 -24
- package/number.cjs +1 -0
- package/{numbers.d.ts → number.d.ts} +2 -5
- package/number.js +103 -0
- package/object.cjs +1 -0
- package/object.d.ts +8 -0
- package/object.js +30 -0
- package/package.json +55 -25
- package/regexp.cjs +1 -0
- package/regexp.js +14 -0
- package/string.cjs +3 -0
- package/{strings.d.ts → string.d.ts} +0 -2
- package/string.js +396 -0
- package/arrays.js +0 -249
- package/async-result.d.ts +0 -37
- package/async-result.js +0 -75
- package/booleans.js +0 -68
- package/colors/cmyk.d.ts +0 -21
- package/colors/cmyk.js +0 -54
- package/colors/convert.d.ts +0 -283
- package/colors/convert.js +0 -742
- package/colors/hsl.d.ts +0 -24
- package/colors/hsl.js +0 -56
- package/colors/hsla.d.ts +0 -18
- package/colors/hsla.js +0 -35
- package/colors/hsluv.d.ts +0 -24
- package/colors/hsluv.js +0 -56
- package/colors/hsv.d.ts +0 -24
- package/colors/hsv.js +0 -54
- package/colors/lab.d.ts +0 -24
- package/colors/lab.js +0 -54
- package/colors/lch.d.ts +0 -19
- package/colors/lch.js +0 -44
- package/colors/luv.d.ts +0 -19
- package/colors/luv.js +0 -45
- package/colors/rgb.d.ts +0 -13
- package/colors/rgb.js +0 -47
- package/colors/rgba.d.ts +0 -12
- package/colors/rgba.js +0 -44
- package/colors/srgb.d.ts +0 -24
- package/colors/srgb.js +0 -51
- package/colors/xyz.d.ts +0 -19
- package/colors/xyz.js +0 -41
- package/edit.d.ts +0 -20
- package/edit.js +0 -29
- package/equals.js +0 -122
- package/functions.js +0 -38
- package/json.d.ts +0 -14
- package/json.js +0 -33
- package/match.d.ts +0 -16
- package/match.js +0 -45
- package/memoize.d.ts +0 -1
- package/memoize.js +0 -9
- package/newtype.d.ts +0 -28
- package/newtype.js +0 -29
- package/numbers.js +0 -183
- package/objects.d.ts +0 -9
- package/objects.js +0 -33
- package/ord.d.ts +0 -19
- package/ord.js +0 -73
- package/reg-exps.js +0 -43
- package/result.d.ts +0 -31
- package/result.js +0 -95
- package/strings.js +0 -685
- package/types/assert.d.ts +0 -12
- package/types/assert.js +0 -13
- package/types/differentiate.d.ts +0 -13
- package/types/differentiate.js +0 -14
- package/types/functions.d.ts +0 -22
- package/types/functions.js +0 -13
- package/types/generic.d.ts +0 -9
- package/types/generic.js +0 -13
- package/types/objects.d.ts +0 -50
- package/types/objects.js +0 -13
- package/types/tuples.d.ts +0 -44
- package/types/tuples.js +0 -24
- package/types/utility.d.ts +0 -2
- package/types/utility.js +0 -1
- package/uuid.d.ts +0 -13
- package/uuid.js +0 -56
- package/validation.d.ts +0 -23
- package/validation.js +0 -44
- /package/{booleans.d.ts → boolean.d.ts} +0 -0
- /package/{equals.d.ts → equal.d.ts} +0 -0
- /package/{functions.d.ts → function.d.ts} +0 -0
- /package/{reg-exps.d.ts → regexp.d.ts} +0 -0
package/types/differentiate.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
import { type AnyKey } from './utility';
|
|
5
|
-
import { type ObjectWithField } from './objects';
|
|
6
|
-
import { type Tail } from './tuples';
|
|
7
|
-
export type Differentiate<Field extends AnyKey, State extends ObjectWithField<Field, any>, ExpectedType extends State[Field]> = State extends ObjectWithField<Field, ExpectedType> ? State : never;
|
|
8
|
-
export type DifferentiateByKind<State extends {
|
|
9
|
-
kind: any;
|
|
10
|
-
}, K extends State['kind']> = Differentiate<'kind', State, K>;
|
|
11
|
-
export type DifferentiateAt<Path extends AnyKey[], State, ExpectedType> = Path extends [] ? State : Path extends [infer T] ? T extends keyof State ? ExpectedType extends State[T] ? Differentiate<T, State, ExpectedType> : never : never : Path extends [infer K, ...any[]] ? K extends keyof State ? Tail<Path> extends infer Rest ? Rest extends AnyKey[] ? State & {
|
|
12
|
-
[k in K]: DifferentiateAt<Rest, State[k], ExpectedType>;
|
|
13
|
-
} : never : never : never : never;
|
package/types/differentiate.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2019 Google LLC
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
See the License for the specific language governing permissions and
|
|
12
|
-
limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
package/types/functions.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type Tail } from './tuples';
|
|
2
|
-
export type Equality<T> = (a: T, b: T) => boolean;
|
|
3
|
-
export type Effect<T> = (value: T) => void;
|
|
4
|
-
export type Proc = () => void;
|
|
5
|
-
export type Lazy<T> = () => T;
|
|
6
|
-
export type Fun = (...args: any[]) => any;
|
|
7
|
-
export type Fun1<A, T> = (a1: A) => T;
|
|
8
|
-
export type Fun2<A, B, T> = (a1: A, a2: B) => T;
|
|
9
|
-
export type Fun3<A, B, C, T> = (a1: A, a2: B, a3: C) => T;
|
|
10
|
-
export type Fun4<A, B, C, D, T> = (a1: A, a2: B, a3: C, a4: D) => T;
|
|
11
|
-
export type Fun5<A, B, C, D, E, T> = (a1: A, a2: B, a3: C, a4: D, a5: E) => T;
|
|
12
|
-
export type Fun6<A, B, C, D, E, F, T> = (a1: A, a2: B, a3: C, a4: D, a5: E, a6: F) => T;
|
|
13
|
-
export type AnyFunction = Fun | Function;
|
|
14
|
-
export type FirstArgument<F extends AnyFunction> = F extends (a: infer A) => any ? unknown extends A ? never : A : never;
|
|
15
|
-
export type OnlyIfDoesNotReturnNever<F extends Fun> = F extends Fun1<any, never> ? never : F;
|
|
16
|
-
type CheckFunctionsChain<In, Args extends Array<Fun1<any, any>>> = {
|
|
17
|
-
empty: (i: In) => In;
|
|
18
|
-
one: FirstArgument<Args[0]> extends In ? Args[0] : never;
|
|
19
|
-
n: FirstArgument<Args[0]> extends In ? (arg: FirstArgument<Args[0]>) => ReturnType<CheckFunctionsChain<ReturnType<Args[0]>, Tail<Args>>> : never;
|
|
20
|
-
}[Args extends [] ? 'empty' : Args extends [any] ? 'one' : 'n'];
|
|
21
|
-
export type FunctionsChain<In, Args extends Fun[]> = OnlyIfDoesNotReturnNever<CheckFunctionsChain<In, Args>>;
|
|
22
|
-
export {};
|
package/types/functions.js
DELETED
|
@@ -1,13 +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 {};
|
package/types/generic.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
import { type Equals, type NotEquals } from './assert';
|
|
5
|
-
export type Pointer<T> = () => T;
|
|
6
|
-
export type DeRef<T extends () => any> = T extends () => infer Ret ? Ret : never;
|
|
7
|
-
export type WhenEquals<X, Y, A = X, B = never> = Equals<X, Y> extends true ? A : B;
|
|
8
|
-
export type WhenNotEquals<X, Y, A = X, B = never> = NotEquals<X, Y> extends true ? A : B;
|
|
9
|
-
export type Cast<A, B> = A extends B ? A : B;
|
package/types/generic.js
DELETED
|
@@ -1,13 +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 {};
|
package/types/objects.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
import { type AnyKey } from './utility';
|
|
5
|
-
import { type Tail } from './tuples';
|
|
6
|
-
import { type AnyFunction } from './functions';
|
|
7
|
-
import { type WhenEquals } from './generic';
|
|
8
|
-
export type ObjectWithField<F extends AnyKey, V> = {
|
|
9
|
-
[_ in F]: V;
|
|
10
|
-
};
|
|
11
|
-
export type ObjectWithPath<Path extends AnyKey[], V> = Path extends [] ? {} : Path extends [infer T] ? T extends AnyKey ? {
|
|
12
|
-
[_ in T]: V;
|
|
13
|
-
} : never : Path extends [infer K, ...any[]] ? K extends AnyKey ? Tail<Path> extends infer Rest ? Rest extends AnyKey[] ? {
|
|
14
|
-
[_ in K]: ObjectWithPath<Rest, V>;
|
|
15
|
-
} : never : never : never : never;
|
|
16
|
-
export type TypeAtPath<Path extends AnyKey[], O> = {
|
|
17
|
-
next: Path extends [infer K, ...any[]] ? K extends AnyKey ? Tail<Path> extends infer Rest ? O extends Record<AnyKey, any> ? Rest extends AnyKey[] ? TypeAtPath<Rest, O[K]> : never : never : never : never : never;
|
|
18
|
-
empty: O;
|
|
19
|
-
done: O extends Record<AnyKey, any> ? Path extends [infer K] ? K extends AnyKey ? O[K] : never : never : never;
|
|
20
|
-
}[Path extends [] ? 'empty' : Path extends [any] ? 'done' : 'next'];
|
|
21
|
-
export type WritableKeys<T> = {
|
|
22
|
-
[K in keyof T]-?: WhenEquals<{
|
|
23
|
-
[Q in K]: T[K];
|
|
24
|
-
}, {
|
|
25
|
-
-readonly [Q in K]: T[K];
|
|
26
|
-
}, K>;
|
|
27
|
-
}[keyof T];
|
|
28
|
-
export type ReadonlyKeys<T> = {
|
|
29
|
-
[P in keyof T]-?: WhenEquals<{
|
|
30
|
-
[Q in P]: T[P];
|
|
31
|
-
}, {
|
|
32
|
-
-readonly [Q in P]: T[P];
|
|
33
|
-
}, never, P>;
|
|
34
|
-
}[keyof T];
|
|
35
|
-
export type Id<T> = {} & {
|
|
36
|
-
[P in keyof T]: T[P];
|
|
37
|
-
};
|
|
38
|
-
export type KeysWithFieldType<T, Condition> = {
|
|
39
|
-
[K in keyof T]: WhenEquals<T[K], Condition, K>;
|
|
40
|
-
}[keyof T];
|
|
41
|
-
export type KeysWithoutFieldType<T, Condition> = {
|
|
42
|
-
[K in keyof T]: WhenEquals<T[K], Condition, never, K>;
|
|
43
|
-
}[keyof T];
|
|
44
|
-
export type RemoveNullableFromFields<T> = {
|
|
45
|
-
[K in keyof T]: NonNullable<T[K]>;
|
|
46
|
-
};
|
|
47
|
-
export type WritableFields<T> = Pick<T, WritableKeys<T>>;
|
|
48
|
-
export type ReadonlyFields<T> = Pick<T, ReadonlyKeys<T>>;
|
|
49
|
-
export type ExcludeFunctionFields<T> = Pick<T, KeysWithoutFieldType<T, AnyFunction>>;
|
|
50
|
-
export type Merge<A, B> = Id<A & B>;
|
package/types/objects.js
DELETED
|
@@ -1,13 +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 {};
|
package/types/tuples.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
import { type Pointer, type DeRef } from './generic';
|
|
5
|
-
export type Tail<T extends any[]> = ((...args: T) => void) extends (_: any, ...rest: infer Rest) => void ? Rest : never;
|
|
6
|
-
type DropNImpl<N extends number, T extends any[], I extends any[]> = {
|
|
7
|
-
return: T;
|
|
8
|
-
next: DropNImpl<N, Tail<T>, Prepend<any, I>>;
|
|
9
|
-
}[Length<I> extends N ? 'return' : 'next'];
|
|
10
|
-
export type DropN<N extends number, T extends any[]> = DropNImpl<N, T, []>;
|
|
11
|
-
type ReverseImpl<T extends any[], R extends any[], I extends any[]> = {
|
|
12
|
-
return: DeRef<Pointer<R>>;
|
|
13
|
-
next: ReverseImpl<T, Prepend<T[Length<I>], R>, Prepend<any, I>>;
|
|
14
|
-
}[Length<I> extends Length<T> ? 'return' : 'next'];
|
|
15
|
-
export type Reverse<T extends any[]> = ReverseImpl<T, [], []>;
|
|
16
|
-
export type Head<T extends any[]> = T extends [infer H, ...any[]] ? H : never;
|
|
17
|
-
export type Last<T extends any[]> = {
|
|
18
|
-
n: Last<Tail<T>>;
|
|
19
|
-
one: T extends [infer H] ? H : never;
|
|
20
|
-
empty: never;
|
|
21
|
-
}[T extends [] ? 'empty' : T extends [any] ? 'one' : 'n'];
|
|
22
|
-
export type TupleToUnion<T extends any[]> = T[number];
|
|
23
|
-
export type Prepend<Insert, Tail extends any[]> = [Insert, ...Tail];
|
|
24
|
-
export type Append<Tuple extends any[], Element> = [...Tuple, Element];
|
|
25
|
-
export type Length<T extends any[]> = T['length'];
|
|
26
|
-
export type LoseLastImpl<A extends any[], B extends any[]> = {
|
|
27
|
-
empty: A;
|
|
28
|
-
next: LoseLastImpl<Prepend<B[0], A>, Tail<B>>;
|
|
29
|
-
}[B extends [] ? 'empty' : B extends [any] ? 'empty' : 'next'];
|
|
30
|
-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
31
|
-
type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
|
|
32
|
-
export type Push<T extends any[], V> = [...T, V];
|
|
33
|
-
export type UnionToTuple<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple1<Exclude<T, L>>, L>;
|
|
34
|
-
type UnionToTuple1<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple2<Exclude<T, L>>, L>;
|
|
35
|
-
type UnionToTuple2<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple3<Exclude<T, L>>, L>;
|
|
36
|
-
type UnionToTuple3<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple4<Exclude<T, L>>, L>;
|
|
37
|
-
type UnionToTuple4<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple5<Exclude<T, L>>, L>;
|
|
38
|
-
type UnionToTuple5<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple6<Exclude<T, L>>, L>;
|
|
39
|
-
type UnionToTuple6<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple7<Exclude<T, L>>, L>;
|
|
40
|
-
type UnionToTuple7<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple8<Exclude<T, L>>, L>;
|
|
41
|
-
type UnionToTuple8<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTuple9<Exclude<T, L>>, L>;
|
|
42
|
-
type UnionToTuple9<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<UnionToTupleX<Exclude<T, L>>, L>;
|
|
43
|
-
type UnionToTupleX<T> = never;
|
|
44
|
-
export {};
|
package/types/tuples.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2019 Google LLC
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
See the License for the specific language governing permissions and
|
|
12
|
-
limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
|
15
|
-
// | _Concat_0_0
|
|
16
|
-
// | _Concat_0_1
|
|
17
|
-
// | _Concat_1_0
|
|
18
|
-
// | _Concat_2_3
|
|
19
|
-
// | _Pop_1
|
|
20
|
-
// | _Pop_2
|
|
21
|
-
// | _LoseLast_1
|
|
22
|
-
// | _LoseLast_2
|
|
23
|
-
// | _LoseLast_3
|
|
24
|
-
// | _LoseLast_4
|
package/types/utility.d.ts
DELETED
package/types/utility.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/uuid.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper functions to generate and validate [UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier)
|
|
3
|
-
* strings (version 4).
|
|
4
|
-
*/
|
|
5
|
-
import { type Newtype, NewtypeClass } from './newtype';
|
|
6
|
-
/**
|
|
7
|
-
* `Uuid.create()` returns a string value representing a random UUID string.
|
|
8
|
-
*/
|
|
9
|
-
export declare function create(): UUID;
|
|
10
|
-
export type UUID = Newtype<string, {
|
|
11
|
-
readonly UUID: unique symbol;
|
|
12
|
-
}>;
|
|
13
|
-
export declare const UUID: NewtypeClass<UUID>;
|
package/uuid.js
DELETED
|
@@ -1,56 +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
|
-
/**
|
|
14
|
-
* Helper functions to generate and validate [UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier)
|
|
15
|
-
* strings (version 4).
|
|
16
|
-
*/
|
|
17
|
-
import { NewtypeClass } from './newtype';
|
|
18
|
-
const random = (max) => Math.floor(Math.random() * max);
|
|
19
|
-
const srandom = () => '0123456789abcdef'.charAt(random(0x10));
|
|
20
|
-
/**
|
|
21
|
-
* `Uuid.create()` returns a string value representing a random UUID string.
|
|
22
|
-
*/
|
|
23
|
-
export function create() {
|
|
24
|
-
const s = [];
|
|
25
|
-
let i = 0;
|
|
26
|
-
for (i = 0; i < 8; i++)
|
|
27
|
-
s[i] = srandom();
|
|
28
|
-
s[8] = '-';
|
|
29
|
-
for (i = 9; i < 13; i++)
|
|
30
|
-
s[i] = srandom();
|
|
31
|
-
s[13] = '-';
|
|
32
|
-
s[14] = '4';
|
|
33
|
-
for (i = 15; i < 18; i++)
|
|
34
|
-
s[i] = srandom();
|
|
35
|
-
s[18] = '-';
|
|
36
|
-
s[19] = '89AB'.charAt(random(0x3));
|
|
37
|
-
for (i = 20; i < 23; i++)
|
|
38
|
-
s[i] = srandom();
|
|
39
|
-
s[23] = '-';
|
|
40
|
-
for (i = 24; i < 36; i++)
|
|
41
|
-
s[i] = srandom();
|
|
42
|
-
return UUID.unsafeOf(s.join(''));
|
|
43
|
-
}
|
|
44
|
-
const pattern = /^[0123456789abcdef]{8}-[0123456789abcdef]{4}-4[0123456789abcdef]{3}-[89ab][0123456789abcdef]{3}-[0123456789abcdef]{12}$/i;
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
46
|
-
export const UUID = new (class extends NewtypeClass {
|
|
47
|
-
/**
|
|
48
|
-
* Returns `true` if the passed `uuid` conforms to the UUID v.4 format.
|
|
49
|
-
*/
|
|
50
|
-
isValid(uuid) {
|
|
51
|
-
return pattern.test(uuid);
|
|
52
|
-
}
|
|
53
|
-
toString(uuid) {
|
|
54
|
-
return UUID.get(uuid);
|
|
55
|
-
}
|
|
56
|
-
})();
|
package/validation.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Result } from './result';
|
|
2
|
-
export interface Valid {
|
|
3
|
-
type: 'valid';
|
|
4
|
-
}
|
|
5
|
-
export interface Invalid<E> {
|
|
6
|
-
type: 'invalid';
|
|
7
|
-
error: E;
|
|
8
|
-
}
|
|
9
|
-
export type Validation<E> = Valid | Invalid<E>;
|
|
10
|
-
export type PromiseValidation<E> = PromiseLike<Validation<E>>;
|
|
11
|
-
export declare const Validation: {
|
|
12
|
-
valid: {
|
|
13
|
-
type: "valid";
|
|
14
|
-
};
|
|
15
|
-
invalid<E>(error: E): Validation<E>;
|
|
16
|
-
isValid<E_1>(r: Validation<E_1>): r is Valid;
|
|
17
|
-
isInvalid<E_2>(r: Validation<E_2>): r is Invalid<E_2>;
|
|
18
|
-
cmatch: <V, E_3>(valid: () => V, invalid: (error: E_3) => V) => (r: Validation<E_3>) => V;
|
|
19
|
-
match: <V_1, E_4>(r: Validation<E_4>, valid: () => V_1, invalid: (error: E_4) => V_1) => V_1;
|
|
20
|
-
toResult: <T, E_5>(value: T) => (validation: Validation<E_5>) => Result<T, E_5>;
|
|
21
|
-
whenValid: <E_6>(apply: () => void) => (r: Validation<E_6>) => Validation<E_6>;
|
|
22
|
-
whenInvalid: <E_7>(apply: (e: E_7) => void) => (r: Validation<E_7>) => Validation<E_7>;
|
|
23
|
-
};
|
package/validation.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Result } from './result';
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
3
|
-
export const Validation = {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
valid: { type: 'valid' },
|
|
6
|
-
invalid(error) {
|
|
7
|
-
return { type: 'invalid', error };
|
|
8
|
-
},
|
|
9
|
-
isValid(r) {
|
|
10
|
-
return r.type === 'valid';
|
|
11
|
-
},
|
|
12
|
-
isInvalid(r) {
|
|
13
|
-
return r.type === 'invalid';
|
|
14
|
-
},
|
|
15
|
-
cmatch: (valid, invalid) => (r) => {
|
|
16
|
-
if (Validation.isValid(r)) {
|
|
17
|
-
return valid();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return invalid(r.error);
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
match: (r, valid, invalid) => {
|
|
24
|
-
if (Validation.isValid(r)) {
|
|
25
|
-
return valid();
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return invalid(r.error);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
toResult: (value) => Validation.cmatch(() => Result.success(value), (err) => Result.failure(err)),
|
|
32
|
-
whenValid: (apply) => (r) => {
|
|
33
|
-
if (Validation.isValid(r)) {
|
|
34
|
-
apply();
|
|
35
|
-
}
|
|
36
|
-
return r;
|
|
37
|
-
},
|
|
38
|
-
whenInvalid: (apply) => (r) => {
|
|
39
|
-
if (Validation.isInvalid(r)) {
|
|
40
|
-
apply(r.error);
|
|
41
|
-
}
|
|
42
|
-
return r;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|