@bemedev/decompose 2.0.3 → 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.
- package/lib/constants/index.cjs +9 -14
- package/lib/constants/index.js +3 -3
- package/lib/constants/objects.cjs +10 -9
- package/lib/constants/objects.cjs.map +1 -1
- package/lib/constants/objects.js +9 -7
- package/lib/constants/objects.js.map +1 -1
- package/lib/constants/strings.cjs +9 -8
- package/lib/constants/strings.cjs.map +1 -1
- package/lib/constants/strings.js +8 -6
- package/lib/constants/strings.js.map +1 -1
- package/lib/contexts/assign.cjs +34 -43
- package/lib/contexts/assign.cjs.map +1 -1
- package/lib/contexts/assign.js +33 -41
- package/lib/contexts/assign.js.map +1 -1
- package/lib/contexts/constants.cjs +8 -7
- package/lib/contexts/constants.cjs.map +1 -1
- package/lib/contexts/constants.js +7 -5
- package/lib/contexts/constants.js.map +1 -1
- package/lib/contexts/get.cjs +20 -22
- package/lib/contexts/get.cjs.map +1 -1
- package/lib/contexts/get.js +19 -20
- package/lib/contexts/get.js.map +1 -1
- package/lib/contexts/index.cjs +5 -10
- package/lib/contexts/index.js +3 -3
- package/lib/decompose.cjs +53 -65
- package/lib/decompose.cjs.map +1 -1
- package/lib/decompose.js +52 -63
- package/lib/decompose.js.map +1 -1
- package/lib/decomposeKeys.cjs +27 -33
- package/lib/decomposeKeys.cjs.map +1 -1
- package/lib/decomposeKeys.js +25 -30
- package/lib/decomposeKeys.js.map +1 -1
- package/lib/decomposeSV.cjs +25 -28
- package/lib/decomposeSV.cjs.map +1 -1
- package/lib/decomposeSV.js +22 -24
- package/lib/decomposeSV.js.map +1 -1
- package/lib/flatByKey.cjs +26 -22
- package/lib/flatByKey.cjs.map +1 -1
- package/lib/flatByKey.js +25 -20
- package/lib/flatByKey.js.map +1 -1
- package/lib/helpers.cjs +10 -13
- package/lib/helpers.cjs.map +1 -1
- package/lib/helpers.js +9 -11
- package/lib/helpers.js.map +1 -1
- package/lib/index.cjs +27 -31
- package/lib/index.js +12 -11
- package/lib/recompose.cjs +43 -51
- package/lib/recompose.cjs.map +1 -1
- package/lib/recompose.js +42 -49
- package/lib/recompose.js.map +1 -1
- package/lib/sortMap.cjs +6 -5
- package/lib/sortMap.cjs.map +1 -1
- package/lib/sortMap.js +5 -3
- package/lib/sortMap.js.map +1 -1
- package/lib/types.types.d.ts +22 -11
- package/lib/types.types.d.ts.map +1 -1
- package/package.json +41 -33
- package/lib/constants/index.cjs.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/contexts/index.cjs.map +0 -1
- package/lib/contexts/index.js.map +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/constants/index.cjs
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
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;
|
package/lib/constants/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/constants/objects.ts
|
|
3
3
|
const DEFAULT_FLAT_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
sep: ".",
|
|
5
|
+
children: false
|
|
6
6
|
};
|
|
7
7
|
const DEFAULT_DECOMPOSE_OPTIONS = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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"],"
|
|
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"}
|
package/lib/constants/objects.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
//#region src/constants/objects.ts
|
|
1
2
|
const DEFAULT_FLAT_OPTIONS = {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
sep: ".",
|
|
4
|
+
children: false
|
|
4
5
|
};
|
|
5
6
|
const DEFAULT_DECOMPOSE_OPTIONS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
sep: ".",
|
|
8
|
+
object: "key",
|
|
9
|
+
start: true
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
11
12
|
export { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS };
|
|
12
|
-
|
|
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"],"
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
const DELIMITER =
|
|
4
|
-
const LEFT_BRACKET =
|
|
5
|
-
const 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
|
-
|
|
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"],"
|
|
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"}
|
package/lib/constants/strings.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
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
|
-
|
|
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"],"
|
|
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"}
|
package/lib/contexts/assign.cjs
CHANGED
|
@@ -1,51 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let idx = helpers.parseIndex(first);
|
|
26
|
-
if (idx > out.length)
|
|
27
|
-
idx = out.length;
|
|
28
|
-
out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
|
|
32
|
-
}
|
|
33
|
-
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;
|
|
34
24
|
};
|
|
35
25
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
*/
|
|
44
34
|
const assignByKey = (obj, path, value) => {
|
|
45
|
-
|
|
35
|
+
return _assignByKey(obj, path, value);
|
|
46
36
|
};
|
|
47
37
|
assignByKey.low = assignByKey;
|
|
48
38
|
assignByKey.typed = assignByKey;
|
|
49
|
-
|
|
39
|
+
//#endregion
|
|
50
40
|
exports.assignByKey = assignByKey;
|
|
51
|
-
|
|
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 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"],"
|
|
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"}
|
package/lib/contexts/assign.js
CHANGED
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { isArrayIndex, nextDefault, parseIndex, splitKey } from "../helpers.js";
|
|
2
|
+
//#region src/contexts/assign.ts
|
|
3
3
|
const _assignByKey = (obj, key, value) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let idx = parseIndex(first);
|
|
24
|
-
if (idx > out.length)
|
|
25
|
-
idx = out.length;
|
|
26
|
-
out[idx] = _assignByKey(out[idx] ?? _nextDefault, nextKey, value);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
out[first] = _assignByKey(out[first] ?? _nextDefault, nextKey, value);
|
|
30
|
-
}
|
|
31
|
-
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;
|
|
32
23
|
};
|
|
33
24
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
*/
|
|
42
33
|
const assignByKey = (obj, path, value) => {
|
|
43
|
-
|
|
34
|
+
return _assignByKey(obj, path, value);
|
|
44
35
|
};
|
|
45
36
|
assignByKey.low = assignByKey;
|
|
46
37
|
assignByKey.typed = assignByKey;
|
|
47
|
-
|
|
38
|
+
//#endregion
|
|
48
39
|
export { assignByKey };
|
|
49
|
-
|
|
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 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"],"
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/contexts/constants.ts
|
|
3
3
|
const DEFAULT_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
start: false,
|
|
5
|
+
sep: ".",
|
|
6
|
+
object: "both"
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
//#endregion
|
|
9
9
|
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
10
|
-
|
|
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"],"
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
start: false,
|
|
4
|
+
sep: ".",
|
|
5
|
+
object: "both"
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
//#endregion
|
|
7
8
|
export { DEFAULT_OPTIONS };
|
|
8
|
-
|
|
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"],"
|
|
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"}
|
package/lib/contexts/get.cjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
return decomposed[key];
|
|
6
|
+
return require_decompose.decompose.low(obj, require_contexts_constants.DEFAULT_OPTIONS)[key];
|
|
9
7
|
};
|
|
10
8
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=get.cjs.map
|
package/lib/contexts/get.cjs.map
CHANGED
|
@@ -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"],"
|
|
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"}
|
package/lib/contexts/get.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
return decomposed[key];
|
|
5
|
+
return decompose.low(obj, DEFAULT_OPTIONS)[key];
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=get.js.map
|
package/lib/contexts/get.js.map
CHANGED
|
@@ -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"],"
|
|
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"}
|
package/lib/contexts/index.cjs
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
package/lib/contexts/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { assignByKey } from "./assign.js";
|
|
2
|
+
import { getByKey } from "./get.js";
|
|
3
|
+
export { assignByKey, getByKey };
|