es-toolkit 1.10.1-dev.246 → 1.10.1-dev.248
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/dist/chunk-4RQPJUPQ.mjs +34 -0
- package/dist/chunk-4RQPJUPQ.mjs.map +1 -0
- package/dist/chunk-54TK5BIS.mjs +1 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +32 -0
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +9 -5
- package/dist/compat/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/dist/object/get.d.mts +20 -0
- package/dist/object/get.d.ts +20 -0
- package/dist/object/get.js +58 -0
- package/dist/object/get.js.map +1 -0
- package/dist/object/get.mjs +8 -0
- package/dist/object/get.mjs.map +1 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +32 -0
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +8 -4
- package/package.json +1 -1
- package/dist/chunk-OSOLEQLZ.mjs +0 -1
- /package/dist/{chunk-OSOLEQLZ.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./chunk-NKLIE2OI.mjs";
|
|
2
|
+
import "./chunk-ARZ5BDR6.mjs";
|
|
2
3
|
import "./chunk-XT74R35S.mjs";
|
|
3
4
|
import {
|
|
4
5
|
camelCase
|
|
@@ -35,14 +36,19 @@ import {
|
|
|
35
36
|
import {
|
|
36
37
|
isUndefined
|
|
37
38
|
} from "./chunk-VH2PV426.mjs";
|
|
38
|
-
import "./chunk-ARZ5BDR6.mjs";
|
|
39
39
|
import {
|
|
40
40
|
delay
|
|
41
41
|
} from "./chunk-O64NE2P4.mjs";
|
|
42
|
-
import "./chunk-
|
|
42
|
+
import "./chunk-54TK5BIS.mjs";
|
|
43
|
+
import {
|
|
44
|
+
pickBy
|
|
45
|
+
} from "./chunk-6CLH5YZ2.mjs";
|
|
43
46
|
import {
|
|
44
47
|
clone
|
|
45
48
|
} from "./chunk-U4JGKZ56.mjs";
|
|
49
|
+
import {
|
|
50
|
+
get
|
|
51
|
+
} from "./chunk-4RQPJUPQ.mjs";
|
|
46
52
|
import {
|
|
47
53
|
invert
|
|
48
54
|
} from "./chunk-OLX53VEF.mjs";
|
|
@@ -55,9 +61,6 @@ import {
|
|
|
55
61
|
import {
|
|
56
62
|
pick
|
|
57
63
|
} from "./chunk-HPFDYUGP.mjs";
|
|
58
|
-
import {
|
|
59
|
-
pickBy
|
|
60
|
-
} from "./chunk-6CLH5YZ2.mjs";
|
|
61
64
|
import "./chunk-FUS75PJ7.mjs";
|
|
62
65
|
import {
|
|
63
66
|
sumBy
|
|
@@ -287,6 +290,7 @@ export {
|
|
|
287
290
|
flatten,
|
|
288
291
|
flattenDeep,
|
|
289
292
|
forEachRight,
|
|
293
|
+
get,
|
|
290
294
|
groupBy,
|
|
291
295
|
head,
|
|
292
296
|
inRange,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a value from an object by path.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a path, and default value that will be returned if
|
|
5
|
+
* a returnable value about the given path does not exist.
|
|
6
|
+
*
|
|
7
|
+
* @template O - Type of the object to get value from.
|
|
8
|
+
* @template T - Type of the default value to return if the value does not exist.
|
|
9
|
+
* @param {O} obj - The object to get value from.
|
|
10
|
+
* @param {string | string[]} path - The path to get value from.
|
|
11
|
+
* @param {T} defaultValue - The default value to return if the value does not exist.
|
|
12
|
+
* @returns {O[keyof O] | undefined} - The value from the object by the given path.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const obj = { a: { b: 3 } };
|
|
16
|
+
* get(obj, 'a.b', null); // 3
|
|
17
|
+
*/
|
|
18
|
+
declare function get<O, T>(obj: O, path: string | string[], defaultValue?: T): O[keyof O] | T | undefined;
|
|
19
|
+
|
|
20
|
+
export { get };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a value from an object by path.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a path, and default value that will be returned if
|
|
5
|
+
* a returnable value about the given path does not exist.
|
|
6
|
+
*
|
|
7
|
+
* @template O - Type of the object to get value from.
|
|
8
|
+
* @template T - Type of the default value to return if the value does not exist.
|
|
9
|
+
* @param {O} obj - The object to get value from.
|
|
10
|
+
* @param {string | string[]} path - The path to get value from.
|
|
11
|
+
* @param {T} defaultValue - The default value to return if the value does not exist.
|
|
12
|
+
* @returns {O[keyof O] | undefined} - The value from the object by the given path.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const obj = { a: { b: 3 } };
|
|
16
|
+
* get(obj, 'a.b', null); // 3
|
|
17
|
+
*/
|
|
18
|
+
declare function get<O, T>(obj: O, path: string | string[], defaultValue?: T): O[keyof O] | T | undefined;
|
|
19
|
+
|
|
20
|
+
export { get };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/object/get.ts
|
|
21
|
+
var get_exports = {};
|
|
22
|
+
__export(get_exports, {
|
|
23
|
+
get: () => get
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_exports);
|
|
26
|
+
function get(obj, path, defaultValue) {
|
|
27
|
+
if (!Array.isArray(path)) {
|
|
28
|
+
const pathArr = path.split(".");
|
|
29
|
+
path = [];
|
|
30
|
+
for (let i = 0; i < pathArr.length; i++) {
|
|
31
|
+
if (/^.+\[[0-9]+\]$/.test(pathArr[i])) {
|
|
32
|
+
path.push(/^.+(?=\[[0-9]+\]$)/.exec(pathArr[i])[0]);
|
|
33
|
+
path.push(`${new RegExp("(?<=^.+\\[)[0-9]+(?=\\]$)").exec(pathArr[i])[0]}`);
|
|
34
|
+
} else {
|
|
35
|
+
path.push(pathArr[i]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const callback = (innerObj, innerPath) => {
|
|
40
|
+
if (typeof innerObj[innerPath] === "undefined") {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
return innerObj[innerPath];
|
|
44
|
+
};
|
|
45
|
+
let currentObj = obj;
|
|
46
|
+
for (let i = 0; i < path.length; i++) {
|
|
47
|
+
currentObj = callback(currentObj, path[i]);
|
|
48
|
+
if (typeof currentObj === "undefined") {
|
|
49
|
+
return typeof defaultValue === "undefined" ? void 0 : defaultValue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return currentObj;
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
get
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/object/get.ts"],"sourcesContent":["/**\n * Get a value from an object by path.\n * \n * This function takes an object and a path, and default value that will be returned if\n * a returnable value about the given path does not exist.\n * \n * @template O - Type of the object to get value from. \n * @template T - Type of the default value to return if the value does not exist.\n * @param {O} obj - The object to get value from. \n * @param {string | string[]} path - The path to get value from. \n * @param {T} defaultValue - The default value to return if the value does not exist.\n * @returns {O[keyof O] | undefined} - The value from the object by the given path.\n * \n * @example\n * const obj = { a: { b: 3 } };\n * get(obj, 'a.b', null); // 3\n */\n\nexport function get<O, T>(obj: O, path: string | string[], defaultValue?: T): O[keyof O] | T | undefined {\n if (!Array.isArray(path)) {\n const pathArr = path.split('.');\n path = []\n for (let i = 0; i < pathArr.length; i++) {\n if (/^.+\\[[0-9]+\\]$/.test(pathArr[i])) {\n path.push(/^.+(?=\\[[0-9]+\\]$)/.exec(pathArr[i])![0])\n path.push(`${/(?<=^.+\\[)[0-9]+(?=\\]$)/.exec(pathArr[i])![0]}`)\n } else {\n path.push(pathArr[i])\n }\n }\n }\n\n const callback = (innerObj: any, innerPath: string) => {\n if (typeof innerObj[innerPath] === 'undefined') {\n return undefined\n }\n return innerObj[innerPath]\n }\n\n let currentObj = obj\n for (let i = 0; i < path.length; i++) {\n currentObj = callback(currentObj, path[i])\n if (typeof currentObj === 'undefined') {\n return typeof defaultValue === 'undefined' ? undefined : defaultValue\n }\n }\n return currentObj as O[keyof O]\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,IAAU,KAAQ,MAAyB,cAA8C;AACvG,MAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACxB,UAAM,UAAU,KAAK,MAAM,GAAG;AAC9B,WAAO,CAAC;AACR,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAI,iBAAiB,KAAK,QAAQ,CAAC,CAAC,GAAG;AACrC,aAAK,KAAK,qBAAqB,KAAK,QAAQ,CAAC,CAAC,EAAG,CAAC,CAAC;AACnD,aAAK,KAAK,GAAG,WAAC,2BAAwB,EAAC,KAAK,QAAQ,CAAC,CAAC,EAAG,CAAC,CAAC,EAAE;AAAA,MAC/D,OAAO;AACL,aAAK,KAAK,QAAQ,CAAC,CAAC;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAW,CAAC,UAAe,cAAsB;AACrD,QAAI,OAAO,SAAS,SAAS,MAAM,aAAa;AAC9C,aAAO;AAAA,IACT;AACA,WAAO,SAAS,SAAS;AAAA,EAC3B;AAEA,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,iBAAa,SAAS,YAAY,KAAK,CAAC,CAAC;AACzC,QAAI,OAAO,eAAe,aAAa;AACrC,aAAO,OAAO,iBAAiB,cAAc,SAAY;AAAA,IAC3D;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/object/index.d.mts
CHANGED
package/dist/object/index.d.ts
CHANGED
package/dist/object/index.js
CHANGED
|
@@ -35,6 +35,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
35
35
|
var object_exports = {};
|
|
36
36
|
__export(object_exports, {
|
|
37
37
|
clone: () => clone,
|
|
38
|
+
get: () => get,
|
|
38
39
|
invert: () => invert,
|
|
39
40
|
omit: () => omit,
|
|
40
41
|
omitBy: () => omitBy,
|
|
@@ -133,9 +134,40 @@ function clone(obj) {
|
|
|
133
134
|
function isPrimitive(value) {
|
|
134
135
|
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
135
136
|
}
|
|
137
|
+
|
|
138
|
+
// src/object/get.ts
|
|
139
|
+
function get(obj, path, defaultValue) {
|
|
140
|
+
if (!Array.isArray(path)) {
|
|
141
|
+
const pathArr = path.split(".");
|
|
142
|
+
path = [];
|
|
143
|
+
for (let i = 0; i < pathArr.length; i++) {
|
|
144
|
+
if (/^.+\[[0-9]+\]$/.test(pathArr[i])) {
|
|
145
|
+
path.push(/^.+(?=\[[0-9]+\]$)/.exec(pathArr[i])[0]);
|
|
146
|
+
path.push(`${new RegExp("(?<=^.+\\[)[0-9]+(?=\\]$)").exec(pathArr[i])[0]}`);
|
|
147
|
+
} else {
|
|
148
|
+
path.push(pathArr[i]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const callback = (innerObj, innerPath) => {
|
|
153
|
+
if (typeof innerObj[innerPath] === "undefined") {
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
return innerObj[innerPath];
|
|
157
|
+
};
|
|
158
|
+
let currentObj = obj;
|
|
159
|
+
for (let i = 0; i < path.length; i++) {
|
|
160
|
+
currentObj = callback(currentObj, path[i]);
|
|
161
|
+
if (typeof currentObj === "undefined") {
|
|
162
|
+
return typeof defaultValue === "undefined" ? void 0 : defaultValue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return currentObj;
|
|
166
|
+
}
|
|
136
167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
168
|
0 && (module.exports = {
|
|
138
169
|
clone,
|
|
170
|
+
get,
|
|
139
171
|
invert,
|
|
140
172
|
omit,
|
|
141
173
|
omitBy,
|
package/dist/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !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AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,MAAM;AAAA,EACnB;AAEA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/B;AAEA,MAAI,eAAe,QAAQ;AACzB,WAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK;AAAA,EACzC;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,aAAO,IAAI,KAAK,KAAK;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,SAAS,KAAK;AACvB,aAAO,IAAI,KAAK;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QACb,OAAO,UAAU,YAAY,OAAO,UAAU;AACnD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts","../../src/object/get.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\nexport { get } from './get.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n","/**\n * Get a value from an object by path.\n * \n * This function takes an object and a path, and default value that will be returned if\n * a returnable value about the given path does not exist.\n * \n * @template O - Type of the object to get value from. \n * @template T - Type of the default value to return if the value does not exist.\n * @param {O} obj - The object to get value from. \n * @param {string | string[]} path - The path to get value from. \n * @param {T} defaultValue - The default value to return if the value does not exist.\n * @returns {O[keyof O] | undefined} - The value from the object by the given path.\n * \n * @example\n * const obj = { a: { b: 3 } };\n * get(obj, 'a.b', null); // 3\n */\n\nexport function get<O, T>(obj: O, path: string | string[], defaultValue?: T): O[keyof O] | T | undefined {\n if (!Array.isArray(path)) {\n const pathArr = path.split('.');\n path = []\n for (let i = 0; i < pathArr.length; i++) {\n if (/^.+\\[[0-9]+\\]$/.test(pathArr[i])) {\n path.push(/^.+(?=\\[[0-9]+\\]$)/.exec(pathArr[i])![0])\n path.push(`${/(?<=^.+\\[)[0-9]+(?=\\]$)/.exec(pathArr[i])![0]}`)\n } else {\n path.push(pathArr[i])\n }\n }\n }\n\n const callback = (innerObj: any, innerPath: string) => {\n if (typeof innerObj[innerPath] === 'undefined') {\n return undefined\n }\n return innerObj[innerPath]\n }\n\n let currentObj = obj\n for (let i = 0; i < path.length; i++) {\n currentObj = callback(currentObj, path[i])\n if (typeof currentObj === 'undefined') {\n return typeof defaultValue === 'undefined' ? undefined : defaultValue\n }\n }\n return currentObj as O[keyof O]\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD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2.mjs";
|
|
2
5
|
import {
|
|
3
6
|
clone
|
|
4
7
|
} from "../chunk-U4JGKZ56.mjs";
|
|
8
|
+
import {
|
|
9
|
+
get
|
|
10
|
+
} from "../chunk-4RQPJUPQ.mjs";
|
|
5
11
|
import {
|
|
6
12
|
invert
|
|
7
13
|
} from "../chunk-OLX53VEF.mjs";
|
|
@@ -14,12 +20,10 @@ import {
|
|
|
14
20
|
import {
|
|
15
21
|
pick
|
|
16
22
|
} from "../chunk-HPFDYUGP.mjs";
|
|
17
|
-
import {
|
|
18
|
-
pickBy
|
|
19
|
-
} from "../chunk-6CLH5YZ2.mjs";
|
|
20
23
|
import "../chunk-2MM5EJJX.mjs";
|
|
21
24
|
export {
|
|
22
25
|
clone,
|
|
26
|
+
get,
|
|
23
27
|
invert,
|
|
24
28
|
omit,
|
|
25
29
|
omitBy,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.10.1-dev.
|
|
4
|
+
"version": "1.10.1-dev.248+a186e5d4",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
package/dist/chunk-OSOLEQLZ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-OSOLEQLZ.mjs.map
|
|
File without changes
|