@tsfun/object
Advanced tools
| export declare function mutObj<Object, Key extends string | number | symbol, Value>(object: Object, key: Key, value: Value): asserts object is Object & Record<Key, Value>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const { defineProperty } = Object; | ||
| function mutObj(object, key, value) { | ||
| defineProperty(object, key, { | ||
| enumerable: true, | ||
| writable: true, | ||
| configurable: true, | ||
| value | ||
| }); | ||
| } | ||
| exports.mutObj = mutObj; | ||
| //# sourceMappingURL=mut-obj.js.map |
| const { | ||
| defineProperty | ||
| } = Object; | ||
| export function mutObj(object, key, value) { | ||
| defineProperty(object, key, { | ||
| enumerable: true, | ||
| writable: true, | ||
| configurable: true, | ||
| value | ||
| }); | ||
| } //# sourceMappingURL=mut-obj.js.map |
| export declare function mutObj<Object, Key extends string | number | symbol, Value>(object: Object, key: Key, value: Value): asserts object is Object & Record<Key, Value>; |
+2
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const mut_obj_1 = require("./utils/mut-obj"); | ||
| /** | ||
@@ -13,3 +14,3 @@ * Create an object with `proto` as prototype | ||
| const object = Object.create(proto); | ||
| object[key] = value; | ||
| mut_obj_1.mutObj(object, key, value); | ||
| return object; | ||
@@ -16,0 +17,0 @@ } |
+3
-1
@@ -0,1 +1,2 @@ | ||
| import { mutObj } from "./utils/mut-obj.mjs"; | ||
| /** | ||
@@ -9,7 +10,8 @@ * Create an object with `proto` as prototype | ||
| */ | ||
| export function addProperty(proto, key, value) { | ||
| const object = Object.create(proto); | ||
| object[key] = value; | ||
| mutObj(object, key, value); | ||
| return object; | ||
| } | ||
| export default addProperty; //# sourceMappingURL=add-property.js.map |
+9
-8
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const mut_obj_1 = require("./utils/mut-obj"); | ||
| const isObject = (value) => value && typeof value === 'object' && !Array.isArray(value); | ||
@@ -19,12 +20,12 @@ /** | ||
| const rightValue = right[key]; | ||
| result[key] = deepMergeWithPreference(leftValue, rightValue, resolveConflict); | ||
| mut_obj_1.mutObj(result, key, deepMergeWithPreference(leftValue, rightValue, resolveConflict)); | ||
| } | ||
| else { | ||
| result[key] = leftValue; | ||
| mut_obj_1.mutObj(result, key, leftValue); | ||
| } | ||
| } | ||
| for (const [key, bValue] of Object.entries(right)) { | ||
| for (const [key, rightValue] of Object.entries(right)) { | ||
| if (key in left) | ||
| continue; | ||
| result[key] = bValue; | ||
| mut_obj_1.mutObj(result, key, rightValue); | ||
| } | ||
@@ -75,3 +76,3 @@ return result; | ||
| if (isObject(leftValue) && isObject(rightValue)) { | ||
| result[key] = deepMergeWithoutCollision(leftValue, rightValue, onerror); | ||
| mut_obj_1.mutObj(result, key, deepMergeWithoutCollision(leftValue, rightValue, onerror)); | ||
| } | ||
@@ -88,9 +89,9 @@ else { | ||
| else { | ||
| result[key] = leftValue; | ||
| mut_obj_1.mutObj(result, key, leftValue); | ||
| } | ||
| } | ||
| for (const [key, bValue] of Object.entries(right)) { | ||
| for (const [key, rightValue] of Object.entries(right)) { | ||
| if (key in left) | ||
| continue; | ||
| result[key] = bValue; | ||
| mut_obj_1.mutObj(result, key, rightValue); | ||
| } | ||
@@ -97,0 +98,0 @@ return result; |
+10
-8
@@ -0,1 +1,3 @@ | ||
| import { mutObj } from "./utils/mut-obj.mjs"; | ||
| const isObject = value => value && typeof value === 'object' && !Array.isArray(value); | ||
@@ -21,11 +23,11 @@ /** | ||
| const rightValue = right[key]; | ||
| result[key] = deepMergeWithPreference(leftValue, rightValue, resolveConflict); | ||
| mutObj(result, key, deepMergeWithPreference(leftValue, rightValue, resolveConflict)); | ||
| } else { | ||
| result[key] = leftValue; | ||
| mutObj(result, key, leftValue); | ||
| } | ||
| } | ||
| for (const [key, bValue] of Object.entries(right)) { | ||
| for (const [key, rightValue] of Object.entries(right)) { | ||
| if (key in left) continue; | ||
| result[key] = bValue; | ||
| mutObj(result, key, rightValue); | ||
| } | ||
@@ -85,3 +87,3 @@ | ||
| if (isObject(leftValue) && isObject(rightValue)) { | ||
| result[key] = deepMergeWithoutCollision(leftValue, rightValue, onerror); | ||
| mutObj(result, key, deepMergeWithoutCollision(leftValue, rightValue, onerror)); | ||
| } else { | ||
@@ -98,9 +100,9 @@ throw onerror({ | ||
| } else { | ||
| result[key] = leftValue; | ||
| mutObj(result, key, leftValue); | ||
| } | ||
| } | ||
| for (const [key, bValue] of Object.entries(right)) { | ||
| for (const [key, rightValue] of Object.entries(right)) { | ||
| if (key in left) continue; | ||
| result[key] = bValue; | ||
| mutObj(result, key, rightValue); | ||
| } | ||
@@ -107,0 +109,0 @@ |
@@ -9,3 +9,3 @@ import { ObjectExtends } from './utils/types'; | ||
| */ | ||
| export declare function objectExtends<Proto extends object | null, Properties extends object | null>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>; | ||
| export declare function objectExtends<Proto extends object | null, Properties extends object>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>; | ||
| export default objectExtends; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const mut_obj_1 = require("./utils/mut-obj"); | ||
| /** | ||
@@ -10,3 +11,7 @@ * Create an object with `proto` as prototype | ||
| function objectExtends(proto, properties) { | ||
| return Object.assign(Object.create(proto), properties); | ||
| const object = Object.create(proto); | ||
| const makeProp = (key) => mut_obj_1.mutObj(object, key, properties[key]); | ||
| Object.getOwnPropertyNames(properties).forEach(makeProp); | ||
| Object.getOwnPropertySymbols(properties).forEach(makeProp); | ||
| return object; | ||
| } | ||
@@ -13,0 +18,0 @@ exports.objectExtends = objectExtends; |
@@ -0,1 +1,2 @@ | ||
| import { mutObj } from "./utils/mut-obj.mjs"; | ||
| /** | ||
@@ -7,5 +8,12 @@ * Create an object with `proto` as prototype | ||
| */ | ||
| export function objectExtends(proto, properties) { | ||
| return Object.assign(Object.create(proto), properties); | ||
| const object = Object.create(proto); | ||
| const makeProp = key => mutObj(object, key, properties[key]); | ||
| Object.getOwnPropertyNames(properties).forEach(makeProp); | ||
| Object.getOwnPropertySymbols(properties).forEach(makeProp); | ||
| return object; | ||
| } | ||
| export default objectExtends; //# sourceMappingURL=object-extends.js.map |
@@ -9,3 +9,3 @@ import { ObjectExtends } from './utils/types'; | ||
| */ | ||
| export declare function objectExtends<Proto extends object | null, Properties extends object | null>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>; | ||
| export declare function objectExtends<Proto extends object | null, Properties extends object>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>; | ||
| export default objectExtends; |
+1
-1
| { | ||
| "name": "@tsfun/object", | ||
| "version": "0.0.14", | ||
| "version": "0.0.15", | ||
| "description": "Utilities related to objects", | ||
@@ -5,0 +5,0 @@ "author": "Hoàng Văn Khải <hvksmr1996@gmail.com>", |
+2
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const mut_obj_1 = require("./utils/mut-obj"); | ||
| /** | ||
@@ -12,3 +13,3 @@ * Pick properties from an object into a new object | ||
| for (const key of keys) { | ||
| result[key] = object[key]; | ||
| mut_obj_1.mutObj(result, key, object[key]); | ||
| } | ||
@@ -15,0 +16,0 @@ return result; |
+3
-1
@@ -0,1 +1,2 @@ | ||
| import { mutObj } from "./utils/mut-obj.mjs"; | ||
| /** | ||
@@ -7,2 +8,3 @@ * Pick properties from an object into a new object | ||
| */ | ||
| export function pick(object, keys) { | ||
@@ -12,3 +14,3 @@ const result = {}; | ||
| for (const key of keys) { | ||
| result[key] = object[key]; | ||
| mutObj(result, key, object[key]); | ||
| } | ||
@@ -15,0 +17,0 @@ |
+4
-2
@@ -22,4 +22,6 @@ "use strict"; | ||
| const { [key]: nextTarget, ...cloned } = object; | ||
| cloned[key] = setPropertyPath(nextTarget, nextPath, value); | ||
| return cloned; | ||
| return { | ||
| ...cloned, | ||
| [key]: setPropertyPath(nextTarget, nextPath, value) | ||
| }; | ||
| } | ||
@@ -26,0 +28,0 @@ exports.setPropertyPath = setPropertyPath; |
@@ -17,4 +17,5 @@ const isObject = object => typeof object === 'object' && object; | ||
| } = object; | ||
| cloned[key] = setPropertyPath(nextTarget, nextPath, value); | ||
| return cloned; | ||
| return { ...cloned, | ||
| [key]: setPropertyPath(nextTarget, nextPath, value) | ||
| }; | ||
| } | ||
@@ -21,0 +22,0 @@ export function deletePropertyPath(object, path) { |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
52269
3.8%53
8.16%1307
3.4%0
-100%