@tempots/std 0.9.6 → 0.9.7
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/arrays.d.ts +49 -0
- package/arrays.js +249 -0
- package/async-result.d.ts +37 -0
- package/async-result.js +75 -0
- package/bigint.d.ts +18 -0
- package/bigint.js +110 -0
- package/booleans.d.ts +23 -0
- package/{src/booleans.ts → booleans.js} +33 -38
- package/colors/cmyk.d.ts +21 -0
- package/colors/cmyk.js +54 -0
- package/colors/convert.d.ts +283 -0
- package/colors/convert.js +742 -0
- package/colors/hsl.d.ts +24 -0
- package/colors/hsl.js +56 -0
- package/colors/hsla.d.ts +18 -0
- package/colors/hsla.js +35 -0
- package/colors/hsluv.d.ts +24 -0
- package/colors/hsluv.js +56 -0
- package/colors/hsv.d.ts +24 -0
- package/colors/hsv.js +54 -0
- package/colors/lab.d.ts +24 -0
- package/colors/lab.js +54 -0
- package/colors/lch.d.ts +19 -0
- package/colors/lch.js +44 -0
- package/colors/luv.d.ts +19 -0
- package/colors/luv.js +45 -0
- package/colors/rgb.d.ts +13 -0
- package/colors/rgb.js +47 -0
- package/colors/rgba.d.ts +12 -0
- package/colors/rgba.js +44 -0
- package/colors/srgb.d.ts +24 -0
- package/colors/srgb.js +51 -0
- package/colors/xyz.d.ts +19 -0
- package/colors/xyz.js +41 -0
- package/edit.d.ts +20 -0
- package/edit.js +29 -0
- package/equals.d.ts +3 -0
- package/equals.js +122 -0
- package/functions.d.ts +20 -0
- package/functions.js +38 -0
- package/json.d.ts +14 -0
- package/json.js +33 -0
- package/match.d.ts +16 -0
- package/match.js +45 -0
- package/maybe.d.ts +9 -0
- package/{src/maybe.ts → maybe.js} +11 -18
- package/memoize.d.ts +1 -0
- package/memoize.js +9 -0
- package/newtype.d.ts +28 -0
- package/newtype.js +29 -0
- package/numbers.d.ts +104 -0
- package/numbers.js +183 -0
- package/objects.d.ts +9 -0
- package/objects.js +33 -0
- package/ord.d.ts +19 -0
- package/ord.js +73 -0
- package/package.json +2 -2
- package/reg-exps.d.ts +10 -0
- package/{src/reg-exps.ts → reg-exps.js} +19 -24
- package/result.d.ts +31 -0
- package/result.js +95 -0
- package/strings.d.ts +314 -0
- package/strings.js +685 -0
- package/types/assert.d.ts +12 -0
- package/types/assert.js +13 -0
- package/types/differentiate.d.ts +13 -0
- package/types/differentiate.js +14 -0
- package/types/functions.d.ts +22 -0
- package/types/functions.js +13 -0
- package/types/generic.d.ts +9 -0
- package/types/generic.js +13 -0
- package/types/objects.d.ts +50 -0
- package/types/objects.js +13 -0
- package/types/tuples.d.ts +44 -0
- package/types/tuples.js +24 -0
- package/{src/types/utility.ts → types/utility.d.ts} +2 -3
- package/types/utility.js +1 -0
- package/uuid.d.ts +13 -0
- package/uuid.js +56 -0
- package/validation.d.ts +23 -0
- package/validation.js +44 -0
- package/src/arrays.ts +0 -296
- package/src/async-result.ts +0 -103
- package/src/bigint.ts +0 -111
- package/src/colors/cmyk.ts +0 -84
- package/src/colors/convert.ts +0 -1093
- package/src/colors/hsl.ts +0 -73
- package/src/colors/hsla.ts +0 -45
- package/src/colors/hsluv.ts +0 -73
- package/src/colors/hsv.ts +0 -75
- package/src/colors/lab.ts +0 -69
- package/src/colors/lch.ts +0 -53
- package/src/colors/luv.ts +0 -56
- package/src/colors/rgb.ts +0 -55
- package/src/colors/rgba.ts +0 -53
- package/src/colors/srgb.ts +0 -72
- package/src/colors/xyz.ts +0 -52
- package/src/edit.ts +0 -29
- package/src/equals.ts +0 -116
- package/src/functions.ts +0 -108
- package/src/json.ts +0 -52
- package/src/match.ts +0 -88
- package/src/memoize.ts +0 -9
- package/src/newtype.ts +0 -59
- package/src/numbers.ts +0 -222
- package/src/objects.ts +0 -47
- package/src/ord.ts +0 -79
- package/src/result.ts +0 -140
- package/src/strings.ts +0 -768
- package/src/types/assert.ts +0 -96
- package/src/types/differentiate.ts +0 -89
- package/src/types/functions.ts +0 -114
- package/src/types/generic.ts +0 -42
- package/src/types/objects.ts +0 -212
- package/src/types/tuples.ts +0 -244
- package/src/uuid.ts +0 -61
- package/src/validation.ts +0 -69
- package/test/arrays.spec.ts +0 -410
- package/test/colors.spec.ts +0 -406
- package/test/commmon.ts +0 -9
- package/test/equals.spec.ts +0 -165
- package/test/functions.spec.ts +0 -9
- package/test/index.d.ts +0 -20
- package/test/objects.spec.ts +0 -22
- package/test/reg-exps.spec.ts +0 -33
- package/test/strings.spec.ts +0 -333
- package/test/uuid.spec.ts +0 -35
- package/tsconfig.json +0 -19
package/src/objects.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type TupleToUnion } from './types/tuples'
|
|
2
|
-
import { type Merge } from './types/objects'
|
|
3
|
-
import { type AnyKey } from './types/utility'
|
|
4
|
-
|
|
5
|
-
export function keys<T extends object> (obj: T): Array<keyof T> {
|
|
6
|
-
return Object.keys(obj) as Array<keyof T>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function sameKeys<T extends object> (a: T, b: T): boolean {
|
|
10
|
-
const ak = keys(a)
|
|
11
|
-
const bk = keys(b)
|
|
12
|
-
if (ak.length !== bk.length) return false
|
|
13
|
-
for (const k of ak) {
|
|
14
|
-
if (!(k in b)) return false
|
|
15
|
-
}
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject (obj: unknown): obj is Record<AnyKey, unknown> {
|
|
20
|
-
return Object.prototype.toString.call(obj) === '[object Object]'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function removeFields<T extends object, F extends Array<keyof T>> (
|
|
24
|
-
ob: T,
|
|
25
|
-
...fields: F
|
|
26
|
-
): Omit<T, TupleToUnion<F>> {
|
|
27
|
-
const ks = keys(ob)
|
|
28
|
-
return ks.reduce((acc: Record<AnyKey, unknown>, key) => {
|
|
29
|
-
if (!fields.includes(key)) acc[key] = ob[key]
|
|
30
|
-
return acc
|
|
31
|
-
}, {}) as Omit<T, TupleToUnion<F>>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function merge<
|
|
35
|
-
A extends Record<AnyKey, unknown>,
|
|
36
|
-
B extends Record<AnyKey, unknown>
|
|
37
|
-
> (a: A, b: B): Merge<A, B> {
|
|
38
|
-
return Object.assign({}, a, b) as Merge<A, B>
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function isEmpty (obj: object): boolean {
|
|
42
|
-
return (
|
|
43
|
-
obj != null &&
|
|
44
|
-
Object.keys(obj).length === 0 &&
|
|
45
|
-
Object.getPrototypeOf(obj) === Object.prototype
|
|
46
|
-
)
|
|
47
|
-
}
|
package/src/ord.ts
DELETED
|
@@ -1,79 +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
|
-
export enum Ordering {
|
|
15
|
-
LT = -1,
|
|
16
|
-
EQ = 0,
|
|
17
|
-
GT = 1
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type CompareOrd<T> = (a: T, b: T) => Ordering
|
|
21
|
-
export type Compare<T> = (a: T, b: T) => number
|
|
22
|
-
|
|
23
|
-
export class Ord<T> {
|
|
24
|
-
static fromNumberComparison<T>(compare: (a: T, b: T) => number): Ord<T> {
|
|
25
|
-
return new Ord<T>(fromNumberComparison(compare))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor (readonly compare: CompareOrd<T>) {}
|
|
29
|
-
|
|
30
|
-
max (a: T, b: T): T {
|
|
31
|
-
switch (this.compare(a, b)) {
|
|
32
|
-
case Ordering.LT:
|
|
33
|
-
case Ordering.EQ:
|
|
34
|
-
return a
|
|
35
|
-
case Ordering.GT:
|
|
36
|
-
return b
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
min (a: T, b: T): T {
|
|
41
|
-
switch (this.compare(a, b)) {
|
|
42
|
-
case Ordering.GT:
|
|
43
|
-
case Ordering.EQ:
|
|
44
|
-
return a
|
|
45
|
-
case Ordering.LT:
|
|
46
|
-
return b
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
equals (a: T, b: T): boolean {
|
|
51
|
-
switch (this.compare(a, b)) {
|
|
52
|
-
case Ordering.EQ:
|
|
53
|
-
return true
|
|
54
|
-
default:
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
contramap<B>(f: (b: B) => T): Ord<B> {
|
|
60
|
-
return new Ord((b0: B, b1: B) => this.compare(f(b0), f(b1)))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
inverse (): Ord<T> {
|
|
64
|
-
return new Ord((a0: T, a1: T) => this.compare(a1, a0))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
numberComparison (a0: T, a1: T): number {
|
|
68
|
-
return this.compare(a0, a1)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function fromNumberComparison<A> (f: (a: A, b: A) => number) {
|
|
73
|
-
return function compare (a: A, b: A) {
|
|
74
|
-
const r = f(a, b)
|
|
75
|
-
if (r < 0) return Ordering.LT
|
|
76
|
-
else if (r === 0) return Ordering.EQ
|
|
77
|
-
else return Ordering.GT
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/result.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { type AsyncResult } from './async-result'
|
|
2
|
-
|
|
3
|
-
export interface Success<V> {
|
|
4
|
-
type: 'success'
|
|
5
|
-
value: V
|
|
6
|
-
}
|
|
7
|
-
export interface Failure<E> {
|
|
8
|
-
type: 'failure'
|
|
9
|
-
error: E
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type Result<V, E> = Success<V> | Failure<E>
|
|
13
|
-
|
|
14
|
-
export type PromiseResult<V, E> = PromiseLike<Result<V, E>>
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
17
|
-
export const Result = {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
success<V>(value: V): Result<V, any> {
|
|
20
|
-
return { type: 'success', value }
|
|
21
|
-
},
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
-
failure<E>(error: E): Result<any, E> {
|
|
24
|
-
return { type: 'failure', error }
|
|
25
|
-
},
|
|
26
|
-
cmap:
|
|
27
|
-
<V1, V2, E>(f: (value: V1) => V2) =>
|
|
28
|
-
(r: Result<V1, E>): Result<V2, E> => {
|
|
29
|
-
if (r.type === 'success') {
|
|
30
|
-
return Result.success(f(r.value))
|
|
31
|
-
} else {
|
|
32
|
-
return r
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
map: <V1, V2, E>(r: Result<V1, E>, f: (value: V1) => V2): Result<V2, E> => {
|
|
36
|
-
if (r.type === 'success') {
|
|
37
|
-
return Result.success(f(r.value))
|
|
38
|
-
} else {
|
|
39
|
-
return r
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
cflatMap:
|
|
43
|
-
<V1, V2, E>(f: (value: V1) => Result<V2, E>) =>
|
|
44
|
-
(r: Result<V1, E>): Result<V2, E> => {
|
|
45
|
-
if (r.type === 'success') {
|
|
46
|
-
return f(r.value)
|
|
47
|
-
} else {
|
|
48
|
-
return r
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
flatMap: <V1, V2, E>(
|
|
52
|
-
r: Result<V1, E>,
|
|
53
|
-
f: (value: V1) => Result<V2, E>
|
|
54
|
-
): Result<V2, E> => {
|
|
55
|
-
if (r.type === 'success') {
|
|
56
|
-
return f(r.value)
|
|
57
|
-
} else {
|
|
58
|
-
return r
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
toAsync<V, E>(r: Result<V, E>): AsyncResult<V, E> {
|
|
62
|
-
return r
|
|
63
|
-
},
|
|
64
|
-
isSuccess<V, E>(r: Result<V, E>): r is Success<V> {
|
|
65
|
-
return r.type === 'success'
|
|
66
|
-
},
|
|
67
|
-
isFailure<V, E>(r: Result<V, E>): r is Failure<E> {
|
|
68
|
-
return r.type === 'failure'
|
|
69
|
-
},
|
|
70
|
-
getOrElse<V, E>(r: Result<V, E>, alt: V): V {
|
|
71
|
-
return Result.isSuccess(r) ? r.value : alt
|
|
72
|
-
},
|
|
73
|
-
getOrElseLazy<V, E>(r: Result<V, E>, altf: () => V): V {
|
|
74
|
-
return Result.isSuccess(r) ? r.value : altf()
|
|
75
|
-
},
|
|
76
|
-
getOrNull<V, E>(r: Result<V, E>): V | null {
|
|
77
|
-
return Result.isSuccess(r) ? r.value : null
|
|
78
|
-
},
|
|
79
|
-
getOrUndefined<V, E>(r: Result<V, E>): V | undefined {
|
|
80
|
-
return Result.isSuccess(r) ? r.value : undefined
|
|
81
|
-
},
|
|
82
|
-
cmatch:
|
|
83
|
-
<V1, V2, E>(success: (value: V1) => V2, failure: (error: E) => V2) =>
|
|
84
|
-
(r: Result<V1, E>): V2 => {
|
|
85
|
-
if (Result.isSuccess(r)) {
|
|
86
|
-
return success(r.value)
|
|
87
|
-
} else {
|
|
88
|
-
return failure(r.error)
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
match: <V1, V2, E>(
|
|
92
|
-
r: Result<V1, E>,
|
|
93
|
-
success: (value: V1) => V2,
|
|
94
|
-
failure: (error: E) => V2
|
|
95
|
-
): V2 => {
|
|
96
|
-
if (Result.isSuccess(r)) {
|
|
97
|
-
return success(r.value)
|
|
98
|
-
} else {
|
|
99
|
-
return failure(r.error)
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
whenSuccess:
|
|
103
|
-
<V, E>(apply: (v: V) => void) =>
|
|
104
|
-
(r: Result<V, E>): Result<V, E> => {
|
|
105
|
-
if (Result.isSuccess(r)) {
|
|
106
|
-
apply(r.value)
|
|
107
|
-
}
|
|
108
|
-
return r
|
|
109
|
-
},
|
|
110
|
-
whenFailure:
|
|
111
|
-
<V, E>(apply: (e: E) => void) =>
|
|
112
|
-
(r: Result<V, E>): Result<V, E> => {
|
|
113
|
-
if (Result.isFailure(r)) {
|
|
114
|
-
apply(r.error)
|
|
115
|
-
}
|
|
116
|
-
return r
|
|
117
|
-
},
|
|
118
|
-
combine: <V, E>(
|
|
119
|
-
r1: Result<V, E>,
|
|
120
|
-
r2: Result<V, E>,
|
|
121
|
-
combineV: (v1: V, v2: V) => V,
|
|
122
|
-
combineE: (e1: E, e2: E) => E
|
|
123
|
-
): Result<V, E> =>
|
|
124
|
-
Result.match<V, Result<V, E>, E>(
|
|
125
|
-
r1,
|
|
126
|
-
(v1: V) =>
|
|
127
|
-
Result.match<V, Result<V, E>, E>(
|
|
128
|
-
r2,
|
|
129
|
-
(v2: V) => Result.success<V>(combineV(v1, v2)),
|
|
130
|
-
(e2: E) => Result.failure<E>(e2)
|
|
131
|
-
),
|
|
132
|
-
(e1: E) =>
|
|
133
|
-
Result.match<V, Result<V, E>, E>(
|
|
134
|
-
r2,
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
136
|
-
(_: V) => Result.failure<E>(e1),
|
|
137
|
-
(e2: E) => Result.failure<E>(combineE(e1, e2))
|
|
138
|
-
)
|
|
139
|
-
)
|
|
140
|
-
}
|