@cto.af/utils 1.3.6 → 1.4.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.mjs CHANGED
@@ -1 +1 @@
1
- var e=class extends Error{constructor(e,t,n){let r=!1;n||(n=`The expression evaluated to a falsy value:\n\n assert(${e})\n`,r=!0),super(n),Object.assign(this,{code:`ERR_ASSERTION`,actual:e,expected:t,operator:`==`,generatedMessage:r})}toString(){return`AssertionError [ERR_ASSERTION]: ${this.message}`}};function t(t,n){if(!t)throw new e(t,!0,n)}function n(e){return e instanceof Error&&Object.prototype.hasOwnProperty.call(e,`code`)}function r(e,t){if(!n(e))return!1;switch(typeof t){case`string`:return e.code===t;case`number`:return e.errno===t}throw TypeError(`Invalid code: ${JSON.stringify(t)}`)}function i(e){if(e&&`CI`in e)return!!e.CI;if(typeof process>`u`)return!1;let{env:t}=process;return!!(t.CI||t.CONTINUOUS_INTEGRATION||t.BUILD_NUMBER||t.RUN_ID)}const a=()=>void 0;function o(){let e=a,t=a;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function s(e){return new Set(Object.keys(e))}function c(...e){let n=new Set;for(let r of e){let e=null;if(Array.isArray(r))e=r;else if(r instanceof Set)e=r;else if(typeof r==`object`&&r)e=Object.keys(r);else throw Error(`Invalid set`);for(let r of e)t(!n.has(r),r),n.add(r)}}function l(e,...t){let n=[],r=t.map(e=>{let t=Object.create(null);if(e instanceof Set)return n.push(e),t;if(Array.isArray(e))return n.push(new Set(e)),t;if(!e||typeof e!=`object`)throw Error(`Invalid set: ${e}`);return n.push(s(e)),Object.assign(t,e)}),i=Object.create(null);if(r.push(i),!e)return r;for(let[t,a]of Object.entries(e)){let e=!1;n.forEach((n,i)=>{!e&&n.has(t)&&(e=!0,r[i][t]=a)}),e||(i[t]=a)}return r}export{e as AssertionError,t as assert,c as assertDisjoint,r as errCode,i as isCI,n as isErrno,s as nameSet,o as promiseWithResolvers,l as select};
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};
@@ -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.6",
3
+ "version": "1.4.1",
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.22.0",
24
+ "packageManager": "pnpm@10.25.0",
22
25
  "engines": {
23
26
  "node": ">=20"
24
27
  }