es-toolkit 1.12.0-dev.281 → 1.12.0-dev.283

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 (48) hide show
  1. package/dist/{chunk-Y5V7UAZZ.mjs → chunk-32AEPQYI.mjs} +4 -4
  2. package/dist/chunk-54TK5BIS.mjs +1 -0
  3. package/dist/chunk-MIGAC7F4.mjs +25 -0
  4. package/dist/chunk-MIGAC7F4.mjs.map +1 -0
  5. package/dist/chunk-WGX4WINP.mjs +1 -0
  6. package/dist/chunk-XGQWTHW6.mjs +34 -0
  7. package/dist/chunk-XGQWTHW6.mjs.map +1 -0
  8. package/dist/compat/index.d.mts +26 -1
  9. package/dist/compat/index.d.ts +26 -1
  10. package/dist/compat/index.js +81 -0
  11. package/dist/compat/index.js.map +1 -1
  12. package/dist/compat/index.mjs +53 -17
  13. package/dist/compat/index.mjs.map +1 -1
  14. package/dist/index.d.mts +2 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +51 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +25 -17
  19. package/dist/object/flattenObject.d.mts +28 -0
  20. package/dist/object/flattenObject.d.ts +28 -0
  21. package/dist/object/flattenObject.js +77 -0
  22. package/dist/object/flattenObject.js.map +1 -0
  23. package/dist/object/flattenObject.mjs +9 -0
  24. package/dist/object/flattenObject.mjs.map +1 -0
  25. package/dist/object/index.d.mts +1 -0
  26. package/dist/object/index.d.ts +1 -0
  27. package/dist/object/index.js +49 -0
  28. package/dist/object/index.js.map +1 -1
  29. package/dist/object/index.mjs +9 -4
  30. package/dist/predicate/index.d.mts +1 -0
  31. package/dist/predicate/index.d.ts +1 -0
  32. package/dist/predicate/index.js +23 -0
  33. package/dist/predicate/index.js.map +1 -1
  34. package/dist/predicate/index.mjs +7 -3
  35. package/dist/predicate/isPlainObject.d.mts +16 -0
  36. package/dist/predicate/isPlainObject.d.ts +16 -0
  37. package/dist/predicate/isPlainObject.js +49 -0
  38. package/dist/predicate/isPlainObject.js.map +1 -0
  39. package/dist/predicate/isPlainObject.mjs +8 -0
  40. package/dist/predicate/isPlainObject.mjs.map +1 -0
  41. package/dist/string/camelCase.mjs +2 -2
  42. package/dist/string/index.mjs +8 -8
  43. package/package.json +1 -1
  44. package/dist/chunk-ASJF5D6C.mjs +0 -1
  45. package/dist/chunk-OSOLEQLZ.mjs +0 -1
  46. /package/dist/{chunk-Y5V7UAZZ.mjs.map → chunk-32AEPQYI.mjs.map} +0 -0
  47. /package/dist/{chunk-ASJF5D6C.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
  48. /package/dist/{chunk-OSOLEQLZ.mjs.map → chunk-WGX4WINP.mjs.map} +0 -0
@@ -1,9 +1,9 @@
1
- import {
2
- capitalize
3
- } from "./chunk-U56ZOM7L.mjs";
4
1
  import {
5
2
  getWords
6
3
  } from "./chunk-WVQ7YVRK.mjs";
4
+ import {
5
+ capitalize
6
+ } from "./chunk-U56ZOM7L.mjs";
7
7
 
8
8
  // src/string/camelCase.ts
9
9
  function camelCase(str) {
@@ -18,4 +18,4 @@ function camelCase(str) {
18
18
  export {
19
19
  camelCase
20
20
  };
21
- //# sourceMappingURL=chunk-Y5V7UAZZ.mjs.map
21
+ //# sourceMappingURL=chunk-32AEPQYI.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-54TK5BIS.mjs.map
@@ -0,0 +1,25 @@
1
+ // src/predicate/isPlainObject.ts
2
+ function isPlainObject(object) {
3
+ if (typeof object !== "object") {
4
+ return false;
5
+ }
6
+ if (object == null) {
7
+ return false;
8
+ }
9
+ if (Object.getPrototypeOf(object) === null) {
10
+ return true;
11
+ }
12
+ if (object.toString() !== "[object Object]") {
13
+ return false;
14
+ }
15
+ let proto = object;
16
+ while (Object.getPrototypeOf(proto) !== null) {
17
+ proto = Object.getPrototypeOf(proto);
18
+ }
19
+ return Object.getPrototypeOf(object) === proto;
20
+ }
21
+
22
+ export {
23
+ isPlainObject
24
+ };
25
+ //# sourceMappingURL=chunk-MIGAC7F4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/predicate/isPlainObject.ts"],"sourcesContent":["/**\n * Checks if a given value is a plain object.\n * \n * @param {object} object - The value to check.\n * @returns {boolean} - True if the value is a plain object, otherwise false.\n * \n * @example\n * console.log(isPlainObject({})); // true\n * console.log(isPlainObject([])); // false\n * console.log(isPlainObject(null)); // false\n * console.log(isPlainObject(Object.create(null))); // true\n * console.log(Buffer.from('hello, world')); // false\n */\nexport function isPlainObject(object: object): boolean {\n if (typeof object !== 'object') {\n return false;\n }\n\n if (object == null) {\n return false;\n }\n\n if (Object.getPrototypeOf(object) === null) {\n return true;\n }\n\n if (object.toString() !== '[object Object]') {\n return false;\n }\n\n let proto = object;\n\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(object) === proto;\n}"],"mappings":";AAaO,SAAS,cAAc,QAAyB;AACrD,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,eAAe,MAAM,MAAM,MAAM;AAC1C,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,MAAM,mBAAmB;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ;AAEZ,SAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,YAAQ,OAAO,eAAe,KAAK;AAAA,EACrC;AAEA,SAAO,OAAO,eAAe,MAAM,MAAM;AAC3C;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-WGX4WINP.mjs.map
@@ -0,0 +1,34 @@
1
+ import {
2
+ isPlainObject
3
+ } from "./chunk-MIGAC7F4.mjs";
4
+
5
+ // src/object/flattenObject.ts
6
+ function flattenObject(object) {
7
+ return flattenObjectImpl(object);
8
+ }
9
+ function flattenObjectImpl(object, prefix = "") {
10
+ const result = {};
11
+ const keys = Object.keys(object);
12
+ for (let i = 0; i < keys.length; i++) {
13
+ const key = keys[i];
14
+ const value = object[key];
15
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
16
+ if (isPlainObject(value) && Object.keys(value).length > 0) {
17
+ Object.assign(result, flattenObjectImpl(value, prefixedKey));
18
+ continue;
19
+ }
20
+ if (Array.isArray(value)) {
21
+ for (let index = 0; index < value.length; index++) {
22
+ result[`${prefixedKey}.${index}`] = value[index];
23
+ }
24
+ continue;
25
+ }
26
+ result[prefixedKey] = value;
27
+ }
28
+ return result;
29
+ }
30
+
31
+ export {
32
+ flattenObject
33
+ };
34
+ //# sourceMappingURL=chunk-XGQWTHW6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/object/flattenObject.ts"],"sourcesContent":["import { isPlainObject } from \"../predicate/isPlainObject.ts\";\n\n/**\n * Flattens a nested object into a single level object with dot-separated keys.\n * \n * @param {object} object - The object to flatten.\n * @returns {Record<string, any>} - The flattened object.\n * \n * @example\n * const nestedObject = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: [2, 3]\n * };\n * \n * const flattened = flattenObject(nestedObject);\n * console.log(flattened); \n * // Output:\n * // {\n * // 'a.b.c': 1,\n * // 'd.0': 2,\n * // 'd.1': 3\n * // }\n */\nexport function flattenObject(object: object): Record<string, any> {\n return flattenObjectImpl(object);\n}\n\nfunction flattenObjectImpl(object: object, prefix = ''): Record<string, any> {\n const result: Record<string, any> = {};\n const keys = Object.keys(object);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = (object as any)[key];\n\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(value) && Object.keys(value).length > 0) {\n Object.assign(result, flattenObjectImpl(value, prefixedKey));\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n result[`${prefixedKey}.${index}`] = value[index];\n }\n continue;\n }\n\n result[prefixedKey] = value;\n }\n\n return result;\n}"],"mappings":";;;;;AA2BO,SAAS,cAAc,QAAqC;AACjE,SAAO,kBAAkB,MAAM;AACjC;AAEA,SAAS,kBAAkB,QAAgB,SAAS,IAAyB;AAC3E,QAAM,SAA8B,CAAC;AACrC,QAAM,OAAO,OAAO,KAAK,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAS,OAAe,GAAG;AAEjC,UAAM,cAAc,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK;AAElD,QAAI,cAAc,KAAK,KAAK,OAAO,KAAK,KAAK,EAAE,SAAS,GAAG;AACzD,aAAO,OAAO,QAAQ,kBAAkB,OAAO,WAAW,CAAC;AAC3D;AAAA,IACF;AAEA,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAS,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;AACjD,eAAO,GAAG,WAAW,IAAI,KAAK,EAAE,IAAI,MAAM,KAAK;AAAA,MACjD;AACA;AAAA,IACF;AAEA,WAAO,WAAW,IAAI;AAAA,EACxB;AAEA,SAAO;AACT;","names":[]}
@@ -70,6 +70,7 @@ export { pick } from '../object/pick.mjs';
70
70
  export { pickBy } from '../object/pickBy.mjs';
71
71
  export { invert } from '../object/invert.mjs';
72
72
  export { clone } from '../object/clone.mjs';
73
+ export { flattenObject } from '../object/flattenObject.mjs';
73
74
  export { isEqual } from '../predicate/isEqual.mjs';
74
75
  export { isNil } from '../predicate/isNil.mjs';
75
76
  export { isNotNil } from '../predicate/isNotNil.mjs';
@@ -457,6 +458,30 @@ declare function get(object: unknown, path: PropertyKey | readonly PropertyKey[]
457
458
  */
458
459
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
459
460
 
461
+ /**
462
+ * Checks if a given value is a plain object.
463
+ *
464
+ * A plain object is an object created by the `{}` literal, `new Object()`, or
465
+ * `Object.create(null)`.
466
+ *
467
+ * This function also handles objects with custom
468
+ * `Symbol.toStringTag` properties.
469
+ *
470
+ * `Symbol.toStringTag` is a built-in symbol that a constructor can use to customize the
471
+ * default string description of objects.
472
+ *
473
+ * @param {unknown} [object] - The value to check.
474
+ * @returns {boolean} - True if the value is a plain object, otherwise false.
475
+ *
476
+ * @example
477
+ * console.log(isPlainObject({})); // true
478
+ * console.log(isPlainObject([])); // false
479
+ * console.log(isPlainObject(null)); // false
480
+ * console.log(isPlainObject(Object.create(null))); // true
481
+ * console.log(isPlainObject(new Map())); // false
482
+ */
483
+ declare function isPlainObject(object?: unknown): boolean;
484
+
460
485
  /**
461
486
  * Checks if a string contains another string at the beginning of the string.
462
487
  *
@@ -527,4 +552,4 @@ declare function max<T>(items?: readonly T[]): T;
527
552
  */
528
553
  declare function min<T>(items?: readonly T[]): T;
529
554
 
530
- export { chunk, concat, difference, endsWith, get, max, min, set, startsWith, zipObjectDeep };
555
+ export { chunk, concat, difference, endsWith, get, isPlainObject, max, min, set, startsWith, zipObjectDeep };
@@ -70,6 +70,7 @@ export { pick } from '../object/pick.js';
70
70
  export { pickBy } from '../object/pickBy.js';
71
71
  export { invert } from '../object/invert.js';
72
72
  export { clone } from '../object/clone.js';
73
+ export { flattenObject } from '../object/flattenObject.js';
73
74
  export { isEqual } from '../predicate/isEqual.js';
74
75
  export { isNil } from '../predicate/isNil.js';
75
76
  export { isNotNil } from '../predicate/isNotNil.js';
@@ -457,6 +458,30 @@ declare function get(object: unknown, path: PropertyKey | readonly PropertyKey[]
457
458
  */
458
459
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
459
460
 
461
+ /**
462
+ * Checks if a given value is a plain object.
463
+ *
464
+ * A plain object is an object created by the `{}` literal, `new Object()`, or
465
+ * `Object.create(null)`.
466
+ *
467
+ * This function also handles objects with custom
468
+ * `Symbol.toStringTag` properties.
469
+ *
470
+ * `Symbol.toStringTag` is a built-in symbol that a constructor can use to customize the
471
+ * default string description of objects.
472
+ *
473
+ * @param {unknown} [object] - The value to check.
474
+ * @returns {boolean} - True if the value is a plain object, otherwise false.
475
+ *
476
+ * @example
477
+ * console.log(isPlainObject({})); // true
478
+ * console.log(isPlainObject([])); // false
479
+ * console.log(isPlainObject(null)); // false
480
+ * console.log(isPlainObject(Object.create(null))); // true
481
+ * console.log(isPlainObject(new Map())); // false
482
+ */
483
+ declare function isPlainObject(object?: unknown): boolean;
484
+
460
485
  /**
461
486
  * Checks if a string contains another string at the beginning of the string.
462
487
  *
@@ -527,4 +552,4 @@ declare function max<T>(items?: readonly T[]): T;
527
552
  */
528
553
  declare function min<T>(items?: readonly T[]): T;
529
554
 
530
- export { chunk, concat, difference, endsWith, get, max, min, set, startsWith, zipObjectDeep };
555
+ export { chunk, concat, difference, endsWith, get, isPlainObject, max, min, set, startsWith, zipObjectDeep };
@@ -79,6 +79,7 @@ __export(compat_exports, {
79
79
  flatMap: () => flatMap,
80
80
  flatten: () => flatten,
81
81
  flattenDeep: () => flattenDeep,
82
+ flattenObject: () => flattenObject,
82
83
  forEachRight: () => forEachRight,
83
84
  get: () => get,
84
85
  groupBy: () => groupBy,
@@ -93,6 +94,7 @@ __export(compat_exports, {
93
94
  isNil: () => isNil,
94
95
  isNotNil: () => isNotNil,
95
96
  isNull: () => isNull,
97
+ isPlainObject: () => isPlainObject2,
96
98
  isUndefined: () => isUndefined,
97
99
  kebabCase: () => kebabCase,
98
100
  keyBy: () => keyBy,
@@ -926,6 +928,53 @@ function isPrimitive(value) {
926
928
  return value == null || typeof value !== "object" && typeof value !== "function";
927
929
  }
928
930
 
931
+ // src/predicate/isPlainObject.ts
932
+ function isPlainObject(object) {
933
+ if (typeof object !== "object") {
934
+ return false;
935
+ }
936
+ if (object == null) {
937
+ return false;
938
+ }
939
+ if (Object.getPrototypeOf(object) === null) {
940
+ return true;
941
+ }
942
+ if (object.toString() !== "[object Object]") {
943
+ return false;
944
+ }
945
+ let proto = object;
946
+ while (Object.getPrototypeOf(proto) !== null) {
947
+ proto = Object.getPrototypeOf(proto);
948
+ }
949
+ return Object.getPrototypeOf(object) === proto;
950
+ }
951
+
952
+ // src/object/flattenObject.ts
953
+ function flattenObject(object) {
954
+ return flattenObjectImpl(object);
955
+ }
956
+ function flattenObjectImpl(object, prefix = "") {
957
+ const result = {};
958
+ const keys = Object.keys(object);
959
+ for (let i = 0; i < keys.length; i++) {
960
+ const key = keys[i];
961
+ const value = object[key];
962
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
963
+ if (isPlainObject(value) && Object.keys(value).length > 0) {
964
+ Object.assign(result, flattenObjectImpl(value, prefixedKey));
965
+ continue;
966
+ }
967
+ if (Array.isArray(value)) {
968
+ for (let index = 0; index < value.length; index++) {
969
+ result[`${prefixedKey}.${index}`] = value[index];
970
+ }
971
+ continue;
972
+ }
973
+ result[prefixedKey] = value;
974
+ }
975
+ return result;
976
+ }
977
+
929
978
  // src/predicate/isEqual.ts
930
979
  function isEqual(a, b) {
931
980
  if (Object.is(a, b)) {
@@ -1211,6 +1260,36 @@ function get(object, path, defaultValue) {
1211
1260
  return current != null ? current : defaultValue;
1212
1261
  }
1213
1262
 
1263
+ // src/compat/predicate/isPlainObject.ts
1264
+ function isPlainObject2(object) {
1265
+ var _a;
1266
+ if (typeof object !== "object") {
1267
+ return false;
1268
+ }
1269
+ if (object == null) {
1270
+ return false;
1271
+ }
1272
+ if (Object.getPrototypeOf(object) === null) {
1273
+ return true;
1274
+ }
1275
+ if (object.toString() !== "[object Object]") {
1276
+ const tag = object[Symbol.toStringTag];
1277
+ if (tag == null) {
1278
+ return false;
1279
+ }
1280
+ const isTagReadonly = !((_a = Object.getOwnPropertyDescriptor(object, Symbol.toStringTag)) == null ? void 0 : _a.writable);
1281
+ if (isTagReadonly) {
1282
+ return false;
1283
+ }
1284
+ return object.toString() === `[object ${tag}]`;
1285
+ }
1286
+ let proto = object;
1287
+ while (Object.getPrototypeOf(proto) !== null) {
1288
+ proto = Object.getPrototypeOf(proto);
1289
+ }
1290
+ return Object.getPrototypeOf(object) === proto;
1291
+ }
1292
+
1214
1293
  // src/compat/string/startsWith.ts
1215
1294
  var startsWith = (str, target, position = 0) => {
1216
1295
  return str.startsWith(target, position);
@@ -1273,6 +1352,7 @@ function min(items = []) {
1273
1352
  flatMap,
1274
1353
  flatten,
1275
1354
  flattenDeep,
1355
+ flattenObject,
1276
1356
  forEachRight,
1277
1357
  get,
1278
1358
  groupBy,
@@ -1287,6 +1367,7 @@ function min(items = []) {
1287
1367
  isNil,
1288
1368
  isNotNil,
1289
1369
  isNull,
1370
+ isPlainObject,
1290
1371
  isUndefined,
1291
1372
  kebabCase,
1292
1373
  keyBy,