@tanstack/form-core 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/package.json +23 -12
  2. package/src/FieldApi.ts +53 -29
  3. package/src/FormApi.ts +14 -7
  4. package/src/tests/FieldApi.spec.ts +84 -17
  5. package/src/utils.ts +4 -0
  6. package/build/lib/FieldApi.cjs +0 -293
  7. package/build/lib/FieldApi.cjs.map +0 -1
  8. package/build/lib/FieldApi.d.ts +0 -95
  9. package/build/lib/FieldApi.d.ts.map +0 -1
  10. package/build/lib/FieldApi.js +0 -291
  11. package/build/lib/FieldApi.js.map +0 -1
  12. package/build/lib/FieldApi.legacy.cjs +0 -293
  13. package/build/lib/FieldApi.legacy.cjs.map +0 -1
  14. package/build/lib/FieldApi.legacy.js +0 -291
  15. package/build/lib/FieldApi.legacy.js.map +0 -1
  16. package/build/lib/FormApi.cjs +0 -239
  17. package/build/lib/FormApi.cjs.map +0 -1
  18. package/build/lib/FormApi.d.ts +0 -78
  19. package/build/lib/FormApi.d.ts.map +0 -1
  20. package/build/lib/FormApi.js +0 -237
  21. package/build/lib/FormApi.js.map +0 -1
  22. package/build/lib/FormApi.legacy.cjs +0 -239
  23. package/build/lib/FormApi.legacy.cjs.map +0 -1
  24. package/build/lib/FormApi.legacy.js +0 -237
  25. package/build/lib/FormApi.legacy.js.map +0 -1
  26. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs +0 -65
  27. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs.map +0 -1
  28. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -56
  29. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  30. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs +0 -65
  31. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +0 -1
  32. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js +0 -56
  33. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +0 -1
  34. package/build/lib/index.cjs +0 -14
  35. package/build/lib/index.cjs.map +0 -1
  36. package/build/lib/index.d.ts +0 -4
  37. package/build/lib/index.d.ts.map +0 -1
  38. package/build/lib/index.js +0 -4
  39. package/build/lib/index.js.map +0 -1
  40. package/build/lib/index.legacy.cjs +0 -14
  41. package/build/lib/index.legacy.cjs.map +0 -1
  42. package/build/lib/index.legacy.js +0 -4
  43. package/build/lib/index.legacy.js.map +0 -1
  44. package/build/lib/tests/FieldApi.spec.d.ts +0 -2
  45. package/build/lib/tests/FieldApi.spec.d.ts.map +0 -1
  46. package/build/lib/tests/FieldApi.test-d.d.ts +0 -2
  47. package/build/lib/tests/FieldApi.test-d.d.ts.map +0 -1
  48. package/build/lib/tests/FormApi.spec.d.ts +0 -2
  49. package/build/lib/tests/FormApi.spec.d.ts.map +0 -1
  50. package/build/lib/tests/utils.d.ts +0 -2
  51. package/build/lib/tests/utils.d.ts.map +0 -1
  52. package/build/lib/utils.cjs +0 -81
  53. package/build/lib/utils.cjs.map +0 -1
  54. package/build/lib/utils.d.ts +0 -32
  55. package/build/lib/utils.d.ts.map +0 -1
  56. package/build/lib/utils.js +0 -77
  57. package/build/lib/utils.js.map +0 -1
  58. package/build/lib/utils.legacy.cjs +0 -81
  59. package/build/lib/utils.legacy.cjs.map +0 -1
  60. package/build/lib/utils.legacy.js +0 -77
  61. package/build/lib/utils.legacy.js.map +0 -1
@@ -1,56 +0,0 @@
1
- function _defineProperty(obj, key, value) {
2
- key = _toPropertyKey(key);
3
- if (key in obj) {
4
- Object.defineProperty(obj, key, {
5
- value: value,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- });
10
- } else {
11
- obj[key] = value;
12
- }
13
- return obj;
14
- }
15
- function _toPrimitive(input, hint) {
16
- if (typeof input !== "object" || input === null) return input;
17
- var prim = input[Symbol.toPrimitive];
18
- if (prim !== undefined) {
19
- var res = prim.call(input, hint || "default");
20
- if (typeof res !== "object") return res;
21
- throw new TypeError("@@toPrimitive must return a primitive value.");
22
- }
23
- return (hint === "string" ? String : Number)(input);
24
- }
25
- function _toPropertyKey(arg) {
26
- var key = _toPrimitive(arg, "string");
27
- return typeof key === "symbol" ? key : String(key);
28
- }
29
- function _classPrivateFieldGet(receiver, privateMap) {
30
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
31
- return _classApplyDescriptorGet(receiver, descriptor);
32
- }
33
- function _classExtractFieldDescriptor(receiver, privateMap, action) {
34
- if (!privateMap.has(receiver)) {
35
- throw new TypeError("attempted to " + action + " private field on non-instance");
36
- }
37
- return privateMap.get(receiver);
38
- }
39
- function _classApplyDescriptorGet(receiver, descriptor) {
40
- if (descriptor.get) {
41
- return descriptor.get.call(receiver);
42
- }
43
- return descriptor.value;
44
- }
45
- function _checkPrivateRedeclaration(obj, privateCollection) {
46
- if (privateCollection.has(obj)) {
47
- throw new TypeError("Cannot initialize the same private elements twice on an object");
48
- }
49
- }
50
- function _classPrivateFieldInitSpec(obj, privateMap, value) {
51
- _checkPrivateRedeclaration(obj, privateMap);
52
- privateMap.set(obj, value);
53
- }
54
-
55
- export { _checkPrivateRedeclaration as checkPrivateRedeclaration, _classApplyDescriptorGet as classApplyDescriptorGet, _classExtractFieldDescriptor as classExtractFieldDescriptor, _classPrivateFieldGet as classPrivateFieldGet, _classPrivateFieldInitSpec as classPrivateFieldInitSpec, _defineProperty as defineProperty, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
56
- //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- function _defineProperty(obj, key, value) {
4
- key = _toPropertyKey(key);
5
- if (key in obj) {
6
- Object.defineProperty(obj, key, {
7
- value: value,
8
- enumerable: true,
9
- configurable: true,
10
- writable: true
11
- });
12
- } else {
13
- obj[key] = value;
14
- }
15
- return obj;
16
- }
17
- function _toPrimitive(input, hint) {
18
- if (typeof input !== "object" || input === null) return input;
19
- var prim = input[Symbol.toPrimitive];
20
- if (prim !== undefined) {
21
- var res = prim.call(input, hint || "default");
22
- if (typeof res !== "object") return res;
23
- throw new TypeError("@@toPrimitive must return a primitive value.");
24
- }
25
- return (hint === "string" ? String : Number)(input);
26
- }
27
- function _toPropertyKey(arg) {
28
- var key = _toPrimitive(arg, "string");
29
- return typeof key === "symbol" ? key : String(key);
30
- }
31
- function _classPrivateFieldGet(receiver, privateMap) {
32
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
33
- return _classApplyDescriptorGet(receiver, descriptor);
34
- }
35
- function _classExtractFieldDescriptor(receiver, privateMap, action) {
36
- if (!privateMap.has(receiver)) {
37
- throw new TypeError("attempted to " + action + " private field on non-instance");
38
- }
39
- return privateMap.get(receiver);
40
- }
41
- function _classApplyDescriptorGet(receiver, descriptor) {
42
- if (descriptor.get) {
43
- return descriptor.get.call(receiver);
44
- }
45
- return descriptor.value;
46
- }
47
- function _checkPrivateRedeclaration(obj, privateCollection) {
48
- if (privateCollection.has(obj)) {
49
- throw new TypeError("Cannot initialize the same private elements twice on an object");
50
- }
51
- }
52
- function _classPrivateFieldInitSpec(obj, privateMap, value) {
53
- _checkPrivateRedeclaration(obj, privateMap);
54
- privateMap.set(obj, value);
55
- }
56
-
57
- exports.checkPrivateRedeclaration = _checkPrivateRedeclaration;
58
- exports.classApplyDescriptorGet = _classApplyDescriptorGet;
59
- exports.classExtractFieldDescriptor = _classExtractFieldDescriptor;
60
- exports.classPrivateFieldGet = _classPrivateFieldGet;
61
- exports.classPrivateFieldInitSpec = _classPrivateFieldInitSpec;
62
- exports.defineProperty = _defineProperty;
63
- exports.toPrimitive = _toPrimitive;
64
- exports.toPropertyKey = _toPropertyKey;
65
- //# sourceMappingURL=_rollupPluginBabelHelpers.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.legacy.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,56 +0,0 @@
1
- function _defineProperty(obj, key, value) {
2
- key = _toPropertyKey(key);
3
- if (key in obj) {
4
- Object.defineProperty(obj, key, {
5
- value: value,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- });
10
- } else {
11
- obj[key] = value;
12
- }
13
- return obj;
14
- }
15
- function _toPrimitive(input, hint) {
16
- if (typeof input !== "object" || input === null) return input;
17
- var prim = input[Symbol.toPrimitive];
18
- if (prim !== undefined) {
19
- var res = prim.call(input, hint || "default");
20
- if (typeof res !== "object") return res;
21
- throw new TypeError("@@toPrimitive must return a primitive value.");
22
- }
23
- return (hint === "string" ? String : Number)(input);
24
- }
25
- function _toPropertyKey(arg) {
26
- var key = _toPrimitive(arg, "string");
27
- return typeof key === "symbol" ? key : String(key);
28
- }
29
- function _classPrivateFieldGet(receiver, privateMap) {
30
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
31
- return _classApplyDescriptorGet(receiver, descriptor);
32
- }
33
- function _classExtractFieldDescriptor(receiver, privateMap, action) {
34
- if (!privateMap.has(receiver)) {
35
- throw new TypeError("attempted to " + action + " private field on non-instance");
36
- }
37
- return privateMap.get(receiver);
38
- }
39
- function _classApplyDescriptorGet(receiver, descriptor) {
40
- if (descriptor.get) {
41
- return descriptor.get.call(receiver);
42
- }
43
- return descriptor.value;
44
- }
45
- function _checkPrivateRedeclaration(obj, privateCollection) {
46
- if (privateCollection.has(obj)) {
47
- throw new TypeError("Cannot initialize the same private elements twice on an object");
48
- }
49
- }
50
- function _classPrivateFieldInitSpec(obj, privateMap, value) {
51
- _checkPrivateRedeclaration(obj, privateMap);
52
- privateMap.set(obj, value);
53
- }
54
-
55
- export { _checkPrivateRedeclaration as checkPrivateRedeclaration, _classApplyDescriptorGet as classApplyDescriptorGet, _classExtractFieldDescriptor as classExtractFieldDescriptor, _classPrivateFieldGet as classPrivateFieldGet, _classPrivateFieldInitSpec as classPrivateFieldInitSpec, _defineProperty as defineProperty, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
56
- //# sourceMappingURL=_rollupPluginBabelHelpers.legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.legacy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var FormApi = require('./FormApi.cjs');
4
- var FieldApi = require('./FieldApi.cjs');
5
- var utils = require('./utils.cjs');
6
-
7
-
8
-
9
- exports.FormApi = FormApi.FormApi;
10
- exports.FieldApi = FieldApi.FieldApi;
11
- exports.functionalUpdate = utils.functionalUpdate;
12
- exports.getBy = utils.getBy;
13
- exports.setBy = utils.setBy;
14
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,4 +0,0 @@
1
- export * from './FormApi';
2
- export * from './FieldApi';
3
- export * from './utils';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
@@ -1,4 +0,0 @@
1
- export { FormApi } from './FormApi.js';
2
- export { FieldApi } from './FieldApi.js';
3
- export { functionalUpdate, getBy, setBy } from './utils.js';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var FormApi = require('./FormApi.legacy.cjs');
4
- var FieldApi = require('./FieldApi.legacy.cjs');
5
- var utils = require('./utils.legacy.cjs');
6
-
7
-
8
-
9
- exports.FormApi = FormApi.FormApi;
10
- exports.FieldApi = FieldApi.FieldApi;
11
- exports.functionalUpdate = utils.functionalUpdate;
12
- exports.getBy = utils.getBy;
13
- exports.setBy = utils.setBy;
14
- //# sourceMappingURL=index.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.legacy.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,4 +0,0 @@
1
- export { FormApi } from './FormApi.legacy.js';
2
- export { FieldApi } from './FieldApi.legacy.js';
3
- export { functionalUpdate, getBy, setBy } from './utils.legacy.js';
4
- //# sourceMappingURL=index.legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.legacy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=FieldApi.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldApi.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/FieldApi.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=FieldApi.test-d.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldApi.test-d.d.ts","sourceRoot":"","sources":["../../../src/tests/FieldApi.test-d.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=FormApi.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormApi.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/FormApi.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare function sleep(timeout: number): Promise<void>;
2
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tests/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD"}
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- function functionalUpdate(updater, input) {
4
- return typeof updater === 'function' ? updater(input) : updater;
5
- }
6
-
7
- /**
8
- * Get a value from an object using a path, including dot notation.
9
- */
10
- function getBy(obj, path) {
11
- const pathArray = makePathArray(path);
12
- const pathObj = pathArray;
13
- return pathObj.reduce((current, pathPart) => {
14
- if (typeof current !== 'undefined') {
15
- return current[pathPart];
16
- }
17
- return undefined;
18
- }, obj);
19
- }
20
-
21
- /**
22
- * Set a value on an object using a path, including dot notation.
23
- */
24
- function setBy(obj, _path, updater) {
25
- const path = makePathArray(_path);
26
- function doSet(parent) {
27
- if (!path.length) {
28
- return functionalUpdate(updater, parent);
29
- }
30
- const key = path.shift();
31
- if (typeof key === 'string') {
32
- if (typeof parent === 'object') {
33
- return {
34
- ...parent,
35
- [key]: doSet(parent[key])
36
- };
37
- }
38
- return {
39
- [key]: doSet()
40
- };
41
- }
42
- if (typeof key === 'number') {
43
- if (Array.isArray(parent)) {
44
- const prefix = parent.slice(0, key);
45
- return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];
46
- }
47
- return [...new Array(key), doSet()];
48
- }
49
- throw new Error('Uh oh!');
50
- }
51
- return doSet(obj);
52
- }
53
- const reFindNumbers0 = /^(\d*)$/gm;
54
- const reFindNumbers1 = /\.(\d*)\./gm;
55
- const reFindNumbers2 = /^(\d*)\./gm;
56
- const reFindNumbers3 = /\.(\d*$)/gm;
57
- const reFindMultiplePeriods = /\.{2,}/gm;
58
- const intPrefix = '__int__';
59
- const intReplace = intPrefix + "$1";
60
- function makePathArray(str) {
61
- if (typeof str !== 'string') {
62
- throw new Error('Path must be a string.');
63
- }
64
- return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, "." + intReplace + ".").replace(reFindNumbers2, intReplace + ".").replace(reFindNumbers3, "." + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {
65
- if (d.indexOf(intPrefix) === 0) {
66
- return parseInt(d.substring(intPrefix.length), 10);
67
- }
68
- return d;
69
- });
70
- }
71
-
72
- // Is this type a tuple?
73
-
74
- // If this type is a tuple, what indices are allowed?
75
-
76
- // Hack to get TypeScript to show simplified types in error messages
77
-
78
- exports.functionalUpdate = functionalUpdate;
79
- exports.getBy = getBy;
80
- exports.setBy = setBy;
81
- //# sourceMappingURL=utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n */\nexport function getBy(obj: any, path: any) {\n const pathArray = makePathArray(path)\n const pathObj = pathArray\n return pathObj.reduce((current: any, pathPart: any) => {\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n throw new Error('Uh oh!')\n }\n\n return doSet(obj)\n}\n\nconst reFindNumbers0 = /^(\\d*)$/gm\nconst reFindNumbers1 = /\\.(\\d*)\\./gm\nconst reFindNumbers2 = /^(\\d*)\\./gm\nconst reFindNumbers3 = /\\.(\\d*$)/gm\nconst reFindMultiplePeriods = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\nfunction makePathArray(str: string) {\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return str\n .replace('[', '.')\n .replace(']', '')\n .replace(reFindNumbers0, intReplace)\n .replace(reFindNumbers1, `.${intReplace}.`)\n .replace(reFindNumbers2, `${intReplace}.`)\n .replace(reFindNumbers3, `.${intReplace}`)\n .replace(reFindMultiplePeriods, '.')\n .split('.')\n .map((d) => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10)\n }\n return d\n })\n}\n\nexport type RequiredByKey<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T> = unknown extends T\n ? keyof T\n : object extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>>\n : T extends any[]\n ? DeepKeys<T[number]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T>\n : never\n\ntype DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\ntype Narrowable = string | number | bigint | boolean\n\ntype NarrowRaw<A> =\n | (A extends [] ? [] : never)\n | (A extends Narrowable ? A : never)\n | {\n [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>\n }\n\nexport type Narrow<A> = Try<A, [], NarrowRaw<A>>\n\ntype Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch\n\n// Hack to get TypeScript to show simplified types in error messages\nexport type Pretty<T> = { [K in keyof T]: T[K] } & {}\n"],"names":["functionalUpdate","updater","input","getBy","obj","path","pathArray","makePathArray","pathObj","reduce","current","pathPart","undefined","setBy","_path","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring"],"mappings":";;AAMO,SAASA,gBAAgBA,CAC9BC,OAAiC,EACjCC,KAAa,EACJ;EACT,OAAO,OAAOD,OAAO,KAAK,UAAU,GAC/BA,OAAO,CAAgCC,KAAK,CAAC,GAC9CD,OAAO,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACO,SAASE,KAAKA,CAACC,GAAQ,EAAEC,IAAS,EAAE;AACzC,EAAA,MAAMC,SAAS,GAAGC,aAAa,CAACF,IAAI,CAAC,CAAA;EACrC,MAAMG,OAAO,GAAGF,SAAS,CAAA;EACzB,OAAOE,OAAO,CAACC,MAAM,CA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OAAO,CAACP,SAAS,CAAC,KAAK,CAAC,EAAE;AAC9B,MAAA,OAAOQ,QAAQ,CAACF,CAAC,CAACG,SAAS,CAACT,SAAS,CAACb,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACpD,KAAA;AACA,IAAA,OAAOmB,CAAC,CAAA;AACV,GAAC,CAAC,CAAA;AACN,CAAA;;AAaA;;AAOA;;AA+CA;;;;;;"}
@@ -1,32 +0,0 @@
1
- export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
2
- export type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
3
- export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
4
- /**
5
- * Get a value from an object using a path, including dot notation.
6
- */
7
- export declare function getBy(obj: any, path: any): any;
8
- /**
9
- * Set a value on an object using a path, including dot notation.
10
- */
11
- export declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
12
- export type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
13
- type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
14
- type Index40 = ComputeRange<40>[number];
15
- type IsTuple<T> = T extends readonly any[] & {
16
- length: infer Length;
17
- } ? Length extends Index40 ? T : never : never;
18
- type AllowedIndexes<Tuple extends ReadonlyArray<any>, Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail['length']> : Keys;
19
- export type DeepKeys<T> = unknown extends T ? keyof T : object extends T ? string : T extends readonly any[] & IsTuple<T> ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>> : T extends any[] ? DeepKeys<T[number]> : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T> : never;
20
- type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
21
- export type DeepValue<T, TProp> = T extends Record<string | number, any> ? TProp extends `${infer TBranch}.${infer TDeepProp}` ? DeepValue<T[TBranch], TDeepProp> : T[TProp & string] : never;
22
- type Narrowable = string | number | bigint | boolean;
23
- type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | {
24
- [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>;
25
- };
26
- export type Narrow<A> = Try<A, [], NarrowRaw<A>>;
27
- type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
28
- export type Pretty<T> = {
29
- [K in keyof T]: T[K];
30
- } & {};
31
- export {};
32
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;AAE5E,MAAM,MAAM,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IACxC,OAAO,GACP,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE9B,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EACvD,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,KAAK,EAAE,MAAM,GACZ,OAAO,CAIT;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OASxC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAsChE;AAiCD,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,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AK,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;AAG5D,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAA"}
@@ -1,77 +0,0 @@
1
- function functionalUpdate(updater, input) {
2
- return typeof updater === 'function' ? updater(input) : updater;
3
- }
4
-
5
- /**
6
- * Get a value from an object using a path, including dot notation.
7
- */
8
- function getBy(obj, path) {
9
- const pathArray = makePathArray(path);
10
- const pathObj = pathArray;
11
- return pathObj.reduce((current, pathPart) => {
12
- if (typeof current !== 'undefined') {
13
- return current[pathPart];
14
- }
15
- return undefined;
16
- }, obj);
17
- }
18
-
19
- /**
20
- * Set a value on an object using a path, including dot notation.
21
- */
22
- function setBy(obj, _path, updater) {
23
- const path = makePathArray(_path);
24
- function doSet(parent) {
25
- if (!path.length) {
26
- return functionalUpdate(updater, parent);
27
- }
28
- const key = path.shift();
29
- if (typeof key === 'string') {
30
- if (typeof parent === 'object') {
31
- return {
32
- ...parent,
33
- [key]: doSet(parent[key])
34
- };
35
- }
36
- return {
37
- [key]: doSet()
38
- };
39
- }
40
- if (typeof key === 'number') {
41
- if (Array.isArray(parent)) {
42
- const prefix = parent.slice(0, key);
43
- return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];
44
- }
45
- return [...new Array(key), doSet()];
46
- }
47
- throw new Error('Uh oh!');
48
- }
49
- return doSet(obj);
50
- }
51
- const reFindNumbers0 = /^(\d*)$/gm;
52
- const reFindNumbers1 = /\.(\d*)\./gm;
53
- const reFindNumbers2 = /^(\d*)\./gm;
54
- const reFindNumbers3 = /\.(\d*$)/gm;
55
- const reFindMultiplePeriods = /\.{2,}/gm;
56
- const intPrefix = '__int__';
57
- const intReplace = intPrefix + "$1";
58
- function makePathArray(str) {
59
- if (typeof str !== 'string') {
60
- throw new Error('Path must be a string.');
61
- }
62
- return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, "." + intReplace + ".").replace(reFindNumbers2, intReplace + ".").replace(reFindNumbers3, "." + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {
63
- if (d.indexOf(intPrefix) === 0) {
64
- return parseInt(d.substring(intPrefix.length), 10);
65
- }
66
- return d;
67
- });
68
- }
69
-
70
- // Is this type a tuple?
71
-
72
- // If this type is a tuple, what indices are allowed?
73
-
74
- // Hack to get TypeScript to show simplified types in error messages
75
-
76
- export { functionalUpdate, getBy, setBy };
77
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n */\nexport function getBy(obj: any, path: any) {\n const pathArray = makePathArray(path)\n const pathObj = pathArray\n return pathObj.reduce((current: any, pathPart: any) => {\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n throw new Error('Uh oh!')\n }\n\n return doSet(obj)\n}\n\nconst reFindNumbers0 = /^(\\d*)$/gm\nconst reFindNumbers1 = /\\.(\\d*)\\./gm\nconst reFindNumbers2 = /^(\\d*)\\./gm\nconst reFindNumbers3 = /\\.(\\d*$)/gm\nconst reFindMultiplePeriods = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\nfunction makePathArray(str: string) {\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return str\n .replace('[', '.')\n .replace(']', '')\n .replace(reFindNumbers0, intReplace)\n .replace(reFindNumbers1, `.${intReplace}.`)\n .replace(reFindNumbers2, `${intReplace}.`)\n .replace(reFindNumbers3, `.${intReplace}`)\n .replace(reFindMultiplePeriods, '.')\n .split('.')\n .map((d) => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10)\n }\n return d\n })\n}\n\nexport type RequiredByKey<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T> = unknown extends T\n ? keyof T\n : object extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>>\n : T extends any[]\n ? DeepKeys<T[number]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T>\n : never\n\ntype DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\ntype Narrowable = string | number | bigint | boolean\n\ntype NarrowRaw<A> =\n | (A extends [] ? [] : never)\n | (A extends Narrowable ? A : never)\n | {\n [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>\n }\n\nexport type Narrow<A> = Try<A, [], NarrowRaw<A>>\n\ntype Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch\n\n// Hack to get TypeScript to show simplified types in error messages\nexport type Pretty<T> = { [K in keyof T]: T[K] } & {}\n"],"names":["functionalUpdate","updater","input","getBy","obj","path","pathArray","makePathArray","pathObj","reduce","current","pathPart","undefined","setBy","_path","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring"],"mappings":"AAMO,SAASA,gBAAgBA,CAC9BC,OAAiC,EACjCC,KAAa,EACJ;EACT,OAAO,OAAOD,OAAO,KAAK,UAAU,GAC/BA,OAAO,CAAgCC,KAAK,CAAC,GAC9CD,OAAO,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACO,SAASE,KAAKA,CAACC,GAAQ,EAAEC,IAAS,EAAE;AACzC,EAAA,MAAMC,SAAS,GAAGC,aAAa,CAACF,IAAI,CAAC,CAAA;EACrC,MAAMG,OAAO,GAAGF,SAAS,CAAA;EACzB,OAAOE,OAAO,CAACC,MAAM,CAAC,CAACC,OAAY,EAAEC,QAAa,KAAK;AACrD,IAAA,IA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MAAA,OAAOQ,QAAQ,CAACF,CAAC,CAACG,SAAS,CAACT,SAAS,CAACb,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AACpD,KAAA;AACA,IAAA,OAAOmB,CAAC,CAAA;AACV,GAAC,CAAC,CAAA;AACN,CAAA;;AAaA;;AAOA;;AA+CA;;;;"}
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- function functionalUpdate(updater, input) {
4
- return typeof updater === 'function' ? updater(input) : updater;
5
- }
6
-
7
- /**
8
- * Get a value from an object using a path, including dot notation.
9
- */
10
- function getBy(obj, path) {
11
- const pathArray = makePathArray(path);
12
- const pathObj = pathArray;
13
- return pathObj.reduce((current, pathPart) => {
14
- if (typeof current !== 'undefined') {
15
- return current[pathPart];
16
- }
17
- return undefined;
18
- }, obj);
19
- }
20
-
21
- /**
22
- * Set a value on an object using a path, including dot notation.
23
- */
24
- function setBy(obj, _path, updater) {
25
- const path = makePathArray(_path);
26
- function doSet(parent) {
27
- if (!path.length) {
28
- return functionalUpdate(updater, parent);
29
- }
30
- const key = path.shift();
31
- if (typeof key === 'string') {
32
- if (typeof parent === 'object') {
33
- return {
34
- ...parent,
35
- [key]: doSet(parent[key])
36
- };
37
- }
38
- return {
39
- [key]: doSet()
40
- };
41
- }
42
- if (typeof key === 'number') {
43
- if (Array.isArray(parent)) {
44
- const prefix = parent.slice(0, key);
45
- return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];
46
- }
47
- return [...new Array(key), doSet()];
48
- }
49
- throw new Error('Uh oh!');
50
- }
51
- return doSet(obj);
52
- }
53
- const reFindNumbers0 = /^(\d*)$/gm;
54
- const reFindNumbers1 = /\.(\d*)\./gm;
55
- const reFindNumbers2 = /^(\d*)\./gm;
56
- const reFindNumbers3 = /\.(\d*$)/gm;
57
- const reFindMultiplePeriods = /\.{2,}/gm;
58
- const intPrefix = '__int__';
59
- const intReplace = intPrefix + "$1";
60
- function makePathArray(str) {
61
- if (typeof str !== 'string') {
62
- throw new Error('Path must be a string.');
63
- }
64
- return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, "." + intReplace + ".").replace(reFindNumbers2, intReplace + ".").replace(reFindNumbers3, "." + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {
65
- if (d.indexOf(intPrefix) === 0) {
66
- return parseInt(d.substring(intPrefix.length), 10);
67
- }
68
- return d;
69
- });
70
- }
71
-
72
- // Is this type a tuple?
73
-
74
- // If this type is a tuple, what indices are allowed?
75
-
76
- // Hack to get TypeScript to show simplified types in error messages
77
-
78
- exports.functionalUpdate = functionalUpdate;
79
- exports.getBy = getBy;
80
- exports.setBy = setBy;
81
- //# sourceMappingURL=utils.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.legacy.cjs","sources":["../../src/utils.ts"],"sourcesContent":["export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput = TInput> =\n | TOutput\n | UpdaterFn<TInput, TOutput>\n\nexport function functionalUpdate<TInput, TOutput = TInput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as UpdaterFn<TInput, TOutput>)(input)\n : updater\n}\n\n/**\n * Get a value from an object using a path, including dot notation.\n */\nexport function getBy(obj: any, path: any) {\n const pathArray = makePathArray(path)\n const pathObj = pathArray\n return pathObj.reduce((current: any, pathPart: any) => {\n if (typeof current !== 'undefined') {\n return current[pathPart]\n }\n return undefined\n }, obj)\n}\n\n/**\n * Set a value on an object using a path, including dot notation.\n */\nexport function setBy(obj: any, _path: any, updater: Updater<any>) {\n const path = makePathArray(_path)\n\n function doSet(parent?: any): any {\n if (!path.length) {\n return functionalUpdate(updater, parent)\n }\n\n const key = path.shift()\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return {\n ...parent,\n [key]: doSet(parent[key]),\n }\n }\n return {\n [key]: doSet(),\n }\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key)\n return [\n ...(prefix.length ? prefix : new Array(key)),\n doSet(parent[key]),\n ...parent.slice(key + 1),\n ]\n }\n return [...new Array(key), doSet()]\n }\n\n throw new Error('Uh oh!')\n }\n\n return doSet(obj)\n}\n\nconst reFindNumbers0 = /^(\\d*)$/gm\nconst reFindNumbers1 = /\\.(\\d*)\\./gm\nconst reFindNumbers2 = /^(\\d*)\\./gm\nconst reFindNumbers3 = /\\.(\\d*$)/gm\nconst reFindMultiplePeriods = /\\.{2,}/gm\n\nconst intPrefix = '__int__'\nconst intReplace = `${intPrefix}$1`\n\nfunction makePathArray(str: string) {\n if (typeof str !== 'string') {\n throw new Error('Path must be a string.')\n }\n\n return str\n .replace('[', '.')\n .replace(']', '')\n .replace(reFindNumbers0, intReplace)\n .replace(reFindNumbers1, `.${intReplace}.`)\n .replace(reFindNumbers2, `${intReplace}.`)\n .replace(reFindNumbers3, `.${intReplace}`)\n .replace(reFindMultiplePeriods, '.')\n .split('.')\n .map((d) => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10)\n }\n return d\n })\n}\n\nexport type RequiredByKey<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T> = unknown extends T\n ? keyof T\n : object extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>>\n : T extends any[]\n ? DeepKeys<T[number]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T>\n : never\n\ntype DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\ntype Narrowable = string | number | bigint | boolean\n\ntype NarrowRaw<A> =\n | (A extends [] ? [] : never)\n | (A extends Narrowable ? A : never)\n | {\n [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>\n }\n\nexport type Narrow<A> = Try<A, [], NarrowRaw<A>>\n\ntype Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch\n\n// Hack to get TypeScript to show simplified types in error messages\nexport type Pretty<T> = { [K in keyof T]: T[K] } & {}\n"],"names":["functionalUpdate","updater","input","getBy","obj","path","pathArray","makePathArray","pathObj","reduce","current","pathPart","undefined","setBy","_path","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring"],"mappings":";;AAMO,SAASA,gBAAgBA,CAC9BC,OAAiC,EACjCC,KAAa,EACJ;EACT,OAAO,OAAOD,OAAO,KAAK,UAAU,GAC/BA,OAAO,CAAgCC,KAAK,CAAC,GAC9CD,OAAO,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACO,SAASE,KAAKA,CAACC,GAAQ,EAAEC,IAAS,EAAE;AACzC,EAAA,MAAMC,SAAS,GAAGC,aAAa,CAACF,IAAI,CAAC,CAAA;EACrC,MAAMG,OAAO,GAAGF,SAAS,CAAA;EACzB,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