@cto.af/utils 1.3.0 → 1.3.2
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 +11 -3
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -52,18 +52,26 @@ declare function nameSet<T extends object>(defaults: T): Set<keyof T>;
|
|
|
52
52
|
* Useful for validating inputs to select.
|
|
53
53
|
*
|
|
54
54
|
* @param sets Sets to check.
|
|
55
|
+
* @throws If sets are the wrong type.
|
|
55
56
|
*/
|
|
56
|
-
declare function assertDisjoint(...sets: Set<string>[]): void;
|
|
57
|
+
declare function assertDisjoint(...sets: (Set<string> | string[] | object)[]): void;
|
|
58
|
+
type Selector<T> = Partial<T> | (keyof T)[] | Set<keyof T>;
|
|
57
59
|
/**
|
|
58
60
|
* Select some properties from an object into multiple other objects.
|
|
61
|
+
* All unselected fields will be contained in a final object for the
|
|
62
|
+
* "leftovers", meaning there will always be at least one element in the
|
|
63
|
+
* result array. If the first selector is a set of defaults, the type from
|
|
64
|
+
* that object will be copied to the first element of the result array.
|
|
59
65
|
*
|
|
60
66
|
* @template T Composed options object.
|
|
67
|
+
* @template U May be a Required<Partial<T>> type.
|
|
61
68
|
* @param obj The source object.
|
|
69
|
+
* @param defaults Defaults object or field names.
|
|
62
70
|
* @param args Arrays of strings to select into the result
|
|
63
71
|
* objects.
|
|
64
72
|
* @returns {Partial<Record<keyof T, any>>[]} One object for each of args,
|
|
65
73
|
* plus an extra one for everything that was left over.
|
|
66
74
|
*/
|
|
67
|
-
declare function select<T extends object
|
|
75
|
+
declare function select<T extends object, U extends Selector<T>>(obj: T, defaults?: U, ...args: Selector<T>[]): [U extends Partial<T> ? U : Partial<T>, ...Partial<T>[]];
|
|
68
76
|
|
|
69
|
-
export { type CiOptions, type PromiseWithResolvers, assertDisjoint, errCode, isCI, isErrno, nameSet, promiseWithResolvers, select };
|
|
77
|
+
export { type CiOptions, type PromiseWithResolvers, type Selector, assertDisjoint, errCode, isCI, isErrno, nameSet, promiseWithResolvers, select };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"assert/strict";function
|
|
1
|
+
import u from"assert/strict";function p(e){return e instanceof Error&&Object.prototype.hasOwnProperty.call(e,"code")}function v(e,t){if(!p(e))return!1;switch(typeof t){case"string":return e.code===t;case"number":return e.errno===t}throw new TypeError(`Invalid code: ${JSON.stringify(t)}`)}function P(e){if(e&&"CI"in e)return!!e.CI;let{env:t}=process;return!!(t.CI||t.CONTINUOUS_INTEGRATION||t.BUILD_NUMBER||t.RUN_ID)}var l=()=>{};function b(){let e=l,t=l;return{promise:new Promise((n,s)=>{e=n,t=s}),resolve:e,reject:t}}function y(e){return new Set(Object.keys(e))}function k(...e){let t=new Set;for(let o of e){let n=null;if(Array.isArray(o))n=o;else if(o instanceof Set)n=o;else if(typeof o=="object"&&o)n=Object.keys(o);else throw new Error("Invalid set");for(let s of n)u(!t.has(s)),t.add(s)}}function m(e,t,...o){t!==void 0&&o.unshift(t);let n=[],s=o.map(r=>{let i=Object.create(null);if(r instanceof Set)return n.push(r),i;if(Array.isArray(r))return n.push(new Set(r)),i;if(!r||typeof r!="object")throw new Error(`Invalid set: ${r}`);return n.push(y(r)),Object.assign(i,r)}),f=Object.create(null);if(s.push(f),!e)return s;for(let[r,i]of Object.entries(e)){let a=!1;n.forEach((c,T)=>{!a&&c.has(r)&&(a=!0,s[T][r]=i)}),a||(f[r]=i)}return s}export{k as assertDisjoint,v as errCode,P as isCI,p as isErrno,y as nameSet,b as promiseWithResolvers,m as select};
|