@cto.af/utils 1.4.2 → 2.0.1
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/lib/{index.d.mts → index.d.ts} +39 -31
- package/lib/index.js +182 -0
- package/lib/{u8.d.mts → u8.d.ts} +1 -3
- package/lib/u8.js +20 -0
- package/lib/{u8Impl.d.mts → u8Impl.d.ts} +3 -6
- package/lib/u8Impl.js +33 -0
- package/package.json +6 -11
- package/lib/index.mjs +0 -1
- package/lib/u8.mjs +0 -1
- package/lib/u8Impl.mjs +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
toString(): string;
|
|
1
|
+
export declare class AssertionError extends Error {
|
|
2
|
+
constructor(actual: unknown, expected: unknown, message?: string);
|
|
3
|
+
toString(): string;
|
|
5
4
|
}
|
|
6
5
|
/**
|
|
7
6
|
* Very simplified assert, which will work in the browser.
|
|
@@ -10,13 +9,15 @@ declare class AssertionError extends Error {
|
|
|
10
9
|
* @param message Optional message.
|
|
11
10
|
* @throws {AssertionError} If value is falsy.
|
|
12
11
|
*/
|
|
13
|
-
declare function assert(value: unknown, message?: string): asserts value;
|
|
14
|
-
type Pretty<T> = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
export declare function assert(value: unknown, message?: string): asserts value;
|
|
13
|
+
export type Pretty<T> = {
|
|
14
|
+
[K in keyof T]: T[K];
|
|
15
|
+
} & {};
|
|
16
|
+
export interface ErrnoException extends Error {
|
|
17
|
+
errno?: number | undefined;
|
|
18
|
+
code?: string | undefined;
|
|
19
|
+
path?: string | undefined;
|
|
20
|
+
syscall?: string | undefined;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Is the object an ErrnoException?
|
|
@@ -24,7 +25,7 @@ interface ErrnoException extends Error {
|
|
|
24
25
|
* @param e Object to check.
|
|
25
26
|
* @returns Type assertion.
|
|
26
27
|
*/
|
|
27
|
-
declare function isErrno(e: unknown): e is ErrnoException;
|
|
28
|
+
export declare function isErrno(e: unknown): e is ErrnoException;
|
|
28
29
|
/**
|
|
29
30
|
* Does the error contain a specific code?
|
|
30
31
|
*
|
|
@@ -33,9 +34,9 @@ declare function isErrno(e: unknown): e is ErrnoException;
|
|
|
33
34
|
* @returns True if code matches.
|
|
34
35
|
* @throws {TypeError} On invalid code type.
|
|
35
36
|
*/
|
|
36
|
-
declare function errCode(e: unknown, code: string | number): boolean;
|
|
37
|
-
interface CiOptions {
|
|
38
|
-
|
|
37
|
+
export declare function errCode(e: unknown, code: string | number): boolean;
|
|
38
|
+
export interface CiOptions {
|
|
39
|
+
CI?: boolean;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Is the current environment CI-like.
|
|
@@ -43,11 +44,11 @@ interface CiOptions {
|
|
|
43
44
|
* @param opts Override the environment determination, for testing.
|
|
44
45
|
* @returns True if in CI.
|
|
45
46
|
*/
|
|
46
|
-
declare function isCI(opts?: CiOptions): boolean;
|
|
47
|
-
interface PromiseWithResolvers<T> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
export declare function isCI(opts?: CiOptions): boolean;
|
|
48
|
+
export interface PromiseWithResolvers<T> {
|
|
49
|
+
promise: Promise<T>;
|
|
50
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
51
|
+
reject(reason?: any): void;
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Polyfill for Promise.withResolvers. Once node 22 is the minimum version,
|
|
@@ -58,7 +59,7 @@ interface PromiseWithResolvers<T> {
|
|
|
58
59
|
* resolve or reject it, corresponding to the two parameters passed to the
|
|
59
60
|
* executor of the Promise() constructor.
|
|
60
61
|
*/
|
|
61
|
-
declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
|
|
62
|
+
export declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
|
|
62
63
|
/**
|
|
63
64
|
* Get the names of the keys of an options type, from the defaults.
|
|
64
65
|
*
|
|
@@ -66,7 +67,7 @@ declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
|
|
|
66
67
|
* @param defaults Default values for the options.
|
|
67
68
|
* @returns List of keys of the given object.
|
|
68
69
|
*/
|
|
69
|
-
declare function nameSet<T extends object>(defaults: T): Set<keyof T>;
|
|
70
|
+
export declare function nameSet<T extends object>(defaults: T): Set<keyof T>;
|
|
70
71
|
/**
|
|
71
72
|
* Assert that none of the given sets of strings share a value.
|
|
72
73
|
* Useful for validating inputs to select.
|
|
@@ -74,14 +75,14 @@ declare function nameSet<T extends object>(defaults: T): Set<keyof T>;
|
|
|
74
75
|
* @param sets Sets to check.
|
|
75
76
|
* @throws {AssertionError} If sets are the wrong type.
|
|
76
77
|
*/
|
|
77
|
-
declare function assertDisjoint(...sets: (Set<string> | string[] | object)[]): void;
|
|
78
|
+
export declare function assertDisjoint(...sets: (Set<string> | string[] | object)[]): void;
|
|
78
79
|
/**
|
|
79
80
|
* Select with a defaults object, a list of keys, or a set of keys. The
|
|
80
81
|
* set of keys might perform better, but we can't extract types from it.
|
|
81
82
|
*
|
|
82
83
|
* @template T Options object, where most properties are optional.
|
|
83
84
|
*/
|
|
84
|
-
type Selector<T extends object> = Partial<T> | (keyof T)[] | Set<keyof T>;
|
|
85
|
+
export type Selector<T extends object> = Partial<T> | (keyof T)[] | Set<keyof T>;
|
|
85
86
|
/**
|
|
86
87
|
* A defaults object extracts a required subset of T.
|
|
87
88
|
* A list of keys extracts a partial subset of T with those possible keys.
|
|
@@ -90,14 +91,14 @@ type Selector<T extends object> = Partial<T> | (keyof T)[] | Set<keyof T>;
|
|
|
90
91
|
* @template T Options object, where most properties are optional.
|
|
91
92
|
* @template U Selector.
|
|
92
93
|
*/
|
|
93
|
-
type Selected<T extends object, U extends Selector<T>> = U extends Partial<T> ? U : U extends (keyof T)[] ? Pretty<Partial<Pick<T, U[number]>>> : Partial<T>;
|
|
94
|
+
export type Selected<T extends object, U extends Selector<T>> = U extends Partial<T> ? U : U extends (keyof T)[] ? Pretty<Partial<Pick<T, U[number]>>> : Partial<T>;
|
|
94
95
|
/**
|
|
95
96
|
* The keys that were selected.
|
|
96
97
|
*
|
|
97
98
|
* @template T Options object, where most properties are optional.
|
|
98
99
|
* @template U Selector.
|
|
99
100
|
*/
|
|
100
|
-
type SelectedKeys<T extends object, U extends Selector<T>> = U extends Partial<T> ? keyof U : U extends (keyof T)[] ? U[number] : never;
|
|
101
|
+
export type SelectedKeys<T extends object, U extends Selector<T>> = U extends Partial<T> ? keyof U : U extends (keyof T)[] ? U[number] : never;
|
|
101
102
|
/**
|
|
102
103
|
* Select some properties from an object into multiple other objects.
|
|
103
104
|
* All unselected fields will be contained in a final object for the
|
|
@@ -113,8 +114,15 @@ type SelectedKeys<T extends object, U extends Selector<T>> = U extends Partial<T
|
|
|
113
114
|
* @returns One object for each of args,
|
|
114
115
|
* plus an extra one for everything that was left over.
|
|
115
116
|
*/
|
|
116
|
-
declare function select<T extends object, U extends Selector<T>>(obj: T, defaultsU: U): [Selected<T, U>, Pretty<Omit<T, SelectedKeys<T, U>>>];
|
|
117
|
-
declare function select<T extends object, U extends Selector<T>, V extends Selector<T>>(obj: T, defaultsU: U, defaultsV: V): [
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
export declare function select<T extends object, U extends Selector<T>>(obj: T, defaultsU: U): [Selected<T, U>, Pretty<Omit<T, SelectedKeys<T, U>>>];
|
|
118
|
+
export declare function select<T extends object, U extends Selector<T>, V extends Selector<T>>(obj: T, defaultsU: U, defaultsV: V): [
|
|
119
|
+
Selected<T, U>,
|
|
120
|
+
Selected<T, V>,
|
|
121
|
+
Pretty<Omit<T, SelectedKeys<T, U> | SelectedKeys<T, V>>>
|
|
122
|
+
];
|
|
123
|
+
export declare function select<T extends object, U extends Selector<T>, V extends Selector<T>, W extends Selector<T>>(obj: T, defaultsU: U, defaultsV: V, defaultsW: W): [
|
|
124
|
+
Selected<T, U>,
|
|
125
|
+
Selected<T, V>,
|
|
126
|
+
Selected<T, W>,
|
|
127
|
+
Pretty<Omit<T, SelectedKeys<T, U> | SelectedKeys<T, V> | SelectedKeys<T, W>>>
|
|
128
|
+
];
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
export class AssertionError extends Error {
|
|
2
|
+
constructor(actual, expected, message) {
|
|
3
|
+
let generatedMessage = false;
|
|
4
|
+
if (!message) {
|
|
5
|
+
message = `The expression evaluated to a falsy value:\n\n assert(${actual})\n`;
|
|
6
|
+
generatedMessage = true;
|
|
7
|
+
}
|
|
8
|
+
super(message);
|
|
9
|
+
Object.assign(this, {
|
|
10
|
+
code: 'ERR_ASSERTION',
|
|
11
|
+
actual,
|
|
12
|
+
expected,
|
|
13
|
+
operator: '==',
|
|
14
|
+
generatedMessage,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
toString() {
|
|
18
|
+
return `AssertionError [ERR_ASSERTION]: ${this.message}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Very simplified assert, which will work in the browser.
|
|
23
|
+
*
|
|
24
|
+
* @param value Any value that should be truthy.
|
|
25
|
+
* @param message Optional message.
|
|
26
|
+
* @throws {AssertionError} If value is falsy.
|
|
27
|
+
*/
|
|
28
|
+
export function assert(value, message) {
|
|
29
|
+
if (value) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
throw new AssertionError(value, true, message);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Is the object an ErrnoException?
|
|
36
|
+
*
|
|
37
|
+
* @param e Object to check.
|
|
38
|
+
* @returns Type assertion.
|
|
39
|
+
*/
|
|
40
|
+
export function isErrno(e) {
|
|
41
|
+
return (e instanceof Error) &&
|
|
42
|
+
Object.prototype.hasOwnProperty.call(e, 'code');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Does the error contain a specific code?
|
|
46
|
+
*
|
|
47
|
+
* @param e Exception to check.
|
|
48
|
+
* @param code Code such as 'ENOENT' or -2.
|
|
49
|
+
* @returns True if code matches.
|
|
50
|
+
* @throws {TypeError} On invalid code type.
|
|
51
|
+
*/
|
|
52
|
+
export function errCode(e, code) {
|
|
53
|
+
if (!isErrno(e)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
switch (typeof code) {
|
|
57
|
+
case 'string':
|
|
58
|
+
return e.code === code;
|
|
59
|
+
case 'number':
|
|
60
|
+
return e.errno === code;
|
|
61
|
+
}
|
|
62
|
+
throw new TypeError(`Invalid code: ${JSON.stringify(code)}`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Is the current environment CI-like.
|
|
66
|
+
*
|
|
67
|
+
* @param opts Override the environment determination, for testing.
|
|
68
|
+
* @returns True if in CI.
|
|
69
|
+
*/
|
|
70
|
+
export function isCI(opts) {
|
|
71
|
+
// Override for testing, so we don't have to much with process.env
|
|
72
|
+
if (opts && ('CI' in opts)) {
|
|
73
|
+
return Boolean(opts.CI);
|
|
74
|
+
}
|
|
75
|
+
if (typeof process === 'undefined') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const { env } = process;
|
|
79
|
+
return Boolean(
|
|
80
|
+
// Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari,
|
|
81
|
+
// GitHub Actions
|
|
82
|
+
env.CI ||
|
|
83
|
+
env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
|
|
84
|
+
env.BUILD_NUMBER || // Jenkins, TeamCity
|
|
85
|
+
env.RUN_ID || // TaskCluster, dsari
|
|
86
|
+
false);
|
|
87
|
+
}
|
|
88
|
+
const noOp = () => undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Polyfill for Promise.withResolvers. Once node 22 is the minimum version,
|
|
91
|
+
* this should be removed.
|
|
92
|
+
*
|
|
93
|
+
* @template T Return type for resolve.
|
|
94
|
+
* @returns An object containing a new Promise object and two functions to
|
|
95
|
+
* resolve or reject it, corresponding to the two parameters passed to the
|
|
96
|
+
* executor of the Promise() constructor.
|
|
97
|
+
*/
|
|
98
|
+
export function promiseWithResolvers() {
|
|
99
|
+
let resolve = noOp;
|
|
100
|
+
let reject = noOp;
|
|
101
|
+
const promise = new Promise((res, rej) => {
|
|
102
|
+
resolve = res;
|
|
103
|
+
reject = rej;
|
|
104
|
+
});
|
|
105
|
+
return { promise, resolve, reject };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the names of the keys of an options type, from the defaults.
|
|
109
|
+
*
|
|
110
|
+
* @template T Options type.
|
|
111
|
+
* @param defaults Default values for the options.
|
|
112
|
+
* @returns List of keys of the given object.
|
|
113
|
+
*/
|
|
114
|
+
export function nameSet(defaults) {
|
|
115
|
+
return new Set(Object.keys(defaults));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Assert that none of the given sets of strings share a value.
|
|
119
|
+
* Useful for validating inputs to select.
|
|
120
|
+
*
|
|
121
|
+
* @param sets Sets to check.
|
|
122
|
+
* @throws {AssertionError} If sets are the wrong type.
|
|
123
|
+
*/
|
|
124
|
+
export function assertDisjoint(...sets) {
|
|
125
|
+
const seen = new Set();
|
|
126
|
+
for (const s of sets) {
|
|
127
|
+
let it = null;
|
|
128
|
+
if (Array.isArray(s)) {
|
|
129
|
+
it = s;
|
|
130
|
+
}
|
|
131
|
+
else if (s instanceof Set) {
|
|
132
|
+
it = s;
|
|
133
|
+
}
|
|
134
|
+
else if ((typeof s === 'object') && s) {
|
|
135
|
+
it = Object.keys(s);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw new Error('Invalid set');
|
|
139
|
+
}
|
|
140
|
+
for (const i of it) {
|
|
141
|
+
assert(!seen.has(i), i);
|
|
142
|
+
seen.add(i);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export function select(obj, ...defaults) {
|
|
147
|
+
const sets = [];
|
|
148
|
+
const res = defaults.map(a => {
|
|
149
|
+
const ret = Object.create(null);
|
|
150
|
+
if (a instanceof Set) {
|
|
151
|
+
sets.push(a);
|
|
152
|
+
return ret;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(a)) {
|
|
155
|
+
sets.push(new Set(a));
|
|
156
|
+
return ret;
|
|
157
|
+
}
|
|
158
|
+
if (!a || (typeof a !== 'object')) {
|
|
159
|
+
throw new Error(`Invalid set: ${a}`);
|
|
160
|
+
}
|
|
161
|
+
sets.push(nameSet(a));
|
|
162
|
+
return Object.assign(ret, a);
|
|
163
|
+
});
|
|
164
|
+
const leftovers = Object.create(null);
|
|
165
|
+
res.push(leftovers);
|
|
166
|
+
if (!obj) {
|
|
167
|
+
return res;
|
|
168
|
+
}
|
|
169
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
170
|
+
let found = false;
|
|
171
|
+
sets.forEach((s, i) => {
|
|
172
|
+
if (!found && s.has(k)) {
|
|
173
|
+
found = true;
|
|
174
|
+
res[i][k] = v;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (!found) {
|
|
178
|
+
leftovers[k] = v;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return res;
|
|
182
|
+
}
|
package/lib/{u8.d.mts → u8.d.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/u8.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Convert hex string to bytes.
|
|
4
3
|
*
|
|
@@ -12,5 +11,4 @@ declare const hexToU8: (s: string) => Uint8Array;
|
|
|
12
11
|
* @returns Hex.
|
|
13
12
|
*/
|
|
14
13
|
declare const u8toHex: (u8: Uint8Array) => string;
|
|
15
|
-
|
|
16
|
-
export { hexToU8, u8toHex };
|
|
14
|
+
export { hexToU8, u8toHex, };
|
package/lib/u8.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as impl from './u8Impl.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert hex string to bytes.
|
|
4
|
+
*
|
|
5
|
+
* @param str String.
|
|
6
|
+
* @returns Buffer.
|
|
7
|
+
*/
|
|
8
|
+
const hexToU8 =
|
|
9
|
+
// @ts-expect-error fromHex not in types yet
|
|
10
|
+
Uint8Array.fromHex ??
|
|
11
|
+
impl.hexToU8;
|
|
12
|
+
/**
|
|
13
|
+
* Convert bytes to hex string.
|
|
14
|
+
* @param u8 Bytes.
|
|
15
|
+
* @returns Hex.
|
|
16
|
+
*/
|
|
17
|
+
const u8toHex =
|
|
18
|
+
// @ts-expect-error toHex not in types yet
|
|
19
|
+
Uint8Array.prototype.toHex ? impl.u8toHexModern : impl.u8toHex;
|
|
20
|
+
export { hexToU8, u8toHex, };
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
//#region src/u8Impl.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Convert hex string to bytes.
|
|
4
3
|
*
|
|
5
4
|
* @param str String.
|
|
6
5
|
* @returns Buffer.
|
|
7
6
|
*/
|
|
8
|
-
declare function hexToU8(str: string): Uint8Array;
|
|
7
|
+
export declare function hexToU8(str: string): Uint8Array;
|
|
9
8
|
/**
|
|
10
9
|
* Convert bytes to hex string.
|
|
11
10
|
* @param u8 Bytes.
|
|
12
11
|
* @returns Hex.
|
|
13
12
|
*/
|
|
14
|
-
declare function u8toHex(u8: Uint8Array): string;
|
|
13
|
+
export declare function u8toHex(u8: Uint8Array): string;
|
|
15
14
|
/**
|
|
16
15
|
* Convert bytes to hex string.
|
|
17
16
|
* @param u8 Bytes.
|
|
18
17
|
* @returns Hex.
|
|
19
18
|
*/
|
|
20
|
-
declare function u8toHexModern(u8: Uint8Array): string;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { hexToU8, u8toHex, u8toHexModern };
|
|
19
|
+
export declare function u8toHexModern(u8: Uint8Array): string;
|
package/lib/u8Impl.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert hex string to bytes.
|
|
3
|
+
*
|
|
4
|
+
* @param str String.
|
|
5
|
+
* @returns Buffer.
|
|
6
|
+
*/
|
|
7
|
+
export function hexToU8(str) {
|
|
8
|
+
str = str.replace(/\s/g, '');
|
|
9
|
+
let len = Math.ceil(str.length / 2);
|
|
10
|
+
const res = new Uint8Array(len);
|
|
11
|
+
len--;
|
|
12
|
+
for (let end = str.length, start = end - 2; end >= 0; end = start, start -= 2, len--) {
|
|
13
|
+
res[len] = parseInt(str.substring(start, end), 16);
|
|
14
|
+
}
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert bytes to hex string.
|
|
19
|
+
* @param u8 Bytes.
|
|
20
|
+
* @returns Hex.
|
|
21
|
+
*/
|
|
22
|
+
export function u8toHex(u8) {
|
|
23
|
+
return u8.reduce((t, v) => t + v.toString(16).padStart(2, '0'), '');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convert bytes to hex string.
|
|
27
|
+
* @param u8 Bytes.
|
|
28
|
+
* @returns Hex.
|
|
29
|
+
*/
|
|
30
|
+
export function u8toHexModern(u8) {
|
|
31
|
+
// @ts-expect-error toHex not in types yet
|
|
32
|
+
return u8.toHex();
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"decription": "",
|
|
5
|
-
"main": "lib/index.
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/*"
|
|
8
8
|
],
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./lib/index.
|
|
11
|
-
"./u8": "./lib/u8.
|
|
10
|
+
".": "./lib/index.js",
|
|
11
|
+
"./u8": "./lib/u8.js"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"author": "Joe Hildebrand <joe-github@cursive.net>",
|
|
@@ -21,13 +21,8 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/cto-af/utils/issues"
|
|
23
23
|
},
|
|
24
|
-
"packageManager": "pnpm@
|
|
25
|
-
"pnpm": {
|
|
26
|
-
"overrides": {
|
|
27
|
-
"c8@11.0.0>yargs": "18.0.0"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
24
|
+
"packageManager": "pnpm@12.5.1",
|
|
30
25
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
26
|
+
"node": ">=22"
|
|
32
27
|
}
|
|
33
28
|
}
|
package/lib/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var AssertionError=class extends Error{constructor(actual,expected,message){let generatedMessage=!1;message||(message=`The expression evaluated to a falsy value:\n\n assert(${actual})\n`,generatedMessage=!0),super(message),Object.assign(this,{code:`ERR_ASSERTION`,actual,expected,operator:`==`,generatedMessage})}toString(){return`AssertionError [ERR_ASSERTION]: ${this.message}`}};function assert(value,message){if(!value)throw new AssertionError(value,!0,message)}function isErrno(e){return e instanceof Error&&Object.prototype.hasOwnProperty.call(e,`code`)}function errCode(e,code){if(!isErrno(e))return!1;switch(typeof code){case`string`:return e.code===code;case`number`:return e.errno===code}throw TypeError(`Invalid code: ${JSON.stringify(code)}`)}function isCI(opts){if(opts&&`CI`in opts)return!!opts.CI;if(typeof process>`u`)return!1;let{env}=process;return!!(env.CI||env.CONTINUOUS_INTEGRATION||env.BUILD_NUMBER||env.RUN_ID)}const noOp=()=>void 0;function promiseWithResolvers(){let resolve=noOp,reject=noOp;return{promise:new Promise((res,rej)=>{resolve=res,reject=rej}),resolve,reject}}function nameSet(defaults){return new Set(Object.keys(defaults))}function assertDisjoint(...sets){let seen=new Set;for(let s of sets){let it=null;if(Array.isArray(s))it=s;else if(s instanceof Set)it=s;else if(typeof s==`object`&&s)it=Object.keys(s);else throw Error(`Invalid set`);for(let i of it)assert(!seen.has(i),i),seen.add(i)}}function select(obj,...defaults){let sets=[],res=defaults.map(a=>{let ret=Object.create(null);if(a instanceof Set)return sets.push(a),ret;if(Array.isArray(a))return sets.push(new Set(a)),ret;if(!a||typeof a!=`object`)throw Error(`Invalid set: ${a}`);return sets.push(nameSet(a)),Object.assign(ret,a)}),leftovers=Object.create(null);if(res.push(leftovers),!obj)return res;for(let[k,v]of Object.entries(obj)){let found=!1;sets.forEach((s,i)=>{!found&&s.has(k)&&(found=!0,res[i][k]=v)}),found||(leftovers[k]=v)}return res}export{AssertionError,assert,assertDisjoint,errCode,isCI,isErrno,nameSet,promiseWithResolvers,select};
|
package/lib/u8.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hexToU8 as hexToU8$1,u8toHex as u8toHex$1,u8toHexModern}from"./u8Impl.mjs";const hexToU8=Uint8Array.fromHex??hexToU8$1,u8toHex=Uint8Array.prototype.toHex?u8toHexModern:u8toHex$1;export{hexToU8,u8toHex};
|
package/lib/u8Impl.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function hexToU8(str){str=str.replace(/\s/g,``);let len=Math.ceil(str.length/2),res=new Uint8Array(len);len--;for(let end=str.length,start=end-2;end>=0;end=start,start-=2,len--)res[len]=parseInt(str.substring(start,end),16);return res}function u8toHex(u8){return u8.reduce((t,v)=>t+v.toString(16).padStart(2,`0`),``)}function u8toHexModern(u8){return u8.toHex()}export{hexToU8,u8toHex,u8toHexModern};
|