@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.
Files changed (82) hide show
  1. package/README.md +3 -0
  2. package/package.json +2 -2
  3. package/dist/arrays.d.ts +0 -49
  4. package/dist/arrays.js +0 -249
  5. package/dist/async-result.d.ts +0 -37
  6. package/dist/async-result.js +0 -75
  7. package/dist/bigint.d.ts +0 -18
  8. package/dist/bigint.js +0 -110
  9. package/dist/booleans.d.ts +0 -23
  10. package/dist/booleans.js +0 -68
  11. package/dist/colors/cmyk.d.ts +0 -21
  12. package/dist/colors/cmyk.js +0 -54
  13. package/dist/colors/convert.d.ts +0 -283
  14. package/dist/colors/convert.js +0 -742
  15. package/dist/colors/hsl.d.ts +0 -24
  16. package/dist/colors/hsl.js +0 -56
  17. package/dist/colors/hsla.d.ts +0 -18
  18. package/dist/colors/hsla.js +0 -35
  19. package/dist/colors/hsluv.d.ts +0 -24
  20. package/dist/colors/hsluv.js +0 -56
  21. package/dist/colors/hsv.d.ts +0 -24
  22. package/dist/colors/hsv.js +0 -54
  23. package/dist/colors/lab.d.ts +0 -24
  24. package/dist/colors/lab.js +0 -54
  25. package/dist/colors/lch.d.ts +0 -19
  26. package/dist/colors/lch.js +0 -44
  27. package/dist/colors/luv.d.ts +0 -19
  28. package/dist/colors/luv.js +0 -45
  29. package/dist/colors/rgb.d.ts +0 -13
  30. package/dist/colors/rgb.js +0 -47
  31. package/dist/colors/rgba.d.ts +0 -12
  32. package/dist/colors/rgba.js +0 -44
  33. package/dist/colors/srgb.d.ts +0 -24
  34. package/dist/colors/srgb.js +0 -51
  35. package/dist/colors/xyz.d.ts +0 -19
  36. package/dist/colors/xyz.js +0 -41
  37. package/dist/edit.d.ts +0 -20
  38. package/dist/edit.js +0 -29
  39. package/dist/equals.d.ts +0 -3
  40. package/dist/equals.js +0 -122
  41. package/dist/functions.d.ts +0 -20
  42. package/dist/functions.js +0 -38
  43. package/dist/json.d.ts +0 -14
  44. package/dist/json.js +0 -33
  45. package/dist/match.d.ts +0 -16
  46. package/dist/match.js +0 -45
  47. package/dist/maybe.d.ts +0 -9
  48. package/dist/maybe.js +0 -25
  49. package/dist/memoize.d.ts +0 -1
  50. package/dist/memoize.js +0 -9
  51. package/dist/newtype.d.ts +0 -28
  52. package/dist/newtype.js +0 -29
  53. package/dist/numbers.d.ts +0 -104
  54. package/dist/numbers.js +0 -183
  55. package/dist/objects.d.ts +0 -9
  56. package/dist/objects.js +0 -33
  57. package/dist/ord.d.ts +0 -19
  58. package/dist/ord.js +0 -73
  59. package/dist/reg-exps.d.ts +0 -10
  60. package/dist/reg-exps.js +0 -43
  61. package/dist/result.d.ts +0 -31
  62. package/dist/result.js +0 -95
  63. package/dist/strings.d.ts +0 -314
  64. package/dist/strings.js +0 -685
  65. package/dist/types/assert.d.ts +0 -12
  66. package/dist/types/assert.js +0 -13
  67. package/dist/types/differentiate.d.ts +0 -13
  68. package/dist/types/differentiate.js +0 -14
  69. package/dist/types/functions.d.ts +0 -22
  70. package/dist/types/functions.js +0 -13
  71. package/dist/types/generic.d.ts +0 -9
  72. package/dist/types/generic.js +0 -13
  73. package/dist/types/objects.d.ts +0 -50
  74. package/dist/types/objects.js +0 -13
  75. package/dist/types/tuples.d.ts +0 -44
  76. package/dist/types/tuples.js +0 -24
  77. package/dist/types/utility.d.ts +0 -2
  78. package/dist/types/utility.js +0 -1
  79. package/dist/uuid.d.ts +0 -13
  80. package/dist/uuid.js +0 -56
  81. package/dist/validation.d.ts +0 -23
  82. package/dist/validation.js +0 -44
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @tempots/std
2
+
3
+ A standard library for TypeScript.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@tempots/std",
3
- "version": "0.9.2",
3
+ "version": "0.9.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "watch": "tsc --watch",
7
7
  "build": "tsc",
8
8
  "test": "vitest",
9
- "publish": "npm publish --access public"
9
+ "publish": "(cp README.md package.json dist && cd dist && npm publish --access public)"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/node": "^18.15.11",
package/dist/arrays.d.ts DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Utility functions to manipulate `Array` values.
3
- */
4
- import { Maybe } from './maybe';
5
- import { type Ordering, type Compare } from './ord';
6
- import { type Primitive } from './types/utility';
7
- export declare function map<A, B>(arr: A[], f: (a: A, index: number) => B): B[];
8
- export declare function mapNotNull<A, B>(arr: A[], f: (a: A, index: number) => B | null | undefined): B[];
9
- export declare function flatMap<A, B>(arr: A[], f: (a: A) => B[]): B[];
10
- export declare function head<A>(arr: A[]): Maybe<A>;
11
- export declare function tail<A>(arr: A[]): A[];
12
- export declare function equals<T>(a: T[], b: T[], equality: (a: T, b: T) => boolean): boolean;
13
- export declare function makeEquals<T>(equality: (a: T, b: T) => boolean): (a: T[], b: T[]) => boolean;
14
- export declare function isEmpty<T>(arr: T[]): arr is [];
15
- export declare function hasValues<T>(arr: T[]): arr is [T, ...T[]];
16
- export declare function filter<T>(arr: T[], predicate: (v: T) => boolean): T[];
17
- export declare function filterNulls<T>(arr: Array<T | null | undefined>): T[];
18
- export declare function flatten<T>(arr: T[][]): T[];
19
- export declare function foldLeft<T, B>(arr: T[], f: (acc: B, curr: T) => B, b: B): B;
20
- export declare function all<T>(arr: T[], predicate: (v: T) => boolean): boolean;
21
- export declare function any<T>(arr: T[], predicate: (v: T) => boolean): boolean;
22
- export declare function each<T>(arr: T[], f: (v: T) => void): void;
23
- export declare function concat<A>(...arrs: A[][]): A[];
24
- export declare function makeCompare<A>(comparef: Compare<A>, shorterFirst?: boolean): (a: A[], b: A[]) => number;
25
- export declare function sort<A>(compare: (a: A, b: A) => Ordering, arr: A[]): A[];
26
- export declare function range<A>(length: number, f: (index: number) => A): A[];
27
- export declare function numbersRange(length: number, startAt?: number): number[];
28
- export declare function fill<A>(length: number, value: A): A[];
29
- export declare function distinctPrimitive<T extends Primitive>(values: T[]): T[];
30
- export declare function distinctByPredicate<T>(values: T[], predicate: (a: T) => string): T[];
31
- export declare function remove<A>(arr: A[], item: A, predicate?: (a: A) => boolean): boolean;
32
- export declare function ofIterableIterator<A>(it: IterableIterator<A>): A[];
33
- export interface DiffOperations<T> {
34
- removals: Array<{
35
- at: number;
36
- qt: number;
37
- }>;
38
- swaps: Array<{
39
- from: number;
40
- to: number;
41
- }>;
42
- inserts: Array<{
43
- at: number;
44
- values: T[];
45
- }>;
46
- }
47
- export declare function diffOperations<T, K>(from: T[], to: T[], getKey: (v: T) => K): DiffOperations<T>;
48
- export declare function applyOperations<T>(operations: DiffOperations<T>, start: T[]): T[];
49
- export declare function joinWithConjunction<A>(arr: A[], conjunction?: string, separator?: string): string;
package/dist/arrays.js DELETED
@@ -1,249 +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
- * Utility functions to manipulate `Array` values.
15
- */
16
- import { Maybe } from './maybe';
17
- import { keys } from './objects';
18
- export function map(arr, f) {
19
- return Array.from({ length: arr.length }, (_, i) => f(arr[i], i));
20
- }
21
- export function mapNotNull(arr, f) {
22
- const buff = [];
23
- for (let i = 0; i < arr.length; i++) {
24
- const v = f(arr[i], i);
25
- if (v != null) {
26
- buff.push(v);
27
- }
28
- }
29
- return buff;
30
- }
31
- export function flatMap(arr, f) {
32
- const buff = [];
33
- for (const el of arr) {
34
- buff.push(...f(el));
35
- }
36
- return buff;
37
- }
38
- export function head(arr) {
39
- return arr.length > 0 ? arr[0] : Maybe.nothing;
40
- }
41
- export function tail(arr) {
42
- return arr.slice(1);
43
- }
44
- export function equals(a, b, equality) {
45
- if (a.length !== b.length)
46
- return false;
47
- else {
48
- for (let i = 0; i < a.length; i++) {
49
- if (!equality(a[i], b[i]))
50
- return false;
51
- }
52
- return true;
53
- }
54
- }
55
- export function makeEquals(equality) {
56
- return function (a, b) {
57
- return equals(a, b, equality);
58
- };
59
- }
60
- export function isEmpty(arr) {
61
- return arr.length === 0;
62
- }
63
- export function hasValues(arr) {
64
- return arr.length > 0;
65
- }
66
- export function filter(arr, predicate) {
67
- const buff = [];
68
- for (const a of arr)
69
- if (predicate(a))
70
- buff.push(a);
71
- return buff;
72
- }
73
- export function filterNulls(arr) {
74
- return filter(arr, v => v != null);
75
- }
76
- export function flatten(arr) {
77
- return [].concat(...arr);
78
- }
79
- export function foldLeft(arr, f, b) {
80
- for (const a of arr) {
81
- b = f(b, a);
82
- }
83
- return b;
84
- }
85
- export function all(arr, predicate) {
86
- for (const a of arr) {
87
- if (!predicate(a)) {
88
- return false;
89
- }
90
- }
91
- return true;
92
- }
93
- export function any(arr, predicate) {
94
- for (const a of arr) {
95
- if (predicate(a)) {
96
- return true;
97
- }
98
- }
99
- return false;
100
- }
101
- export function each(arr, f) {
102
- for (const a of arr)
103
- f(a);
104
- }
105
- export function concat(...arrs) {
106
- return [].concat(...arrs);
107
- }
108
- export function makeCompare(comparef, shorterFirst = true) {
109
- return function (a, b) {
110
- if (a.length < b.length) {
111
- return -1 * (shorterFirst ? 1 : -1);
112
- }
113
- else if (a.length > b.length) {
114
- return 1 * (shorterFirst ? 1 : -1);
115
- }
116
- for (let i = 0; i < a.length; i++) {
117
- const ord = comparef(a[i], b[i]);
118
- if (ord !== 0)
119
- return ord;
120
- }
121
- return 0;
122
- };
123
- }
124
- export function sort(compare, arr) {
125
- return arr.slice().sort(compare);
126
- }
127
- export function range(length, f) {
128
- return Array.from({ length }, (_, i) => f(i));
129
- }
130
- export function numbersRange(length, startAt = 0) {
131
- return range(length, i => startAt + i);
132
- }
133
- export function fill(length, value) {
134
- return range(length, () => value);
135
- }
136
- export function distinctPrimitive(values) {
137
- return Array.from(new Set(values));
138
- }
139
- export function distinctByPredicate(values, predicate) {
140
- const map = {};
141
- values.forEach(v => {
142
- map[predicate(v)] = v;
143
- });
144
- return keys(map).map(k => map[k]);
145
- }
146
- export function remove(arr, item, predicate) {
147
- let index;
148
- if (predicate !== undefined) {
149
- index = arr.findIndex(predicate);
150
- }
151
- else {
152
- index = arr.indexOf(item);
153
- }
154
- if (index < 0) {
155
- return false;
156
- }
157
- else {
158
- arr.splice(index, 1);
159
- return true;
160
- }
161
- }
162
- export function ofIterableIterator(it) {
163
- const buff = [];
164
- for (let r = it.next(); !(r.done ?? false); r = it.next()) {
165
- buff.push(r.value);
166
- }
167
- return buff;
168
- }
169
- export function diffOperations(from, to, getKey) {
170
- const ops = {
171
- removals: [],
172
- swaps: [],
173
- inserts: []
174
- };
175
- const { removals, inserts, swaps } = ops;
176
- const mapB = new Map();
177
- to.forEach((v, i) => mapB.set(getKey(v), i));
178
- const indexesOfAThatDoNotExistInB = from
179
- .map((v, i) => [v, i])
180
- .filter(([v]) => !mapB.has(getKey(v)))
181
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
182
- .map(([_, i]) => i);
183
- for (let i = indexesOfAThatDoNotExistInB.length - 1; i >= 0; i--) {
184
- const p = indexesOfAThatDoNotExistInB[i];
185
- const last = removals.length > 0 ? removals[removals.length - 1] : undefined;
186
- if ((last != null) && last.at === p + 1) {
187
- last.at--;
188
- last.qt++;
189
- }
190
- else {
191
- removals.push({ at: p, qt: 1 });
192
- }
193
- }
194
- const mapA = new Map();
195
- from.forEach((v, i) => mapA.set(getKey(v), i));
196
- const indexesOfBThatDoNotExistInA = to
197
- .map((v, i) => [v, i])
198
- .filter(([v]) => !mapA.has(getKey(v)))
199
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
200
- .map(([_, i]) => i);
201
- for (const p of indexesOfBThatDoNotExistInA) {
202
- const last = inserts.length > 0 ? inserts[inserts.length - 1] : undefined;
203
- if ((last != null) && last.at + last.values.length === p) {
204
- last.values.push(to[p]);
205
- }
206
- else {
207
- inserts.push({ at: p, values: [to[p]] });
208
- }
209
- }
210
- const ra = from.filter((_, i) => !indexesOfAThatDoNotExistInB.includes(i));
211
- const mapRA = new Map();
212
- for (let i = 0; i < ra.length; i++) {
213
- mapRA.set(getKey(ra[i]), i);
214
- }
215
- const rb = to.filter((_, i) => !indexesOfBThatDoNotExistInA.includes(i));
216
- for (let i = 0; i < rb.length; i++) {
217
- const bk = getKey(rb[i]);
218
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
219
- const ai = mapRA.get(bk);
220
- if (ai == null || i === ai)
221
- continue;
222
- const ak = getKey(ra[i]);
223
- mapRA.delete(ak);
224
- swaps.push({ from: i, to: ai });
225
- }
226
- return ops;
227
- }
228
- export function applyOperations(operations, start) {
229
- const buff = [...start];
230
- for (const { at, qt } of operations.removals) {
231
- buff.splice(at, qt);
232
- }
233
- for (const { from, to } of operations.swaps) {
234
- const t = buff[to];
235
- buff[to] = buff[from];
236
- buff[from] = t;
237
- }
238
- for (const op of operations.inserts) {
239
- buff.splice(op.at, 0, ...op.values);
240
- }
241
- return buff;
242
- }
243
- export function joinWithConjunction(arr, conjunction = ' and ', separator = ', ') {
244
- if (arr.length === 0)
245
- return '';
246
- if (arr.length === 1)
247
- return String(arr[0]);
248
- return `${arr.slice(0, -1).join(separator)}${conjunction}${String(arr[arr.length - 1])}`;
249
- }
@@ -1,37 +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
- export type AsyncResult<V, E> = Idle | Loading | Success<V> | Failure<E>;
16
- export declare const AsyncResult: {
17
- idle: {
18
- type: "idle";
19
- };
20
- loading: {
21
- type: "loading";
22
- };
23
- success<V>(value: V): AsyncResult<V, never>;
24
- failure<E>(error: E): AsyncResult<never, E>;
25
- isSuccess<V_1, E_1>(r: AsyncResult<V_1, E_1>): r is Success<V_1>;
26
- isFailure<V_2, E_2>(r: AsyncResult<V_2, E_2>): r is Failure<E_2>;
27
- isIdle<V_3, E_3>(r: AsyncResult<V_3, E_3>): r is Idle;
28
- isLoading<V_4, E_4>(r: AsyncResult<V_4, E_4>): r is Loading;
29
- getOrElse<V_5, E_5>(r: AsyncResult<V_5, E_5>, alt: V_5): V_5;
30
- getOrElseLazy<V_6, E_6>(r: AsyncResult<V_6, E_6>, altf: () => V_6): V_6;
31
- getOrNull<V_7, E_7>(r: AsyncResult<V_7, E_7>): V_7 | null;
32
- getOrUndefined<V_8, E_8>(r: AsyncResult<V_8, E_8>): V_8 | undefined;
33
- cmatch: <V1, V2, E_9>(success: (value: V1) => V2, failure: (error: E_9) => V2, loading: () => V2, idle?: () => V2) => (r: AsyncResult<V1, E_9>) => V2;
34
- match: <V1_1, V2_1, E_10>(r: AsyncResult<V1_1, E_10>, success: (value: V1_1) => V2_1, failure: (error: E_10) => V2_1, loading: () => V2_1, idle?: () => V2_1) => V2_1;
35
- whenSuccess: <V_9, E_11>(apply: (v: V_9) => void) => (r: AsyncResult<V_9, E_11>) => AsyncResult<V_9, E_11>;
36
- whenFailure: <V_10, E_12>(apply: (e: E_12) => void) => (r: AsyncResult<V_10, E_12>) => AsyncResult<V_10, E_12>;
37
- };
@@ -1,75 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-redeclare
2
- export const AsyncResult = {
3
- idle: { type: 'idle' },
4
- loading: { type: 'loading' },
5
- success(value) {
6
- return { type: 'success', value };
7
- },
8
- failure(error) {
9
- return { type: 'failure', error };
10
- },
11
- isSuccess(r) {
12
- return r.type === 'success';
13
- },
14
- isFailure(r) {
15
- return r.type === 'failure';
16
- },
17
- isIdle(r) {
18
- return r.type === 'idle';
19
- },
20
- isLoading(r) {
21
- return r.type === 'loading';
22
- },
23
- getOrElse(r, alt) {
24
- return AsyncResult.isSuccess(r) ? r.value : alt;
25
- },
26
- getOrElseLazy(r, altf) {
27
- return AsyncResult.isSuccess(r) ? r.value : altf();
28
- },
29
- getOrNull(r) {
30
- return AsyncResult.isSuccess(r) ? r.value : null;
31
- },
32
- getOrUndefined(r) {
33
- return AsyncResult.isSuccess(r) ? r.value : undefined;
34
- },
35
- cmatch: (success, failure, loading, idle = loading) => (r) => {
36
- if (AsyncResult.isSuccess(r)) {
37
- return success(r.value);
38
- }
39
- else if (AsyncResult.isFailure(r)) {
40
- return failure(r.error);
41
- }
42
- else if (AsyncResult.isIdle(r)) {
43
- return idle();
44
- }
45
- else {
46
- return loading();
47
- }
48
- },
49
- match: (r, success, failure, loading, idle = loading) => {
50
- if (AsyncResult.isSuccess(r)) {
51
- return success(r.value);
52
- }
53
- else if (AsyncResult.isFailure(r)) {
54
- return failure(r.error);
55
- }
56
- else if (AsyncResult.isIdle(r)) {
57
- return idle();
58
- }
59
- else {
60
- return loading();
61
- }
62
- },
63
- whenSuccess: (apply) => (r) => {
64
- if (AsyncResult.isSuccess(r)) {
65
- apply(r.value);
66
- }
67
- return r;
68
- },
69
- whenFailure: (apply) => (r) => {
70
- if (AsyncResult.isFailure(r)) {
71
- apply(r.error);
72
- }
73
- return r;
74
- }
75
- };
package/dist/bigint.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export declare function ceilDiv(x: bigint, y: bigint): bigint;
2
- export declare function floorDiv(x: bigint, y: bigint): bigint;
3
- export declare function compare(x: bigint, y: bigint): number;
4
- export declare function abs(x: bigint): bigint;
5
- export declare function min(x: bigint, y: bigint): bigint;
6
- export declare function max(x: bigint, y: bigint): bigint;
7
- export declare function pow(x: bigint, y: bigint): bigint;
8
- export declare function gcd(x: bigint, y: bigint): bigint;
9
- export declare function lcm(x: bigint, y: bigint): bigint;
10
- export declare function isPrime(x: bigint): boolean;
11
- export declare function nextPrime(x: bigint): bigint;
12
- export declare function prevPrime(x: bigint): bigint;
13
- export declare function isEven(x: bigint): boolean;
14
- export declare function isOdd(x: bigint): boolean;
15
- export declare function isZero(x: bigint): boolean;
16
- export declare function isOne(x: bigint): boolean;
17
- export declare function isNegative(x: bigint): boolean;
18
- export declare function isPositive(x: bigint): boolean;
package/dist/bigint.js DELETED
@@ -1,110 +0,0 @@
1
- export function ceilDiv(x, y) {
2
- if (y < 0n) {
3
- x = -x;
4
- y = -y;
5
- }
6
- return x <= 0n ? x / y : (x - 1n) / y + 1n;
7
- }
8
- export function floorDiv(x, y) {
9
- if (y < 0n) {
10
- x = -x;
11
- y = -y;
12
- }
13
- return x >= 0n ? x / y : (x + 1n) / y - 1n;
14
- }
15
- export function compare(x, y) {
16
- return x < y ? -1 : x > y ? 1 : 0;
17
- }
18
- export function abs(x) {
19
- return x < 0n ? -x : x;
20
- }
21
- export function min(x, y) {
22
- return x < y ? x : y;
23
- }
24
- export function max(x, y) {
25
- return x > y ? x : y;
26
- }
27
- export function pow(x, y) {
28
- if (y < 0n)
29
- throw new Error('negative exponent');
30
- let result = 1n;
31
- while (y > 0n) {
32
- if ((y & 1n) !== 0n)
33
- result *= x;
34
- y >>= 1n;
35
- x *= x;
36
- }
37
- return result;
38
- }
39
- export function gcd(x, y) {
40
- x = abs(x);
41
- y = abs(y);
42
- while (y > 0n) {
43
- const t = y;
44
- y = x % y;
45
- x = t;
46
- }
47
- return x;
48
- }
49
- export function lcm(x, y) {
50
- return abs(x * y) / gcd(x, y);
51
- }
52
- export function isPrime(x) {
53
- if (x < 2n)
54
- return false;
55
- if (x === 2n || x === 3n)
56
- return true;
57
- if (x % 2n === 0n || x % 3n === 0n)
58
- return false;
59
- let i = 5n;
60
- while (i * i <= x) {
61
- if (x % i === 0n || x % (i + 2n) === 0n)
62
- return false;
63
- i += 6n;
64
- }
65
- return true;
66
- }
67
- export function nextPrime(x) {
68
- if (x < 2n)
69
- return 2n;
70
- if (x === 2n)
71
- return 3n;
72
- if (x % 2n === 0n)
73
- x++;
74
- else
75
- x += 2n;
76
- while (!isPrime(x))
77
- x += 2n;
78
- return x;
79
- }
80
- export function prevPrime(x) {
81
- if (x <= 2n)
82
- throw new Error('no previous prime');
83
- if (x === 3n)
84
- return 2n;
85
- if (x % 2n === 0n)
86
- x--;
87
- else
88
- x -= 2n;
89
- while (!isPrime(x))
90
- x -= 2n;
91
- return x;
92
- }
93
- export function isEven(x) {
94
- return x % 2n === 0n;
95
- }
96
- export function isOdd(x) {
97
- return x % 2n !== 0n;
98
- }
99
- export function isZero(x) {
100
- return x === 0n;
101
- }
102
- export function isOne(x) {
103
- return x === 1n;
104
- }
105
- export function isNegative(x) {
106
- return x < 0n;
107
- }
108
- export function isPositive(x) {
109
- return x > 0n;
110
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Utility functions to manipulate `boolean` values.
3
- */
4
- /**
5
- * Returns a comparison value (`Int`) from two boolean values.
6
- */
7
- export declare function compare(a: boolean, b: boolean): number;
8
- /**
9
- * Converts a boolean to an integer value (`true` => `1`, `false` => `0`).
10
- */
11
- export declare function toInt(v: boolean): number;
12
- /**
13
- * Returns `true` if the passed value is either `true` or `false` (case insensitive).
14
- */
15
- export declare function canParse(v: string): boolean;
16
- /**
17
- * Returns `true`/`false` if the passed value is `true`/`false` (case insensitive) with any other value it will return null.
18
- */
19
- export declare function parse(v: string): boolean;
20
- /**
21
- * Returns `true` when arguments are different.
22
- */
23
- export declare function xor(a: boolean, b: boolean): boolean;
package/dist/booleans.js DELETED
@@ -1,68 +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
- * Utility functions to manipulate `boolean` values.
15
- */
16
- /**
17
- * Returns a comparison value (`Int`) from two boolean values.
18
- */
19
- export function compare(a, b) {
20
- return a === b ? 0 : a ? -1 : 1;
21
- }
22
- /**
23
- * Converts a boolean to an integer value (`true` => `1`, `false` => `0`).
24
- */
25
- export function toInt(v) {
26
- return v ? 1 : 0;
27
- }
28
- /**
29
- * Returns `true` if the passed value is either `true` or `false` (case insensitive).
30
- */
31
- export function canParse(v) {
32
- if (v == null)
33
- return false;
34
- switch (v.toLowerCase()) {
35
- case 'true':
36
- case 'false':
37
- case '0':
38
- case '1':
39
- case 'on':
40
- case 'off':
41
- return true;
42
- default:
43
- return false;
44
- }
45
- }
46
- /**
47
- * Returns `true`/`false` if the passed value is `true`/`false` (case insensitive) with any other value it will return null.
48
- */
49
- export function parse(v) {
50
- switch (v.toLowerCase()) {
51
- case 'true':
52
- case '1':
53
- case 'on':
54
- return true;
55
- case 'false':
56
- case '0':
57
- case 'off':
58
- return false;
59
- default:
60
- throw new Error(`unable to parse '${v}'`);
61
- }
62
- }
63
- /**
64
- * Returns `true` when arguments are different.
65
- */
66
- export function xor(a, b) {
67
- return a !== b;
68
- }
@@ -1,21 +0,0 @@
1
- export declare class CMYK {
2
- static fromString(s: string): CMYK;
3
- static ofChannels([cyan, magenta, yellow, black]: [
4
- cyan: number,
5
- magenta: number,
6
- yellow: number,
7
- black: number
8
- ]): CMYK;
9
- readonly cyan: number;
10
- readonly magenta: number;
11
- readonly yellow: number;
12
- readonly black: number;
13
- constructor(cyan: number, magenta: number, yellow: number, black: number);
14
- withCyan(cyan: number): CMYK;
15
- withMagenta(magenta: number): CMYK;
16
- withYellow(yellow: number): CMYK;
17
- withBlack(black: number): CMYK;
18
- toChannels(): [number, number, number, number];
19
- toString(): string;
20
- equals(other: CMYK, tollerance?: number): boolean;
21
- }