@cto.af/utils 1.3.6 → 1.4.0
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.mjs +1 -1
- package/lib/u8.d.mts +16 -0
- package/lib/u8.mjs +1 -0
- package/lib/u8Impl.d.mts +22 -0
- package/lib/u8Impl.mjs +1 -0
- package/package.json +6 -3
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/u8.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert hex string to bytes.
|
|
4
|
+
*
|
|
5
|
+
* @param str String.
|
|
6
|
+
* @returns Buffer.
|
|
7
|
+
*/
|
|
8
|
+
declare const hexToU8: (s: string) => Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Convert bytes to hex string.
|
|
11
|
+
* @param u8 Bytes.
|
|
12
|
+
* @returns Hex.
|
|
13
|
+
*/
|
|
14
|
+
declare const u8toHex: (u8: Uint8Array) => string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { hexToU8, u8toHex };
|
package/lib/u8.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/u8Impl.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert hex string to bytes.
|
|
4
|
+
*
|
|
5
|
+
* @param str String.
|
|
6
|
+
* @returns Buffer.
|
|
7
|
+
*/
|
|
8
|
+
declare function hexToU8(str: string): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Convert bytes to hex string.
|
|
11
|
+
* @param u8 Bytes.
|
|
12
|
+
* @returns Hex.
|
|
13
|
+
*/
|
|
14
|
+
declare function u8toHex(u8: Uint8Array): string;
|
|
15
|
+
/**
|
|
16
|
+
* Convert bytes to hex string.
|
|
17
|
+
* @param u8 Bytes.
|
|
18
|
+
* @returns Hex.
|
|
19
|
+
*/
|
|
20
|
+
declare function u8toHexModern(u8: Uint8Array): string;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { hexToU8, u8toHex, u8toHexModern };
|
package/lib/u8Impl.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"decription": "",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/*"
|
|
8
8
|
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.mjs",
|
|
11
|
+
"u8": "./lib/u8.mjs"
|
|
12
|
+
},
|
|
9
13
|
"type": "module",
|
|
10
|
-
"keywords": [],
|
|
11
14
|
"author": "Joe Hildebrand <joe-github@cursive.net>",
|
|
12
15
|
"license": "MIT",
|
|
13
16
|
"repository": {
|
|
@@ -18,7 +21,7 @@
|
|
|
18
21
|
"bugs": {
|
|
19
22
|
"url": "https://github.com/cto-af/utils/issues"
|
|
20
23
|
},
|
|
21
|
-
"packageManager": "pnpm@10.
|
|
24
|
+
"packageManager": "pnpm@10.25.0",
|
|
22
25
|
"engines": {
|
|
23
26
|
"node": ">=20"
|
|
24
27
|
}
|