@bemedev/decompose 2.0.2 → 2.1.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.
Files changed (64) hide show
  1. package/lib/constants/index.cjs +9 -14
  2. package/lib/constants/index.js +3 -3
  3. package/lib/constants/objects.cjs +10 -9
  4. package/lib/constants/objects.cjs.map +1 -1
  5. package/lib/constants/objects.js +9 -7
  6. package/lib/constants/objects.js.map +1 -1
  7. package/lib/constants/strings.cjs +9 -8
  8. package/lib/constants/strings.cjs.map +1 -1
  9. package/lib/constants/strings.js +8 -6
  10. package/lib/constants/strings.js.map +1 -1
  11. package/lib/contexts/assign.cjs +34 -38
  12. package/lib/contexts/assign.cjs.map +1 -1
  13. package/lib/contexts/assign.d.ts.map +1 -1
  14. package/lib/contexts/assign.js +33 -36
  15. package/lib/contexts/assign.js.map +1 -1
  16. package/lib/contexts/constants.cjs +8 -7
  17. package/lib/contexts/constants.cjs.map +1 -1
  18. package/lib/contexts/constants.js +7 -5
  19. package/lib/contexts/constants.js.map +1 -1
  20. package/lib/contexts/get.cjs +20 -22
  21. package/lib/contexts/get.cjs.map +1 -1
  22. package/lib/contexts/get.js +19 -20
  23. package/lib/contexts/get.js.map +1 -1
  24. package/lib/contexts/index.cjs +5 -10
  25. package/lib/contexts/index.js +3 -3
  26. package/lib/decompose.cjs +53 -65
  27. package/lib/decompose.cjs.map +1 -1
  28. package/lib/decompose.js +52 -63
  29. package/lib/decompose.js.map +1 -1
  30. package/lib/decomposeKeys.cjs +27 -33
  31. package/lib/decomposeKeys.cjs.map +1 -1
  32. package/lib/decomposeKeys.js +25 -30
  33. package/lib/decomposeKeys.js.map +1 -1
  34. package/lib/decomposeSV.cjs +25 -28
  35. package/lib/decomposeSV.cjs.map +1 -1
  36. package/lib/decomposeSV.js +22 -24
  37. package/lib/decomposeSV.js.map +1 -1
  38. package/lib/flatByKey.cjs +26 -22
  39. package/lib/flatByKey.cjs.map +1 -1
  40. package/lib/flatByKey.js +25 -20
  41. package/lib/flatByKey.js.map +1 -1
  42. package/lib/helpers.cjs +10 -13
  43. package/lib/helpers.cjs.map +1 -1
  44. package/lib/helpers.js +9 -11
  45. package/lib/helpers.js.map +1 -1
  46. package/lib/index.cjs +27 -31
  47. package/lib/index.js +12 -11
  48. package/lib/recompose.cjs +43 -51
  49. package/lib/recompose.cjs.map +1 -1
  50. package/lib/recompose.js +42 -49
  51. package/lib/recompose.js.map +1 -1
  52. package/lib/sortMap.cjs +6 -5
  53. package/lib/sortMap.cjs.map +1 -1
  54. package/lib/sortMap.js +5 -3
  55. package/lib/sortMap.js.map +1 -1
  56. package/lib/types.types.d.ts +22 -11
  57. package/lib/types.types.d.ts.map +1 -1
  58. package/package.json +41 -33
  59. package/lib/constants/index.cjs.map +0 -1
  60. package/lib/constants/index.js.map +0 -1
  61. package/lib/contexts/index.cjs.map +0 -1
  62. package/lib/contexts/index.js.map +0 -1
  63. package/lib/index.cjs.map +0 -1
  64. package/lib/index.js.map +0 -1
@@ -1,14 +1,9 @@
1
- 'use strict';
2
-
3
- var constants_objects = require('./objects.cjs');
4
- var constants_strings = require('./strings.cjs');
5
-
6
-
7
-
8
- exports.DEFAULT_DECOMPOSE_OPTIONS = constants_objects.DEFAULT_DECOMPOSE_OPTIONS;
9
- exports.DEFAULT_FLAT_OPTIONS = constants_objects.DEFAULT_FLAT_OPTIONS;
10
- exports.DELIMITER = constants_strings.DELIMITER;
11
- exports.LEFT_BRACKET = constants_strings.LEFT_BRACKET;
12
- exports.RIGHT_BRACKET = constants_strings.RIGHT_BRACKET;
13
- exports.SEPARATOR = constants_strings.SEPARATOR;
14
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_constants_strings = require("./strings.cjs");
3
+ const require_constants_objects = require("./objects.cjs");
4
+ exports.DEFAULT_DECOMPOSE_OPTIONS = require_constants_objects.DEFAULT_DECOMPOSE_OPTIONS;
5
+ exports.DEFAULT_FLAT_OPTIONS = require_constants_objects.DEFAULT_FLAT_OPTIONS;
6
+ exports.DELIMITER = require_constants_strings.DELIMITER;
7
+ exports.LEFT_BRACKET = require_constants_strings.LEFT_BRACKET;
8
+ exports.RIGHT_BRACKET = require_constants_strings.RIGHT_BRACKET;
9
+ exports.SEPARATOR = require_constants_strings.SEPARATOR;
@@ -1,3 +1,3 @@
1
- export { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS } from './objects.js';
2
- export { DELIMITER, LEFT_BRACKET, RIGHT_BRACKET, SEPARATOR } from './strings.js';
3
- //# sourceMappingURL=index.js.map
1
+ import { DELIMITER, LEFT_BRACKET, RIGHT_BRACKET, SEPARATOR } from "./strings.js";
2
+ import { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS } from "./objects.js";
3
+ export { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS, DELIMITER, LEFT_BRACKET, RIGHT_BRACKET, SEPARATOR };
@@ -1,15 +1,16 @@
1
- 'use strict';
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/constants/objects.ts
3
3
  const DEFAULT_FLAT_OPTIONS = {
4
- sep: '.',
5
- children: false,
4
+ sep: ".",
5
+ children: false
6
6
  };
7
7
  const DEFAULT_DECOMPOSE_OPTIONS = {
8
- sep: '.',
9
- object: 'key',
10
- start: true,
8
+ sep: ".",
9
+ object: "key",
10
+ start: true
11
11
  };
12
-
12
+ //#endregion
13
13
  exports.DEFAULT_DECOMPOSE_OPTIONS = DEFAULT_DECOMPOSE_OPTIONS;
14
14
  exports.DEFAULT_FLAT_OPTIONS = DEFAULT_FLAT_OPTIONS;
15
- //# sourceMappingURL=objects.cjs.map
15
+
16
+ //# sourceMappingURL=objects.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"objects.cjs","sources":["../../src/constants/objects.ts"],"sourcesContent":["import type { DecomposeOptions, FlatOptions } from '../types.types';\n\nexport const DEFAULT_FLAT_OPTIONS = {\n sep: '.',\n children: false,\n} as const satisfies FlatOptions;\n\nexport const DEFAULT_DECOMPOSE_OPTIONS = {\n sep: '.',\n object: 'key',\n start: true,\n} as const satisfies DecomposeOptions;\n"],"names":[],"mappings":";;AAEO,MAAM,oBAAoB,GAAG;AAClC,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,QAAQ,EAAE,KAAK;;AAGV,MAAM,yBAAyB,GAAG;AACvC,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,MAAM,EAAE,KAAK;AACb,IAAA,KAAK,EAAE,IAAI;;;;;;"}
1
+ {"version":3,"file":"objects.cjs","names":[],"sources":["../../src/constants/objects.ts"],"sourcesContent":["import type { DecomposeOptions, FlatOptions } from '../types.types';\n\nexport const DEFAULT_FLAT_OPTIONS = {\n sep: '.',\n children: false,\n} as const satisfies FlatOptions;\n\nexport const DEFAULT_DECOMPOSE_OPTIONS = {\n sep: '.',\n object: 'key',\n start: true,\n} as const satisfies DecomposeOptions;\n"],"mappings":";;AAEA,MAAa,uBAAuB;CAClC,KAAK;CACL,UAAU;CACX;AAED,MAAa,4BAA4B;CACvC,KAAK;CACL,QAAQ;CACR,OAAO;CACR"}
@@ -1,12 +1,14 @@
1
+ //#region src/constants/objects.ts
1
2
  const DEFAULT_FLAT_OPTIONS = {
2
- sep: '.',
3
- children: false,
3
+ sep: ".",
4
+ children: false
4
5
  };
5
6
  const DEFAULT_DECOMPOSE_OPTIONS = {
6
- sep: '.',
7
- object: 'key',
8
- start: true,
7
+ sep: ".",
8
+ object: "key",
9
+ start: true
9
10
  };
10
-
11
+ //#endregion
11
12
  export { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS };
12
- //# sourceMappingURL=objects.js.map
13
+
14
+ //# sourceMappingURL=objects.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"objects.js","sources":["../../src/constants/objects.ts"],"sourcesContent":["import type { DecomposeOptions, FlatOptions } from '../types.types';\n\nexport const DEFAULT_FLAT_OPTIONS = {\n sep: '.',\n children: false,\n} as const satisfies FlatOptions;\n\nexport const DEFAULT_DECOMPOSE_OPTIONS = {\n sep: '.',\n object: 'key',\n start: true,\n} as const satisfies DecomposeOptions;\n"],"names":[],"mappings":"AAEO,MAAM,oBAAoB,GAAG;AAClC,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,QAAQ,EAAE,KAAK;;AAGV,MAAM,yBAAyB,GAAG;AACvC,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,MAAM,EAAE,KAAK;AACb,IAAA,KAAK,EAAE,IAAI;;;;;"}
1
+ {"version":3,"file":"objects.js","names":[],"sources":["../../src/constants/objects.ts"],"sourcesContent":["import type { DecomposeOptions, FlatOptions } from '../types.types';\n\nexport const DEFAULT_FLAT_OPTIONS = {\n sep: '.',\n children: false,\n} as const satisfies FlatOptions;\n\nexport const DEFAULT_DECOMPOSE_OPTIONS = {\n sep: '.',\n object: 'key',\n start: true,\n} as const satisfies DecomposeOptions;\n"],"mappings":";AAEA,MAAa,uBAAuB;CAClC,KAAK;CACL,UAAU;CACX;AAED,MAAa,4BAA4B;CACvC,KAAK;CACL,QAAQ;CACR,OAAO;CACR"}
@@ -1,12 +1,13 @@
1
- 'use strict';
2
-
3
- const DELIMITER = '-{/./:}-';
4
- const LEFT_BRACKET = '-{LEFT_BRACKET}-';
5
- const RIGHT_BRACKET = '-{RIGHT_BRACKET}-';
6
- const SEPARATOR = '.';
7
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/constants/strings.ts
3
+ const DELIMITER = "-{/./:}-";
4
+ const LEFT_BRACKET = "-{LEFT_BRACKET}-";
5
+ const RIGHT_BRACKET = "-{RIGHT_BRACKET}-";
6
+ const SEPARATOR = ".";
7
+ //#endregion
8
8
  exports.DELIMITER = DELIMITER;
9
9
  exports.LEFT_BRACKET = LEFT_BRACKET;
10
10
  exports.RIGHT_BRACKET = RIGHT_BRACKET;
11
11
  exports.SEPARATOR = SEPARATOR;
12
- //# sourceMappingURL=strings.cjs.map
12
+
13
+ //# sourceMappingURL=strings.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.cjs","sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\nexport const LEFT_BRACKET = '-{LEFT_BRACKET}-' as const;\nexport const RIGHT_BRACKET = '-{RIGHT_BRACKET}-' as const;\nexport const SEPARATOR = '.' as const;\n"],"names":[],"mappings":";;AAAO,MAAM,SAAS,GAAG;AAClB,MAAM,YAAY,GAAG;AACrB,MAAM,aAAa,GAAG;AACtB,MAAM,SAAS,GAAG;;;;;;;"}
1
+ {"version":3,"file":"strings.cjs","names":[],"sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\nexport const LEFT_BRACKET = '-{LEFT_BRACKET}-' as const;\nexport const RIGHT_BRACKET = '-{RIGHT_BRACKET}-' as const;\nexport const SEPARATOR = '.' as const;\n"],"mappings":";;AAAA,MAAa,YAAY;AACzB,MAAa,eAAe;AAC5B,MAAa,gBAAgB;AAC7B,MAAa,YAAY"}
@@ -1,7 +1,9 @@
1
- const DELIMITER = '-{/./:}-';
2
- const LEFT_BRACKET = '-{LEFT_BRACKET}-';
3
- const RIGHT_BRACKET = '-{RIGHT_BRACKET}-';
4
- const SEPARATOR = '.';
5
-
1
+ //#region src/constants/strings.ts
2
+ const DELIMITER = "-{/./:}-";
3
+ const LEFT_BRACKET = "-{LEFT_BRACKET}-";
4
+ const RIGHT_BRACKET = "-{RIGHT_BRACKET}-";
5
+ const SEPARATOR = ".";
6
+ //#endregion
6
7
  export { DELIMITER, LEFT_BRACKET, RIGHT_BRACKET, SEPARATOR };
7
- //# sourceMappingURL=strings.js.map
8
+
9
+ //# sourceMappingURL=strings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.js","sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\nexport const LEFT_BRACKET = '-{LEFT_BRACKET}-' as const;\nexport const RIGHT_BRACKET = '-{RIGHT_BRACKET}-' as const;\nexport const SEPARATOR = '.' as const;\n"],"names":[],"mappings":"AAAO,MAAM,SAAS,GAAG;AAClB,MAAM,YAAY,GAAG;AACrB,MAAM,aAAa,GAAG;AACtB,MAAM,SAAS,GAAG;;;;"}
1
+ {"version":3,"file":"strings.js","names":[],"sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\nexport const LEFT_BRACKET = '-{LEFT_BRACKET}-' as const;\nexport const RIGHT_BRACKET = '-{RIGHT_BRACKET}-' as const;\nexport const SEPARATOR = '.' as const;\n"],"mappings":";AAAA,MAAa,YAAY;AACzB,MAAa,eAAe;AAC5B,MAAa,gBAAgB;AAC7B,MAAa,YAAY"}
@@ -1,46 +1,42 @@
1
- 'use strict';
2
-
3
- var helpers = require('../helpers.cjs');
4
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_helpers = require("../helpers.cjs");
3
+ //#region src/contexts/assign.ts
5
4
  const _assignByKey = (obj, key, value) => {
6
- const segments = helpers.splitKey(key);
7
- const [first, ...rest] = segments;
8
- const out = obj ?? helpers.nextDefault(first);
9
- if (rest.length === 0) {
10
- if (helpers.isArrayIndex(first)) {
11
- out[helpers.parseIndex(first)] = value;
12
- }
13
- else {
14
- out[first] = value;
15
- }
16
- return out;
17
- }
18
- const nextKey = rest.join('.');
19
- const next = rest[0];
20
- const _nextDefault = helpers.nextDefault(next);
21
- if (helpers.isArrayIndex(first)) {
22
- const idx = helpers.parseIndex(first);
23
- out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
24
- }
25
- else {
26
- out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
27
- }
28
- return out;
5
+ const [first, ...rest] = require_helpers.splitKey(key);
6
+ const out = obj ?? require_helpers.nextDefault(first);
7
+ if (rest.length === 0) {
8
+ if (require_helpers.isArrayIndex(first)) {
9
+ let idx = require_helpers.parseIndex(first);
10
+ if (idx > out.length) idx = out.length;
11
+ out[idx] = value;
12
+ } else out[first] = value;
13
+ return out;
14
+ }
15
+ const nextKey = rest.join(".");
16
+ const next = rest[0];
17
+ const _nextDefault = require_helpers.nextDefault(next);
18
+ if (require_helpers.isArrayIndex(first)) {
19
+ let idx = require_helpers.parseIndex(first);
20
+ if (idx > out.length) idx = out.length;
21
+ out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
22
+ } else out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
23
+ return out;
29
24
  };
30
25
  /**
31
- * Assigns a value to a path in an object.
32
- * @param obj The object to assign the value to
33
- * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')
34
- * @param value The value to assign to the key
35
- * @returns The modified object with the value assigned to the specified key
36
- *
37
- * @see {@linkcode Decompose} for more details on object decomposition.
38
- */
26
+ * Assigns a value to a path in an object.
27
+ * @param obj The object to assign the value to
28
+ * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')
29
+ * @param value The value to assign to the key
30
+ * @returns The modified object with the value assigned to the specified key
31
+ *
32
+ * @see {@linkcode Decompose} for more details on object decomposition.
33
+ */
39
34
  const assignByKey = (obj, path, value) => {
40
- return _assignByKey(obj, path, value);
35
+ return _assignByKey(obj, path, value);
41
36
  };
42
37
  assignByKey.low = assignByKey;
43
38
  assignByKey.typed = assignByKey;
44
-
39
+ //#endregion
45
40
  exports.assignByKey = assignByKey;
46
- //# sourceMappingURL=assign.cjs.map
41
+
42
+ //# sourceMappingURL=assign.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"assign.cjs","sources":["../../src/contexts/assign.ts"],"sourcesContent":["import {\n isArrayIndex,\n nextDefault,\n parseIndex,\n splitKey,\n} from '../helpers';\nimport type { Decompose, Ru } from '../types.types';\nimport type { DEFAULT_OPTIONS } from './constants';\n\n// #region type AssignByBey_F\nexport type AssignByBey_F = <\n T extends Ru,\n D extends Decompose<T, typeof DEFAULT_OPTIONS>,\n K extends Extract<keyof D, string>,\n R extends D[K],\n>(\n obj: T,\n key: K,\n value: R,\n) => T;\n// #endregion\n\nexport interface AssignByKey {\n (obj: any, key: string, value: any): any;\n low: (obj: any, key: string, value: any) => any;\n typed: AssignByBey_F;\n}\n\nconst _assignByKey: AssignByKey['low'] = (obj, key, value) => {\n const segments = splitKey(key);\n\n const [first, ...rest] = segments;\n const out: any = obj ?? nextDefault(first);\n\n if (rest.length === 0) {\n if (isArrayIndex(first)) {\n out[parseIndex(first)] = value;\n } else {\n out[first] = value;\n }\n return out;\n }\n\n const nextKey = rest.join('.');\n const next = rest[0];\n const _nextDefault = nextDefault(next);\n\n if (isArrayIndex(first)) {\n const idx = parseIndex(first);\n out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);\n } else {\n out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);\n }\n\n return out;\n};\n\n/**\n * Assigns a value to a path in an object.\n * @param obj The object to assign the value to\n * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')\n * @param value The value to assign to the key\n * @returns The modified object with the value assigned to the specified key\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const assignByKey: AssignByKey = (obj, path, value) => {\n return _assignByKey(obj, path, value);\n};\n\nassignByKey.low = assignByKey;\nassignByKey.typed = assignByKey;\n"],"names":["splitKey","nextDefault","isArrayIndex","parseIndex"],"mappings":";;;;AA4BA,MAAM,YAAY,GAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAI;AAC3D,IAAA,MAAM,QAAQ,GAAGA,gBAAQ,CAAC,GAAG,CAAC;IAE9B,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ;IACjC,MAAM,GAAG,GAAQ,GAAG,IAAIC,mBAAW,CAAC,KAAK,CAAC;AAE1C,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,IAAIC,oBAAY,CAAC,KAAK,CAAC,EAAE;YACvB,GAAG,CAACC,kBAAU,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK;QAChC;aAAO;AACL,YAAA,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK;QACpB;AACA,QAAA,OAAO,GAAG;IACZ;IAEA,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;AACpB,IAAA,MAAM,YAAY,GAAGF,mBAAW,CAAC,IAAI,CAAC;AAEtC,IAAA,IAAIC,oBAAY,CAAC,KAAK,CAAC,EAAE;AACvB,QAAA,MAAM,GAAG,GAAGC,kBAAU,CAAC,KAAK,CAAC;AAC7B,QAAA,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC;IACnE;SAAO;AACL,QAAA,GAAG,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC;IACvE;AAEA,IAAA,OAAO,GAAG;AACZ,CAAC;AAED;;;;;;;;AAQG;AACI,MAAM,WAAW,GAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,KAAI;IAC3D,OAAO,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;AACvC;AAEA,WAAW,CAAC,GAAG,GAAG,WAAW;AAC7B,WAAW,CAAC,KAAK,GAAG,WAAW;;;;"}
1
+ {"version":3,"file":"assign.cjs","names":["splitKey","nextDefault","isArrayIndex","parseIndex"],"sources":["../../src/contexts/assign.ts"],"sourcesContent":["import {\n isArrayIndex,\n nextDefault,\n parseIndex,\n splitKey,\n} from '../helpers';\nimport type { Decompose, Ru } from '../types.types';\nimport type { DEFAULT_OPTIONS } from './constants';\n\n// #region type AssignByBey_F\nexport type AssignByBey_F = <\n T extends Ru,\n D extends Decompose<T, typeof DEFAULT_OPTIONS>,\n K extends Extract<keyof D, string>,\n R extends D[K],\n>(\n obj: T,\n key: K,\n value: R,\n) => T;\n// #endregion\n\nexport interface AssignByKey {\n (obj: any, key: string, value: any): any;\n low: (obj: any, key: string, value: any) => any;\n typed: AssignByBey_F;\n}\n\nconst _assignByKey: AssignByKey['low'] = (obj, key, value) => {\n const segments = splitKey(key);\n\n const [first, ...rest] = segments;\n const out: any = obj ?? nextDefault(first);\n\n if (rest.length === 0) {\n if (isArrayIndex(first)) {\n let idx = parseIndex(first);\n if (idx > out.length) idx = out.length;\n out[idx] = value;\n } else {\n out[first] = value;\n }\n return out;\n }\n\n const nextKey = rest.join('.');\n const next = rest[0];\n const _nextDefault = nextDefault(next);\n\n if (isArrayIndex(first)) {\n let idx = parseIndex(first);\n if (idx > out.length) idx = out.length;\n out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);\n } else {\n out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);\n }\n\n return out;\n};\n\n/**\n * Assigns a value to a path in an object.\n * @param obj The object to assign the value to\n * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')\n * @param value The value to assign to the key\n * @returns The modified object with the value assigned to the specified key\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const assignByKey: AssignByKey = (obj, path, value) => {\n return _assignByKey(obj, path, value);\n};\n\nassignByKey.low = assignByKey;\nassignByKey.typed = assignByKey;\n"],"mappings":";;;AA4BA,MAAM,gBAAoC,KAAK,KAAK,UAAU;CAG5D,MAAM,CAAC,OAAO,GAAG,QAFAA,gBAAAA,SAAS,IAAI;CAG9B,MAAM,MAAW,OAAOC,gBAAAA,YAAY,MAAM;AAE1C,KAAI,KAAK,WAAW,GAAG;AACrB,MAAIC,gBAAAA,aAAa,MAAM,EAAE;GACvB,IAAI,MAAMC,gBAAAA,WAAW,MAAM;AAC3B,OAAI,MAAM,IAAI,OAAQ,OAAM,IAAI;AAChC,OAAI,OAAO;QAEX,KAAI,SAAS;AAEf,SAAO;;CAGT,MAAM,UAAU,KAAK,KAAK,IAAI;CAC9B,MAAM,OAAO,KAAK;CAClB,MAAM,eAAeF,gBAAAA,YAAY,KAAK;AAEtC,KAAIC,gBAAAA,aAAa,MAAM,EAAE;EACvB,IAAI,MAAMC,gBAAAA,WAAW,MAAM;AAC3B,MAAI,MAAM,IAAI,OAAQ,OAAM,IAAI;AAChC,MAAI,OAAO,aAAa,IAAI,QAAQ,cAAc,SAAS,MAAM;OAEjE,KAAI,SAAS,aAAa,IAAI,UAAU,cAAc,SAAS,MAAM;AAGvE,QAAO;;;;;;;;;;;AAYT,MAAa,eAA4B,KAAK,MAAM,UAAU;AAC5D,QAAO,aAAa,KAAK,MAAM,MAAM;;AAGvC,YAAY,MAAM;AAClB,YAAY,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../../src/contexts/assign.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,MAAM,MAAM,aAAa,GAAG,CAC1B,CAAC,SAAS,EAAE,EACZ,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,OAAO,eAAe,CAAC,EAC9C,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAClC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAEd,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,CAAC,KACL,CAAC,CAAC;AAGP,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IACzC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;IAChD,KAAK,EAAE,aAAa,CAAC;CACtB;AA+BD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,EAAE,WAEzB,CAAC"}
1
+ {"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../../src/contexts/assign.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,MAAM,MAAM,aAAa,GAAG,CAC1B,CAAC,SAAS,EAAE,EACZ,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,OAAO,eAAe,CAAC,EAC9C,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAClC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAEd,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,CAAC,KACL,CAAC,CAAC;AAGP,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IACzC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;IAChD,KAAK,EAAE,aAAa,CAAC;CACtB;AAkCD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,EAAE,WAEzB,CAAC"}
@@ -1,44 +1,41 @@
1
- import { splitKey, isArrayIndex, parseIndex, nextDefault } from '../helpers.js';
2
-
1
+ import { isArrayIndex, nextDefault, parseIndex, splitKey } from "../helpers.js";
2
+ //#region src/contexts/assign.ts
3
3
  const _assignByKey = (obj, key, value) => {
4
- const segments = splitKey(key);
5
- const [first, ...rest] = segments;
6
- const out = obj ?? nextDefault(first);
7
- if (rest.length === 0) {
8
- if (isArrayIndex(first)) {
9
- out[parseIndex(first)] = value;
10
- }
11
- else {
12
- out[first] = value;
13
- }
14
- return out;
15
- }
16
- const nextKey = rest.join('.');
17
- const next = rest[0];
18
- const _nextDefault = nextDefault(next);
19
- if (isArrayIndex(first)) {
20
- const idx = parseIndex(first);
21
- out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
22
- }
23
- else {
24
- out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
25
- }
26
- return out;
4
+ const [first, ...rest] = splitKey(key);
5
+ const out = obj ?? nextDefault(first);
6
+ if (rest.length === 0) {
7
+ if (isArrayIndex(first)) {
8
+ let idx = parseIndex(first);
9
+ if (idx > out.length) idx = out.length;
10
+ out[idx] = value;
11
+ } else out[first] = value;
12
+ return out;
13
+ }
14
+ const nextKey = rest.join(".");
15
+ const next = rest[0];
16
+ const _nextDefault = nextDefault(next);
17
+ if (isArrayIndex(first)) {
18
+ let idx = parseIndex(first);
19
+ if (idx > out.length) idx = out.length;
20
+ out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
21
+ } else out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
22
+ return out;
27
23
  };
28
24
  /**
29
- * Assigns a value to a path in an object.
30
- * @param obj The object to assign the value to
31
- * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')
32
- * @param value The value to assign to the key
33
- * @returns The modified object with the value assigned to the specified key
34
- *
35
- * @see {@linkcode Decompose} for more details on object decomposition.
36
- */
25
+ * Assigns a value to a path in an object.
26
+ * @param obj The object to assign the value to
27
+ * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')
28
+ * @param value The value to assign to the key
29
+ * @returns The modified object with the value assigned to the specified key
30
+ *
31
+ * @see {@linkcode Decompose} for more details on object decomposition.
32
+ */
37
33
  const assignByKey = (obj, path, value) => {
38
- return _assignByKey(obj, path, value);
34
+ return _assignByKey(obj, path, value);
39
35
  };
40
36
  assignByKey.low = assignByKey;
41
37
  assignByKey.typed = assignByKey;
42
-
38
+ //#endregion
43
39
  export { assignByKey };
44
- //# sourceMappingURL=assign.js.map
40
+
41
+ //# sourceMappingURL=assign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assign.js","sources":["../../src/contexts/assign.ts"],"sourcesContent":["import {\n isArrayIndex,\n nextDefault,\n parseIndex,\n splitKey,\n} from '../helpers';\nimport type { Decompose, Ru } from '../types.types';\nimport type { DEFAULT_OPTIONS } from './constants';\n\n// #region type AssignByBey_F\nexport type AssignByBey_F = <\n T extends Ru,\n D extends Decompose<T, typeof DEFAULT_OPTIONS>,\n K extends Extract<keyof D, string>,\n R extends D[K],\n>(\n obj: T,\n key: K,\n value: R,\n) => T;\n// #endregion\n\nexport interface AssignByKey {\n (obj: any, key: string, value: any): any;\n low: (obj: any, key: string, value: any) => any;\n typed: AssignByBey_F;\n}\n\nconst _assignByKey: AssignByKey['low'] = (obj, key, value) => {\n const segments = splitKey(key);\n\n const [first, ...rest] = segments;\n const out: any = obj ?? nextDefault(first);\n\n if (rest.length === 0) {\n if (isArrayIndex(first)) {\n out[parseIndex(first)] = value;\n } else {\n out[first] = value;\n }\n return out;\n }\n\n const nextKey = rest.join('.');\n const next = rest[0];\n const _nextDefault = nextDefault(next);\n\n if (isArrayIndex(first)) {\n const idx = parseIndex(first);\n out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);\n } else {\n out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);\n }\n\n return out;\n};\n\n/**\n * Assigns a value to a path in an object.\n * @param obj The object to assign the value to\n * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')\n * @param value The value to assign to the key\n * @returns The modified object with the value assigned to the specified key\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const assignByKey: AssignByKey = (obj, path, value) => {\n return _assignByKey(obj, path, value);\n};\n\nassignByKey.low = assignByKey;\nassignByKey.typed = assignByKey;\n"],"names":[],"mappings":";;AA4BA,MAAM,YAAY,GAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAI;AAC3D,IAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC;IAE9B,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ;IACjC,MAAM,GAAG,GAAQ,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC;AAE1C,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;YACvB,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK;QAChC;aAAO;AACL,YAAA,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK;QACpB;AACA,QAAA,OAAO,GAAG;IACZ;IAEA,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;AACpB,IAAA,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC;AAEtC,IAAA,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;AACvB,QAAA,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC;AAC7B,QAAA,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC;IACnE;SAAO;AACL,QAAA,GAAG,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC;IACvE;AAEA,IAAA,OAAO,GAAG;AACZ,CAAC;AAED;;;;;;;;AAQG;AACI,MAAM,WAAW,GAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,KAAI;IAC3D,OAAO,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;AACvC;AAEA,WAAW,CAAC,GAAG,GAAG,WAAW;AAC7B,WAAW,CAAC,KAAK,GAAG,WAAW;;;;"}
1
+ {"version":3,"file":"assign.js","names":[],"sources":["../../src/contexts/assign.ts"],"sourcesContent":["import {\n isArrayIndex,\n nextDefault,\n parseIndex,\n splitKey,\n} from '../helpers';\nimport type { Decompose, Ru } from '../types.types';\nimport type { DEFAULT_OPTIONS } from './constants';\n\n// #region type AssignByBey_F\nexport type AssignByBey_F = <\n T extends Ru,\n D extends Decompose<T, typeof DEFAULT_OPTIONS>,\n K extends Extract<keyof D, string>,\n R extends D[K],\n>(\n obj: T,\n key: K,\n value: R,\n) => T;\n// #endregion\n\nexport interface AssignByKey {\n (obj: any, key: string, value: any): any;\n low: (obj: any, key: string, value: any) => any;\n typed: AssignByBey_F;\n}\n\nconst _assignByKey: AssignByKey['low'] = (obj, key, value) => {\n const segments = splitKey(key);\n\n const [first, ...rest] = segments;\n const out: any = obj ?? nextDefault(first);\n\n if (rest.length === 0) {\n if (isArrayIndex(first)) {\n let idx = parseIndex(first);\n if (idx > out.length) idx = out.length;\n out[idx] = value;\n } else {\n out[first] = value;\n }\n return out;\n }\n\n const nextKey = rest.join('.');\n const next = rest[0];\n const _nextDefault = nextDefault(next);\n\n if (isArrayIndex(first)) {\n let idx = parseIndex(first);\n if (idx > out.length) idx = out.length;\n out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);\n } else {\n out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);\n }\n\n return out;\n};\n\n/**\n * Assigns a value to a path in an object.\n * @param obj The object to assign the value to\n * @param path The key to assign the value to, can be a nested key (e.g. 'a.b.c')\n * @param value The value to assign to the key\n * @returns The modified object with the value assigned to the specified key\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const assignByKey: AssignByKey = (obj, path, value) => {\n return _assignByKey(obj, path, value);\n};\n\nassignByKey.low = assignByKey;\nassignByKey.typed = assignByKey;\n"],"mappings":";;AA4BA,MAAM,gBAAoC,KAAK,KAAK,UAAU;CAG5D,MAAM,CAAC,OAAO,GAAG,QAFA,SAAS,IAAI;CAG9B,MAAM,MAAW,OAAO,YAAY,MAAM;AAE1C,KAAI,KAAK,WAAW,GAAG;AACrB,MAAI,aAAa,MAAM,EAAE;GACvB,IAAI,MAAM,WAAW,MAAM;AAC3B,OAAI,MAAM,IAAI,OAAQ,OAAM,IAAI;AAChC,OAAI,OAAO;QAEX,KAAI,SAAS;AAEf,SAAO;;CAGT,MAAM,UAAU,KAAK,KAAK,IAAI;CAC9B,MAAM,OAAO,KAAK;CAClB,MAAM,eAAe,YAAY,KAAK;AAEtC,KAAI,aAAa,MAAM,EAAE;EACvB,IAAI,MAAM,WAAW,MAAM;AAC3B,MAAI,MAAM,IAAI,OAAQ,OAAM,IAAI;AAChC,MAAI,OAAO,aAAa,IAAI,QAAQ,cAAc,SAAS,MAAM;OAEjE,KAAI,SAAS,aAAa,IAAI,UAAU,cAAc,SAAS,MAAM;AAGvE,QAAO;;;;;;;;;;;AAYT,MAAa,eAA4B,KAAK,MAAM,UAAU;AAC5D,QAAO,aAAa,KAAK,MAAM,MAAM;;AAGvC,YAAY,MAAM;AAClB,YAAY,QAAQ"}
@@ -1,10 +1,11 @@
1
- 'use strict';
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/contexts/constants.ts
3
3
  const DEFAULT_OPTIONS = {
4
- start: false,
5
- sep: '.',
6
- object: 'both',
4
+ start: false,
5
+ sep: ".",
6
+ object: "both"
7
7
  };
8
-
8
+ //#endregion
9
9
  exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
10
- //# sourceMappingURL=constants.cjs.map
10
+
11
+ //# sourceMappingURL=constants.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../src/contexts/constants.ts"],"sourcesContent":["import type { DecomposeOptions } from '../types.types';\n\nexport const DEFAULT_OPTIONS = {\n start: false,\n sep: '.',\n object: 'both',\n} as const satisfies DecomposeOptions;\n"],"names":[],"mappings":";;AAEO,MAAM,eAAe,GAAG;AAC7B,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,MAAM,EAAE,MAAM;;;;;"}
1
+ {"version":3,"file":"constants.cjs","names":[],"sources":["../../src/contexts/constants.ts"],"sourcesContent":["import type { DecomposeOptions } from '../types.types';\n\nexport const DEFAULT_OPTIONS = {\n start: false,\n sep: '.',\n object: 'both',\n} as const satisfies DecomposeOptions;\n"],"mappings":";;AAEA,MAAa,kBAAkB;CAC7B,OAAO;CACP,KAAK;CACL,QAAQ;CACT"}
@@ -1,8 +1,10 @@
1
+ //#region src/contexts/constants.ts
1
2
  const DEFAULT_OPTIONS = {
2
- start: false,
3
- sep: '.',
4
- object: 'both',
3
+ start: false,
4
+ sep: ".",
5
+ object: "both"
5
6
  };
6
-
7
+ //#endregion
7
8
  export { DEFAULT_OPTIONS };
8
- //# sourceMappingURL=constants.js.map
9
+
10
+ //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../src/contexts/constants.ts"],"sourcesContent":["import type { DecomposeOptions } from '../types.types';\n\nexport const DEFAULT_OPTIONS = {\n start: false,\n sep: '.',\n object: 'both',\n} as const satisfies DecomposeOptions;\n"],"names":[],"mappings":"AAEO,MAAM,eAAe,GAAG;AAC7B,IAAA,KAAK,EAAE,KAAK;AACZ,IAAA,GAAG,EAAE,GAAG;AACR,IAAA,MAAM,EAAE,MAAM;;;;;"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../src/contexts/constants.ts"],"sourcesContent":["import type { DecomposeOptions } from '../types.types';\n\nexport const DEFAULT_OPTIONS = {\n start: false,\n sep: '.',\n object: 'both',\n} as const satisfies DecomposeOptions;\n"],"mappings":";AAEA,MAAa,kBAAkB;CAC7B,OAAO;CACP,KAAK;CACL,QAAQ;CACT"}
@@ -1,31 +1,29 @@
1
- 'use strict';
2
-
3
- var contexts_constants = require('./constants.cjs');
4
- var decompose = require('../decompose.cjs');
5
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_decompose = require("../decompose.cjs");
3
+ const require_contexts_constants = require("./constants.cjs");
4
+ //#region src/contexts/get.ts
6
5
  const _getByKey = (obj, key) => {
7
- const decomposed = decompose.decompose.low(obj, contexts_constants.DEFAULT_OPTIONS);
8
- return decomposed[key];
6
+ return require_decompose.decompose.low(obj, require_contexts_constants.DEFAULT_OPTIONS)[key];
9
7
  };
10
8
  /**
11
- * Retrieves a value from an object by a specified key.
12
- * @param obj The object to retrieve the value from
13
- * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')
14
- * @returns The value associated with the specified key in the object
15
- *
16
- * @see {@linkcode Decompose} for more details on object decomposition.
17
- */
9
+ * Retrieves a value from an object by a specified key.
10
+ * @param obj The object to retrieve the value from
11
+ * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')
12
+ * @returns The value associated with the specified key in the object
13
+ *
14
+ * @see {@linkcode Decompose} for more details on object decomposition.
15
+ */
18
16
  const getByKey = (obj, key) => _getByKey(obj, key);
19
17
  getByKey.low = getByKey;
20
18
  getByKey.typed = getByKey;
21
19
  getByKey.defined = getByKey;
22
- getByKey.options = options => (obj, key) => {
23
- const decomposed = decompose.decompose.low(obj, {
24
- ...contexts_constants.DEFAULT_OPTIONS,
25
- ...options,
26
- });
27
- return decomposed[key];
20
+ getByKey.options = (options) => (obj, key) => {
21
+ return require_decompose.decompose.low(obj, {
22
+ ...require_contexts_constants.DEFAULT_OPTIONS,
23
+ ...options
24
+ })[key];
28
25
  };
29
-
26
+ //#endregion
30
27
  exports.getByKey = getByKey;
31
- //# sourceMappingURL=get.cjs.map
28
+
29
+ //# sourceMappingURL=get.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"get.cjs","sources":["../../src/contexts/get.ts"],"sourcesContent":["import { DEFAULT_OPTIONS } from './constants';\nimport { decompose } from '../decompose';\nimport type { Decompose, DecomposeOptions, Ru } from '../types.types';\nimport type { NotUndefined } from '@bemedev/types/lib/types/commons.types';\n\n// #region type GetByKey_F\nexport type GetByKey_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, typeof DEFAULT_OPTIONS>[K];\nexport type GetByKeyDefined_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => NotUndefined<Decompose<T, typeof DEFAULT_OPTIONS>[K]>;\n\nexport type GetByKeyOption_F = <\n const O extends DecomposeOptions = typeof DEFAULT_OPTIONS,\n>(\n val: O,\n) => <const T extends Ru, const K extends keyof Decompose<T, O>>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, O>[K];\n// #endregion\n\nexport interface GetByKey {\n (obj: any, key: string): any;\n low: (obj: any, key: string) => any;\n typed: GetByKey_F;\n defined: GetByKeyDefined_F;\n options: GetByKeyOption_F;\n}\n\nconst _getByKey: GetByKey['low'] = (obj, key) => {\n const decomposed = decompose.low(obj, DEFAULT_OPTIONS);\n return (decomposed as any)[key];\n};\n\n/**\n * Retrieves a value from an object by a specified key.\n * @param obj The object to retrieve the value from\n * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')\n * @returns The value associated with the specified key in the object\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const getByKey: GetByKey = (obj, key) => _getByKey(obj, key);\n\ngetByKey.low = getByKey;\ngetByKey.typed = getByKey;\ngetByKey.defined = getByKey;\n\ngetByKey.options = options => (obj, key) => {\n const decomposed = decompose.low(obj, {\n ...DEFAULT_OPTIONS,\n ...options,\n });\n return decomposed[key];\n};\n"],"names":["decompose","DEFAULT_OPTIONS"],"mappings":";;;;;AAuCA,MAAM,SAAS,GAAoB,CAAC,GAAG,EAAE,GAAG,KAAI;IAC9C,MAAM,UAAU,GAAGA,mBAAS,CAAC,GAAG,CAAC,GAAG,EAAEC,kCAAe,CAAC;AACtD,IAAA,OAAQ,UAAkB,CAAC,GAAG,CAAC;AACjC,CAAC;AAED;;;;;;;AAOG;AACI,MAAM,QAAQ,GAAa,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC,GAAG,EAAE,GAAG;AAElE,QAAQ,CAAC,GAAG,GAAG,QAAQ;AACvB,QAAQ,CAAC,KAAK,GAAG,QAAQ;AACzB,QAAQ,CAAC,OAAO,GAAG,QAAQ;AAE3B,QAAQ,CAAC,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAI;AACzC,IAAA,MAAM,UAAU,GAAGD,mBAAS,CAAC,GAAG,CAAC,GAAG,EAAE;AACpC,QAAA,GAAGC,kCAAe;AAClB,QAAA,GAAG,OAAO;AACX,KAAA,CAAC;AACF,IAAA,OAAO,UAAU,CAAC,GAAG,CAAC;AACxB,CAAC;;;;"}
1
+ {"version":3,"file":"get.cjs","names":["decompose","DEFAULT_OPTIONS"],"sources":["../../src/contexts/get.ts"],"sourcesContent":["import { DEFAULT_OPTIONS } from './constants';\nimport { decompose } from '../decompose';\nimport type { Decompose, DecomposeOptions, Ru } from '../types.types';\nimport type { NotUndefined } from '@bemedev/types/lib/types/commons.types';\n\n// #region type GetByKey_F\nexport type GetByKey_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, typeof DEFAULT_OPTIONS>[K];\nexport type GetByKeyDefined_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => NotUndefined<Decompose<T, typeof DEFAULT_OPTIONS>[K]>;\n\nexport type GetByKeyOption_F = <\n const O extends DecomposeOptions = typeof DEFAULT_OPTIONS,\n>(\n val: O,\n) => <const T extends Ru, const K extends keyof Decompose<T, O>>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, O>[K];\n// #endregion\n\nexport interface GetByKey {\n (obj: any, key: string): any;\n low: (obj: any, key: string) => any;\n typed: GetByKey_F;\n defined: GetByKeyDefined_F;\n options: GetByKeyOption_F;\n}\n\nconst _getByKey: GetByKey['low'] = (obj, key) => {\n const decomposed = decompose.low(obj, DEFAULT_OPTIONS);\n return (decomposed as any)[key];\n};\n\n/**\n * Retrieves a value from an object by a specified key.\n * @param obj The object to retrieve the value from\n * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')\n * @returns The value associated with the specified key in the object\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const getByKey: GetByKey = (obj, key) => _getByKey(obj, key);\n\ngetByKey.low = getByKey;\ngetByKey.typed = getByKey;\ngetByKey.defined = getByKey;\n\ngetByKey.options = options => (obj, key) => {\n const decomposed = decompose.low(obj, {\n ...DEFAULT_OPTIONS,\n ...options,\n });\n return decomposed[key];\n};\n"],"mappings":";;;;AAuCA,MAAM,aAA8B,KAAK,QAAQ;AAE/C,QADmBA,kBAAAA,UAAU,IAAI,KAAKC,2BAAAA,gBAAgB,CAC3B;;;;;;;;;;AAW7B,MAAa,YAAsB,KAAK,QAAQ,UAAU,KAAK,IAAI;AAEnE,SAAS,MAAM;AACf,SAAS,QAAQ;AACjB,SAAS,UAAU;AAEnB,SAAS,WAAU,aAAY,KAAK,QAAQ;AAK1C,QAJmBD,kBAAAA,UAAU,IAAI,KAAK;EACpC,GAAGC,2BAAAA;EACH,GAAG;EACJ,CAAC,CACgB"}
@@ -1,29 +1,28 @@
1
- import { DEFAULT_OPTIONS } from './constants.js';
2
- import { decompose } from '../decompose.js';
3
-
1
+ import { decompose } from "../decompose.js";
2
+ import { DEFAULT_OPTIONS } from "./constants.js";
3
+ //#region src/contexts/get.ts
4
4
  const _getByKey = (obj, key) => {
5
- const decomposed = decompose.low(obj, DEFAULT_OPTIONS);
6
- return decomposed[key];
5
+ return decompose.low(obj, DEFAULT_OPTIONS)[key];
7
6
  };
8
7
  /**
9
- * Retrieves a value from an object by a specified key.
10
- * @param obj The object to retrieve the value from
11
- * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')
12
- * @returns The value associated with the specified key in the object
13
- *
14
- * @see {@linkcode Decompose} for more details on object decomposition.
15
- */
8
+ * Retrieves a value from an object by a specified key.
9
+ * @param obj The object to retrieve the value from
10
+ * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')
11
+ * @returns The value associated with the specified key in the object
12
+ *
13
+ * @see {@linkcode Decompose} for more details on object decomposition.
14
+ */
16
15
  const getByKey = (obj, key) => _getByKey(obj, key);
17
16
  getByKey.low = getByKey;
18
17
  getByKey.typed = getByKey;
19
18
  getByKey.defined = getByKey;
20
- getByKey.options = options => (obj, key) => {
21
- const decomposed = decompose.low(obj, {
22
- ...DEFAULT_OPTIONS,
23
- ...options,
24
- });
25
- return decomposed[key];
19
+ getByKey.options = (options) => (obj, key) => {
20
+ return decompose.low(obj, {
21
+ ...DEFAULT_OPTIONS,
22
+ ...options
23
+ })[key];
26
24
  };
27
-
25
+ //#endregion
28
26
  export { getByKey };
29
- //# sourceMappingURL=get.js.map
27
+
28
+ //# sourceMappingURL=get.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sources":["../../src/contexts/get.ts"],"sourcesContent":["import { DEFAULT_OPTIONS } from './constants';\nimport { decompose } from '../decompose';\nimport type { Decompose, DecomposeOptions, Ru } from '../types.types';\nimport type { NotUndefined } from '@bemedev/types/lib/types/commons.types';\n\n// #region type GetByKey_F\nexport type GetByKey_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, typeof DEFAULT_OPTIONS>[K];\nexport type GetByKeyDefined_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => NotUndefined<Decompose<T, typeof DEFAULT_OPTIONS>[K]>;\n\nexport type GetByKeyOption_F = <\n const O extends DecomposeOptions = typeof DEFAULT_OPTIONS,\n>(\n val: O,\n) => <const T extends Ru, const K extends keyof Decompose<T, O>>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, O>[K];\n// #endregion\n\nexport interface GetByKey {\n (obj: any, key: string): any;\n low: (obj: any, key: string) => any;\n typed: GetByKey_F;\n defined: GetByKeyDefined_F;\n options: GetByKeyOption_F;\n}\n\nconst _getByKey: GetByKey['low'] = (obj, key) => {\n const decomposed = decompose.low(obj, DEFAULT_OPTIONS);\n return (decomposed as any)[key];\n};\n\n/**\n * Retrieves a value from an object by a specified key.\n * @param obj The object to retrieve the value from\n * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')\n * @returns The value associated with the specified key in the object\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const getByKey: GetByKey = (obj, key) => _getByKey(obj, key);\n\ngetByKey.low = getByKey;\ngetByKey.typed = getByKey;\ngetByKey.defined = getByKey;\n\ngetByKey.options = options => (obj, key) => {\n const decomposed = decompose.low(obj, {\n ...DEFAULT_OPTIONS,\n ...options,\n });\n return decomposed[key];\n};\n"],"names":[],"mappings":";;;AAuCA,MAAM,SAAS,GAAoB,CAAC,GAAG,EAAE,GAAG,KAAI;IAC9C,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC;AACtD,IAAA,OAAQ,UAAkB,CAAC,GAAG,CAAC;AACjC,CAAC;AAED;;;;;;;AAOG;AACI,MAAM,QAAQ,GAAa,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC,GAAG,EAAE,GAAG;AAElE,QAAQ,CAAC,GAAG,GAAG,QAAQ;AACvB,QAAQ,CAAC,KAAK,GAAG,QAAQ;AACzB,QAAQ,CAAC,OAAO,GAAG,QAAQ;AAE3B,QAAQ,CAAC,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAI;AACzC,IAAA,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE;AACpC,QAAA,GAAG,eAAe;AAClB,QAAA,GAAG,OAAO;AACX,KAAA,CAAC;AACF,IAAA,OAAO,UAAU,CAAC,GAAG,CAAC;AACxB,CAAC;;;;"}
1
+ {"version":3,"file":"get.js","names":[],"sources":["../../src/contexts/get.ts"],"sourcesContent":["import { DEFAULT_OPTIONS } from './constants';\nimport { decompose } from '../decompose';\nimport type { Decompose, DecomposeOptions, Ru } from '../types.types';\nimport type { NotUndefined } from '@bemedev/types/lib/types/commons.types';\n\n// #region type GetByKey_F\nexport type GetByKey_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, typeof DEFAULT_OPTIONS>[K];\nexport type GetByKeyDefined_F = <\n const T extends Ru,\n const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>,\n>(\n obj: T,\n key: Extract<K, string>,\n) => NotUndefined<Decompose<T, typeof DEFAULT_OPTIONS>[K]>;\n\nexport type GetByKeyOption_F = <\n const O extends DecomposeOptions = typeof DEFAULT_OPTIONS,\n>(\n val: O,\n) => <const T extends Ru, const K extends keyof Decompose<T, O>>(\n obj: T,\n key: Extract<K, string>,\n) => Decompose<T, O>[K];\n// #endregion\n\nexport interface GetByKey {\n (obj: any, key: string): any;\n low: (obj: any, key: string) => any;\n typed: GetByKey_F;\n defined: GetByKeyDefined_F;\n options: GetByKeyOption_F;\n}\n\nconst _getByKey: GetByKey['low'] = (obj, key) => {\n const decomposed = decompose.low(obj, DEFAULT_OPTIONS);\n return (decomposed as any)[key];\n};\n\n/**\n * Retrieves a value from an object by a specified key.\n * @param obj The object to retrieve the value from\n * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')\n * @returns The value associated with the specified key in the object\n *\n * @see {@linkcode Decompose} for more details on object decomposition.\n */\nexport const getByKey: GetByKey = (obj, key) => _getByKey(obj, key);\n\ngetByKey.low = getByKey;\ngetByKey.typed = getByKey;\ngetByKey.defined = getByKey;\n\ngetByKey.options = options => (obj, key) => {\n const decomposed = decompose.low(obj, {\n ...DEFAULT_OPTIONS,\n ...options,\n });\n return decomposed[key];\n};\n"],"mappings":";;;AAuCA,MAAM,aAA8B,KAAK,QAAQ;AAE/C,QADmB,UAAU,IAAI,KAAK,gBAAgB,CAC3B;;;;;;;;;;AAW7B,MAAa,YAAsB,KAAK,QAAQ,UAAU,KAAK,IAAI;AAEnE,SAAS,MAAM;AACf,SAAS,QAAQ;AACjB,SAAS,UAAU;AAEnB,SAAS,WAAU,aAAY,KAAK,QAAQ;AAK1C,QAJmB,UAAU,IAAI,KAAK;EACpC,GAAG;EACH,GAAG;EACJ,CAAC,CACgB"}
@@ -1,10 +1,5 @@
1
- 'use strict';
2
-
3
- var contexts_assign = require('./assign.cjs');
4
- var contexts_get = require('./get.cjs');
5
-
6
-
7
-
8
- exports.assignByKey = contexts_assign.assignByKey;
9
- exports.getByKey = contexts_get.getByKey;
10
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_contexts_assign = require("./assign.cjs");
3
+ const require_contexts_get = require("./get.cjs");
4
+ exports.assignByKey = require_contexts_assign.assignByKey;
5
+ exports.getByKey = require_contexts_get.getByKey;
@@ -1,3 +1,3 @@
1
- export { assignByKey } from './assign.js';
2
- export { getByKey } from './get.js';
3
- //# sourceMappingURL=index.js.map
1
+ import { assignByKey } from "./assign.js";
2
+ import { getByKey } from "./get.js";
3
+ export { assignByKey, getByKey };