@cto.af/utils 1.2.2 → 1.3.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.d.ts CHANGED
@@ -39,5 +39,31 @@ interface PromiseWithResolvers<T> {
39
39
  * executor of the Promise() constructor.
40
40
  */
41
41
  declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
42
+ /**
43
+ * Get the names of the keys of an options type, from the defaults.
44
+ *
45
+ * @template T
46
+ * @param defaults Default values for the options.
47
+ * @returns List of keys of the given object.
48
+ */
49
+ declare function nameSet<T extends object>(defaults: T): Set<keyof T>;
50
+ /**
51
+ * Assert that none of the given sets of strings share a value.
52
+ * Useful for validating inputs to select.
53
+ *
54
+ * @param sets Sets to check.
55
+ */
56
+ declare function assertDisjoint(...sets: Set<string>[]): void;
57
+ /**
58
+ * Select some properties from an object into multiple other objects.
59
+ *
60
+ * @template T Composed options object.
61
+ * @param obj The source object.
62
+ * @param args Arrays of strings to select into the result
63
+ * objects.
64
+ * @returns {Partial<Record<keyof T, any>>[]} One object for each of args,
65
+ * plus an extra one for everything that was left over.
66
+ */
67
+ declare function select<T extends object>(obj: T, ...args: ((keyof T)[] | Set<keyof T>)[]): Partial<T>[];
42
68
 
43
- export { type CiOptions, type PromiseWithResolvers, errCode, isCI, isErrno, promiseWithResolvers };
69
+ export { type CiOptions, type PromiseWithResolvers, assertDisjoint, errCode, isCI, isErrno, nameSet, promiseWithResolvers, select };
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- function t(e){return e instanceof Error&&Object.prototype.hasOwnProperty.call(e,"code")}function a(e,r){if(!t(e))return!1;switch(typeof r){case"string":return e.code===r;case"number":return e.errno===r}throw new TypeError(`Invalid code: ${JSON.stringify(r)}`)}function c(e){if(e&&"CI"in e)return!!e.CI;let{env:r}=process;return!!(r.CI||r.CONTINUOUS_INTEGRATION||r.BUILD_NUMBER||r.RUN_ID)}var o=()=>{};function l(){let e=o,r=o;return{promise:new Promise((n,i)=>{e=n,r=i}),resolve:e,reject:r}}export{a as errCode,c as isCI,t as isErrno,l as promiseWithResolvers};
1
+ import u from"assert/strict";function T(e){return e instanceof Error&&Object.prototype.hasOwnProperty.call(e,"code")}function m(e,o){if(!T(e))return!1;switch(typeof o){case"string":return e.code===o;case"number":return e.errno===o}throw new TypeError(`Invalid code: ${JSON.stringify(o)}`)}function v(e){if(e&&"CI"in e)return!!e.CI;let{env:o}=process;return!!(o.CI||o.CONTINUOUS_INTEGRATION||o.BUILD_NUMBER||o.RUN_ID)}var f=()=>{};function y(){let e=f,o=f;return{promise:new Promise((t,s)=>{e=t,o=s}),resolve:e,reject:o}}function d(e){return new Set(Object.keys(e))}function k(...e){let o=new Set;for(let r of e)for(let t of r)u(!o.has(t)),o.add(t)}function O(e,...o){let r=o.map(()=>Object.create(null)),t=Object.create(null);if(r.push(t),!e)return r;let s=o.map(n=>n instanceof Set?n:new Set(n));for(let[n,a]of Object.entries(e)){let i=!1;s.forEach((c,l)=>{!i&&c.has(n)&&(i=!0,r[l][n]=a)}),i||(t[n]=a)}return r}export{k as assertDisjoint,m as errCode,v as isCI,T as isErrno,d as nameSet,y as promiseWithResolvers,O as select};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cto.af/utils",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "decription": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -18,7 +18,7 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/cto-af/utils/issues"
20
20
  },
21
- "packageManager": "pnpm@10.14.0",
21
+ "packageManager": "pnpm@10.15.0",
22
22
  "engines": {
23
23
  "node": ">=20"
24
24
  }