es-toolkit 1.29.0-dev.954 → 1.29.0-dev.956
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +22 -0
- package/dist/compat/index.mjs +1 -0
- package/dist/compat/util/toPlainObject.d.mts +16 -0
- package/dist/compat/util/toPlainObject.d.ts +16 -0
- package/dist/compat/util/toPlainObject.mjs +24 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -251,5 +251,6 @@ export { toInteger } from './util/toInteger.mjs';
|
|
|
251
251
|
export { toLength } from './util/toLength.mjs';
|
|
252
252
|
export { toNumber } from './util/toNumber.mjs';
|
|
253
253
|
export { toPath } from './util/toPath.mjs';
|
|
254
|
+
export { toPlainObject } from './util/toPlainObject.mjs';
|
|
254
255
|
export { toSafeInteger } from './util/toSafeInteger.mjs';
|
|
255
256
|
export { toString } from './util/toString.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -251,5 +251,6 @@ export { toInteger } from './util/toInteger.js';
|
|
|
251
251
|
export { toLength } from './util/toLength.js';
|
|
252
252
|
export { toNumber } from './util/toNumber.js';
|
|
253
253
|
export { toPath } from './util/toPath.js';
|
|
254
|
+
export { toPlainObject } from './util/toPlainObject.js';
|
|
254
255
|
export { toSafeInteger } from './util/toSafeInteger.js';
|
|
255
256
|
export { toString } from './util/toString.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -2971,6 +2971,27 @@ function toLength(value) {
|
|
|
2971
2971
|
return clamp(length, 0, MAX_ARRAY_LENGTH);
|
|
2972
2972
|
}
|
|
2973
2973
|
|
|
2974
|
+
function toPlainObject(value) {
|
|
2975
|
+
const plainObject = {};
|
|
2976
|
+
const valueKeys = keysIn(value);
|
|
2977
|
+
for (let i = 0; i < valueKeys.length; i++) {
|
|
2978
|
+
const key = valueKeys[i];
|
|
2979
|
+
const objValue = value[key];
|
|
2980
|
+
if (key === '__proto__') {
|
|
2981
|
+
Object.defineProperty(plainObject, key, {
|
|
2982
|
+
configurable: true,
|
|
2983
|
+
enumerable: true,
|
|
2984
|
+
value: objValue,
|
|
2985
|
+
writable: true,
|
|
2986
|
+
});
|
|
2987
|
+
}
|
|
2988
|
+
else {
|
|
2989
|
+
plainObject[key] = objValue;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
return plainObject;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2974
2995
|
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
2975
2996
|
|
|
2976
2997
|
function toSafeInteger(value) {
|
|
@@ -3222,6 +3243,7 @@ exports.toLength = toLength;
|
|
|
3222
3243
|
exports.toLower = toLower;
|
|
3223
3244
|
exports.toNumber = toNumber;
|
|
3224
3245
|
exports.toPath = toPath;
|
|
3246
|
+
exports.toPlainObject = toPlainObject;
|
|
3225
3247
|
exports.toSafeInteger = toSafeInteger;
|
|
3226
3248
|
exports.toString = toString;
|
|
3227
3249
|
exports.toUpper = toUpper;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -251,5 +251,6 @@ export { toInteger } from './util/toInteger.mjs';
|
|
|
251
251
|
export { toLength } from './util/toLength.mjs';
|
|
252
252
|
export { toNumber } from './util/toNumber.mjs';
|
|
253
253
|
export { toPath } from './util/toPath.mjs';
|
|
254
|
+
export { toPlainObject } from './util/toPlainObject.mjs';
|
|
254
255
|
export { toSafeInteger } from './util/toSafeInteger.mjs';
|
|
255
256
|
export { toString } from './util/toString.mjs';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} value The value to convert.
|
|
5
|
+
* @returns {Record<string, any>} Returns the converted plain object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* function Foo() {
|
|
9
|
+
* this.b = 2;
|
|
10
|
+
* }
|
|
11
|
+
* Foo.prototype.c = 3;
|
|
12
|
+
* toPlainObject(new Foo()); // { b: 2, c: 3 }
|
|
13
|
+
*/
|
|
14
|
+
declare function toPlainObject(value: any): Record<string, any>;
|
|
15
|
+
|
|
16
|
+
export { toPlainObject };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} value The value to convert.
|
|
5
|
+
* @returns {Record<string, any>} Returns the converted plain object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* function Foo() {
|
|
9
|
+
* this.b = 2;
|
|
10
|
+
* }
|
|
11
|
+
* Foo.prototype.c = 3;
|
|
12
|
+
* toPlainObject(new Foo()); // { b: 2, c: 3 }
|
|
13
|
+
*/
|
|
14
|
+
declare function toPlainObject(value: any): Record<string, any>;
|
|
15
|
+
|
|
16
|
+
export { toPlainObject };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { keysIn } from '../object/keysIn.mjs';
|
|
2
|
+
|
|
3
|
+
function toPlainObject(value) {
|
|
4
|
+
const plainObject = {};
|
|
5
|
+
const valueKeys = keysIn(value);
|
|
6
|
+
for (let i = 0; i < valueKeys.length; i++) {
|
|
7
|
+
const key = valueKeys[i];
|
|
8
|
+
const objValue = value[key];
|
|
9
|
+
if (key === '__proto__') {
|
|
10
|
+
Object.defineProperty(plainObject, key, {
|
|
11
|
+
configurable: true,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
value: objValue,
|
|
14
|
+
writable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
plainObject[key] = objValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return plainObject;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { toPlainObject };
|
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.29.0-dev.
|
|
4
|
+
"version": "1.29.0-dev.956+07ca421d",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|