🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@tsfun/object

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsfun/object - npm Package Compare versions

Comparing version
0.0.14
to
0.0.15
+1
utils/mut-obj.d.ts
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 @@ }

@@ -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
"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;

@@ -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;
{
"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>",

"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;

@@ -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 @@

@@ -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) {