@webdeveric/utils 0.29.0 → 0.29.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.
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cartesian = void 0;
4
+ /**
5
+ * @see https://en.wikipedia.org/wiki/Cartesian_product
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ function* cartesian(...input) {
9
+ const [head, ...tail] = input;
10
+ if (!Array.isArray(head)) {
11
+ return [[]];
12
+ }
13
+ const remainder = tail.length ? cartesian(...tail) : [[]];
14
+ for (const rest of remainder) {
15
+ for (const item of head) {
16
+ yield [item, ...rest];
17
+ }
18
+ }
19
+ }
20
+ exports.cartesian = cartesian;
21
+ //# sourceMappingURL=cartesian.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartesian.js","sourceRoot":"","sources":["../../src/cartesian.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,8DAA8D;AAC9D,QAAe,CAAC,CAAC,SAAS,CAAC,GAAG,KAAc;IAC1C,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;IAE9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE1D,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAdD,8BAcC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combinations = void 0;
4
+ const asArray_js_1 = require("./asArray.js");
5
+ const cartesian_js_1 = require("./cartesian.js");
6
+ const type_predicate_js_1 = require("./type-predicate.js");
7
+ function* combinations(input) {
8
+ const propertyNames = Object.keys(input);
9
+ const propertyValues = Object.values(input).map(value => (0, type_predicate_js_1.isObject)(value) ? [...combinations(value)] : (0, asArray_js_1.asArray)(value));
10
+ for (const combo of (0, cartesian_js_1.cartesian)(...propertyValues)) {
11
+ yield Object.fromEntries(combo.map((value, index) => [propertyNames[index], value]));
12
+ }
13
+ }
14
+ exports.combinations = combinations;
15
+ //# sourceMappingURL=combinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.js","sourceRoot":"","sources":["../../src/combinations.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AACvC,iDAA2C;AAC3C,2DAA+C;AAc/C,QAAe,CAAC,CAAC,YAAY,CAG3B,KAAY;IACZ,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CACtD,IAAA,4BAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,oBAAO,EAAC,KAAK,CAAC,CAC5D,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,IAAA,wBAAS,EAAC,GAAG,cAAc,CAAC,EAAE,CAAC;QACjD,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;AACH,CAAC;AAZD,oCAYC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @see https://en.wikipedia.org/wiki/Cartesian_product
3
+ */
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ export function* cartesian(...input) {
6
+ const [head, ...tail] = input;
7
+ if (!Array.isArray(head)) {
8
+ return [[]];
9
+ }
10
+ const remainder = tail.length ? cartesian(...tail) : [[]];
11
+ for (const rest of remainder) {
12
+ for (const item of head) {
13
+ yield [item, ...rest];
14
+ }
15
+ }
16
+ }
17
+ //# sourceMappingURL=cartesian.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartesian.js","sourceRoot":"","sources":["../../src/cartesian.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,8DAA8D;AAC9D,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,KAAc;IAC1C,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;IAE9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE1D,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { asArray } from './asArray.js';
2
+ import { cartesian } from './cartesian.js';
3
+ import { isObject } from './type-predicate.js';
4
+ export function* combinations(input) {
5
+ const propertyNames = Object.keys(input);
6
+ const propertyValues = Object.values(input).map(value => isObject(value) ? [...combinations(value)] : asArray(value));
7
+ for (const combo of cartesian(...propertyValues)) {
8
+ yield Object.fromEntries(combo.map((value, index) => [propertyNames[index], value]));
9
+ }
10
+ }
11
+ //# sourceMappingURL=combinations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.js","sourceRoot":"","sources":["../../src/combinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAc/C,MAAM,SAAS,CAAC,CAAC,YAAY,CAG3B,KAAY;IACZ,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CACtD,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAC5D,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,GAAG,cAAc,CAAC,EAAE,CAAC;QACjD,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @see https://en.wikipedia.org/wiki/Cartesian_product
3
+ */
4
+ export declare function cartesian(...input: any[][]): Generator<any[]>;
5
+ //# sourceMappingURL=cartesian.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartesian.d.ts","sourceRoot":"","sources":["../../src/cartesian.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAiB,SAAS,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,CAc9D"}
@@ -0,0 +1,7 @@
1
+ import type { UnknownRecord } from './types/records.js';
2
+ export type CombinationsInput<Type> = {
3
+ [Property in keyof Type]: Type[Property] extends UnknownRecord ? CombinationsInput<Type[Property]> : Type[Property] | Type[Property][];
4
+ };
5
+ export type CombinationsOutput<Input extends CombinationsInput<unknown>> = Input extends CombinationsInput<infer Type> ? Type : never;
6
+ export declare function combinations<Type extends UnknownRecord = UnknownRecord, Input extends CombinationsInput<Type> = CombinationsInput<Type>>(input: Input): Generator<CombinationsOutput<Input>>;
7
+ //# sourceMappingURL=combinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/combinations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,MAAM,iBAAiB,CAAC,IAAI,IAAI;KACnC,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,aAAa,GAC1D,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE;CACtC,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,iBAAiB,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,iBAAiB,CAAC,MAAM,IAAI,CAAC,GAClH,IAAI,GACJ,KAAK,CAAC;AAEV,wBAAiB,YAAY,CAC3B,IAAI,SAAS,aAAa,GAAG,aAAa,EAC1C,KAAK,SAAS,iBAAiB,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,EAC/D,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CASpD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.29.0",
4
+ "version": "0.29.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },