@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/async-result.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
export interface Idle {
|
|
2
|
-
type: 'idle'
|
|
3
|
-
}
|
|
4
|
-
export interface Loading {
|
|
5
|
-
type: 'loading'
|
|
6
|
-
}
|
|
7
|
-
export interface Success<V> {
|
|
8
|
-
type: 'success'
|
|
9
|
-
value: V
|
|
10
|
-
}
|
|
11
|
-
export interface Failure<E> {
|
|
12
|
-
type: 'failure'
|
|
13
|
-
error: E
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type AsyncResult<V, E> = Idle | Loading | Success<V> | Failure<E>
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
19
|
-
export const AsyncResult = {
|
|
20
|
-
idle: { type: 'idle' } satisfies AsyncResult<never, never>,
|
|
21
|
-
loading: { type: 'loading' } satisfies AsyncResult<never, never>,
|
|
22
|
-
success<V>(value: V): AsyncResult<V, never> {
|
|
23
|
-
return { type: 'success', value }
|
|
24
|
-
},
|
|
25
|
-
failure<E>(error: E): AsyncResult<never, E> {
|
|
26
|
-
return { type: 'failure', error }
|
|
27
|
-
},
|
|
28
|
-
isSuccess<V, E>(r: AsyncResult<V, E>): r is Success<V> {
|
|
29
|
-
return r.type === 'success'
|
|
30
|
-
},
|
|
31
|
-
isFailure<V, E>(r: AsyncResult<V, E>): r is Failure<E> {
|
|
32
|
-
return r.type === 'failure'
|
|
33
|
-
},
|
|
34
|
-
isIdle<V, E>(r: AsyncResult<V, E>): r is Idle {
|
|
35
|
-
return r.type === 'idle'
|
|
36
|
-
},
|
|
37
|
-
isLoading<V, E>(r: AsyncResult<V, E>): r is Loading {
|
|
38
|
-
return r.type === 'loading'
|
|
39
|
-
},
|
|
40
|
-
getOrElse<V, E>(r: AsyncResult<V, E>, alt: V): V {
|
|
41
|
-
return AsyncResult.isSuccess(r) ? r.value : alt
|
|
42
|
-
},
|
|
43
|
-
getOrElseLazy<V, E>(r: AsyncResult<V, E>, altf: () => V): V {
|
|
44
|
-
return AsyncResult.isSuccess(r) ? r.value : altf()
|
|
45
|
-
},
|
|
46
|
-
getOrNull<V, E>(r: AsyncResult<V, E>): V | null {
|
|
47
|
-
return AsyncResult.isSuccess(r) ? r.value : null
|
|
48
|
-
},
|
|
49
|
-
getOrUndefined<V, E>(r: AsyncResult<V, E>): V | undefined {
|
|
50
|
-
return AsyncResult.isSuccess(r) ? r.value : undefined
|
|
51
|
-
},
|
|
52
|
-
cmatch:
|
|
53
|
-
<V1, V2, E>(
|
|
54
|
-
success: (value: V1) => V2,
|
|
55
|
-
failure: (error: E) => V2,
|
|
56
|
-
loading: () => V2,
|
|
57
|
-
idle: () => V2 = loading
|
|
58
|
-
) =>
|
|
59
|
-
(r: AsyncResult<V1, E>): V2 => {
|
|
60
|
-
if (AsyncResult.isSuccess(r)) {
|
|
61
|
-
return success(r.value)
|
|
62
|
-
} else if (AsyncResult.isFailure(r)) {
|
|
63
|
-
return failure(r.error)
|
|
64
|
-
} else if (AsyncResult.isIdle(r)) {
|
|
65
|
-
return idle()
|
|
66
|
-
} else {
|
|
67
|
-
return loading()
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
match: <V1, V2, E>(
|
|
71
|
-
r: AsyncResult<V1, E>,
|
|
72
|
-
success: (value: V1) => V2,
|
|
73
|
-
failure: (error: E) => V2,
|
|
74
|
-
loading: () => V2,
|
|
75
|
-
idle: () => V2 = loading
|
|
76
|
-
): V2 => {
|
|
77
|
-
if (AsyncResult.isSuccess(r)) {
|
|
78
|
-
return success(r.value)
|
|
79
|
-
} else if (AsyncResult.isFailure(r)) {
|
|
80
|
-
return failure(r.error)
|
|
81
|
-
} else if (AsyncResult.isIdle(r)) {
|
|
82
|
-
return idle()
|
|
83
|
-
} else {
|
|
84
|
-
return loading()
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
whenSuccess:
|
|
88
|
-
<V, E>(apply: (v: V) => void) =>
|
|
89
|
-
(r: AsyncResult<V, E>): AsyncResult<V, E> => {
|
|
90
|
-
if (AsyncResult.isSuccess(r)) {
|
|
91
|
-
apply(r.value)
|
|
92
|
-
}
|
|
93
|
-
return r
|
|
94
|
-
},
|
|
95
|
-
whenFailure:
|
|
96
|
-
<V, E>(apply: (e: E) => void) =>
|
|
97
|
-
(r: AsyncResult<V, E>): AsyncResult<V, E> => {
|
|
98
|
-
if (AsyncResult.isFailure(r)) {
|
|
99
|
-
apply(r.error)
|
|
100
|
-
}
|
|
101
|
-
return r
|
|
102
|
-
}
|
|
103
|
-
}
|
package/src/bigint.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export function ceilDiv (x: bigint, y: bigint): bigint {
|
|
2
|
-
if (y < 0n) {
|
|
3
|
-
x = -x
|
|
4
|
-
y = -y
|
|
5
|
-
}
|
|
6
|
-
return x <= 0n ? x / y : (x - 1n) / y + 1n
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function floorDiv (x: bigint, y: bigint): bigint {
|
|
10
|
-
if (y < 0n) {
|
|
11
|
-
x = -x
|
|
12
|
-
y = -y
|
|
13
|
-
}
|
|
14
|
-
return x >= 0n ? x / y : (x + 1n) / y - 1n
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function compare (x: bigint, y: bigint): number {
|
|
18
|
-
return x < y ? -1 : x > y ? 1 : 0
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function abs (x: bigint): bigint {
|
|
22
|
-
return x < 0n ? -x : x
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function min (x: bigint, y: bigint): bigint {
|
|
26
|
-
return x < y ? x : y
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function max (x: bigint, y: bigint): bigint {
|
|
30
|
-
return x > y ? x : y
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function pow (x: bigint, y: bigint): bigint {
|
|
34
|
-
if (y < 0n) throw new Error('negative exponent')
|
|
35
|
-
let result = 1n
|
|
36
|
-
while (y > 0n) {
|
|
37
|
-
if ((y & 1n) !== 0n) result *= x
|
|
38
|
-
y >>= 1n
|
|
39
|
-
x *= x
|
|
40
|
-
}
|
|
41
|
-
return result
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function gcd (x: bigint, y: bigint): bigint {
|
|
45
|
-
x = abs(x)
|
|
46
|
-
y = abs(y)
|
|
47
|
-
while (y > 0n) {
|
|
48
|
-
const t = y
|
|
49
|
-
y = x % y
|
|
50
|
-
x = t
|
|
51
|
-
}
|
|
52
|
-
return x
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function lcm (x: bigint, y: bigint): bigint {
|
|
56
|
-
return abs(x * y) / gcd(x, y)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function isPrime (x: bigint): boolean {
|
|
60
|
-
if (x < 2n) return false
|
|
61
|
-
if (x === 2n || x === 3n) return true
|
|
62
|
-
if (x % 2n === 0n || x % 3n === 0n) return false
|
|
63
|
-
let i = 5n
|
|
64
|
-
while (i * i <= x) {
|
|
65
|
-
if (x % i === 0n || x % (i + 2n) === 0n) return false
|
|
66
|
-
i += 6n
|
|
67
|
-
}
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function nextPrime (x: bigint): bigint {
|
|
72
|
-
if (x < 2n) return 2n
|
|
73
|
-
if (x === 2n) return 3n
|
|
74
|
-
if (x % 2n === 0n) x++
|
|
75
|
-
else x += 2n
|
|
76
|
-
while (!isPrime(x)) x += 2n
|
|
77
|
-
return x
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function prevPrime (x: bigint): bigint {
|
|
81
|
-
if (x <= 2n) throw new Error('no previous prime')
|
|
82
|
-
if (x === 3n) return 2n
|
|
83
|
-
if (x % 2n === 0n) x--
|
|
84
|
-
else x -= 2n
|
|
85
|
-
while (!isPrime(x)) x -= 2n
|
|
86
|
-
return x
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function isEven (x: bigint): boolean {
|
|
90
|
-
return x % 2n === 0n
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function isOdd (x: bigint): boolean {
|
|
94
|
-
return x % 2n !== 0n
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function isZero (x: bigint): boolean {
|
|
98
|
-
return x === 0n
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function isOne (x: bigint): boolean {
|
|
102
|
-
return x === 1n
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function isNegative (x: bigint): boolean {
|
|
106
|
-
return x < 0n
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function isPositive (x: bigint): boolean {
|
|
110
|
-
return x > 0n
|
|
111
|
-
}
|
package/src/colors/cmyk.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class CMYK {
|
|
6
|
-
static fromString (s: string): CMYK {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^cmyk\((\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%\)$/
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, cyan, magenta, y, k] = m
|
|
12
|
-
return new CMYK(
|
|
13
|
-
parseFloat(cyan),
|
|
14
|
-
parseFloat(magenta),
|
|
15
|
-
parseFloat(y),
|
|
16
|
-
parseFloat(k)
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
throw new Error(`Invalid CMYK string: ${s}`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static ofChannels ([cyan, magenta, yellow, black]: [
|
|
23
|
-
cyan: number,
|
|
24
|
-
magenta: number,
|
|
25
|
-
yellow: number,
|
|
26
|
-
black: number
|
|
27
|
-
]): CMYK {
|
|
28
|
-
return new CMYK(
|
|
29
|
-
clamp(cyan * 100, 0, 100),
|
|
30
|
-
clamp(magenta * 100, 0, 100),
|
|
31
|
-
clamp(yellow * 100, 0, 100),
|
|
32
|
-
clamp(black * 100, 0, 100)
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
readonly cyan: number
|
|
37
|
-
readonly magenta: number
|
|
38
|
-
readonly yellow: number
|
|
39
|
-
readonly black: number
|
|
40
|
-
constructor (cyan: number, magenta: number, yellow: number, black: number) {
|
|
41
|
-
this.cyan = clamp(cyan, 0, 100)
|
|
42
|
-
this.magenta = clamp(magenta, 0, 100)
|
|
43
|
-
this.yellow = clamp(yellow, 0, 100)
|
|
44
|
-
this.black = clamp(black, 0, 100)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
withCyan (cyan: number): CMYK {
|
|
48
|
-
return new CMYK(cyan, this.magenta, this.yellow, this.black)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
withMagenta (magenta: number): CMYK {
|
|
52
|
-
return new CMYK(this.cyan, magenta, this.yellow, this.black)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
withYellow (yellow: number): CMYK {
|
|
56
|
-
return new CMYK(this.cyan, this.magenta, yellow, this.black)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
withBlack (black: number): CMYK {
|
|
60
|
-
return new CMYK(this.cyan, this.magenta, this.yellow, black)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
toChannels (): [number, number, number, number] {
|
|
64
|
-
return [
|
|
65
|
-
this.cyan / 100,
|
|
66
|
-
this.magenta / 100,
|
|
67
|
-
this.yellow / 100,
|
|
68
|
-
this.black / 100
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
toString (): string {
|
|
73
|
-
return `cmyk(${this.cyan}%, ${this.magenta}%, ${this.yellow}%, ${this.black}%)`
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
equals (other: CMYK, tollerance = TOLLERANCE): boolean {
|
|
77
|
-
return (
|
|
78
|
-
nearEquals(this.cyan, other.cyan, tollerance) &&
|
|
79
|
-
nearEquals(this.magenta, other.magenta, tollerance) &&
|
|
80
|
-
nearEquals(this.yellow, other.yellow, tollerance) &&
|
|
81
|
-
nearEquals(this.black, other.black, tollerance)
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
}
|