🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
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.18
to
0.0.19
+1
-1
add-property.js

@@ -0,1 +1,2 @@

/// <reference path="add-property.d.ts" />
"use strict";

@@ -19,2 +20,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.default = addProperty;
//# sourceMappingURL=add-property.js.map

@@ -0,1 +1,2 @@

/// <reference path="add-property.d.ts" />
/**

@@ -15,2 +16,2 @@ * Create an object with `proto` as prototype

}
export default addProperty; //# sourceMappingURL=add-property.js.map
export default addProperty;

@@ -0,1 +1,2 @@

/// <reference path="call-method.d.ts" />
"use strict";

@@ -51,2 +52,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.methodGetter = (object) => (name) => exports.getMethod(object, name);
//# sourceMappingURL=call-method.js.map

@@ -0,1 +1,2 @@

/// <reference path="call-method.d.ts" />
import { bindContext } from "./utils/bind.mjs";

@@ -52,2 +53,2 @@ /**

export const methodGetter = object => name => getMethod(object, name); //# sourceMappingURL=call-method.js.map
export const methodGetter = object => name => getMethod(object, name);

@@ -0,1 +1,2 @@

/// <reference path="deep-merge.d.ts" />
"use strict";

@@ -125,2 +126,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
//# sourceMappingURL=deep-merge.js.map

@@ -0,1 +1,2 @@

/// <reference path="deep-merge.d.ts" />
import { mutObj } from "./utils/mut-obj.mjs";

@@ -143,2 +144,2 @@

ErrorType[ErrorType["PropertyCollision"] = 1] = "PropertyCollision";
})(ErrorType || (ErrorType = {})); //# sourceMappingURL=deep-merge.js.map
})(ErrorType || (ErrorType = {}));

@@ -0,1 +1,2 @@

/// <reference path="get-property.d.ts" />
"use strict";

@@ -22,2 +23,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.propertyGetter = (object) => (key) => object[key];
//# sourceMappingURL=get-property.js.map

@@ -0,1 +1,2 @@

/// <reference path="get-property.d.ts" />
/**

@@ -21,2 +22,2 @@ * Create a function that accesses a particular key from an object

export const propertyGetter = object => key => object[key]; //# sourceMappingURL=get-property.js.map
export const propertyGetter = object => key => object[key];

@@ -0,1 +1,2 @@

/// <reference path="index.d.ts" />
"use strict";

@@ -13,2 +14,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

tslib_1.__exportStar(require("./omit"), exports);
//# sourceMappingURL=index.js.map

@@ -0,1 +1,2 @@

/// <reference path="index.d.ts" />
export * from "./add-property.mjs";

@@ -9,2 +10,2 @@ export * from "./set-property.mjs";

export * from "./pick.mjs";
export * from "./omit.mjs"; //# sourceMappingURL=index.js.map
export * from "./omit.mjs";

@@ -0,1 +1,2 @@

/// <reference path="object-extends.d.ts" />
"use strict";

@@ -19,2 +20,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.default = objectExtends;
//# sourceMappingURL=object-extends.js.map

@@ -0,1 +1,2 @@

/// <reference path="object-extends.d.ts" />
import { mutObj } from "./utils/mut-obj.mjs";

@@ -18,2 +19,2 @@ /**

}
export default objectExtends; //# sourceMappingURL=object-extends.js.map
export default objectExtends;

@@ -0,1 +1,2 @@

/// <reference path="omit.d.ts" />
"use strict";

@@ -28,2 +29,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.omitOne = omitOne;
//# sourceMappingURL=omit.js.map

@@ -0,1 +1,2 @@

/// <reference path="omit.d.ts" />
/**

@@ -30,2 +31,2 @@ * Creates a shallow clone of an object without certain properties

return result;
} //# sourceMappingURL=omit.js.map
}
{
"name": "@tsfun/object",
"version": "0.0.18",
"version": "0.0.19",
"description": "Utilities related to objects",

@@ -5,0 +5,0 @@ "author": "Hoàng Văn Khải <hvksmr1996@gmail.com>",

@@ -0,1 +1,2 @@

/// <reference path="pick.d.ts" />
"use strict";

@@ -25,2 +26,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.pickOne = (object, key) => ({ [key]: object[key] });
//# sourceMappingURL=pick.js.map

@@ -0,1 +1,2 @@

/// <reference path="pick.d.ts" />
import { mutObj } from "./utils/mut-obj.mjs";

@@ -27,2 +28,2 @@ /**

[key]: object[key]
}); //# sourceMappingURL=pick.js.map
});

@@ -0,1 +1,2 @@

/// <reference path="property-path.d.ts" />
"use strict";

@@ -43,2 +44,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.deletePropertyPath = deletePropertyPath;
//# sourceMappingURL=property-path.js.map

@@ -0,1 +1,2 @@

/// <reference path="property-path.d.ts" />
const isObject = object => typeof object === 'object' && object;

@@ -33,2 +34,2 @@

};
} //# sourceMappingURL=property-path.js.map
}

@@ -0,1 +1,2 @@

/// <reference path="set-property.d.ts" />
"use strict";

@@ -15,2 +16,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.default = exports.setProperty;
//# sourceMappingURL=set-property.js.map

@@ -0,1 +1,2 @@

/// <reference path="set-property.d.ts" />
/**

@@ -11,2 +12,2 @@ * Shallow clone an object and alter one property

});
export default setProperty; //# sourceMappingURL=set-property.js.map
export default setProperty;

@@ -0,1 +1,2 @@

/// <reference path="bind.d.ts" />
"use strict";

@@ -5,2 +6,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.bindContext = (fn, ctx) => protoBind.call(fn, ctx);
//# sourceMappingURL=bind.js.map

@@ -0,2 +1,3 @@

/// <reference path="bind.d.ts" />
const protoBind = Function.prototype.bind;
export const bindContext = (fn, ctx) => protoBind.call(fn, ctx); //# sourceMappingURL=bind.js.map
export const bindContext = (fn, ctx) => protoBind.call(fn, ctx);

@@ -0,1 +1,2 @@

/// <reference path="mut-obj.d.ts" />
"use strict";

@@ -13,2 +14,1 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.mutObj = mutObj;
//# sourceMappingURL=mut-obj.js.map

@@ -0,1 +1,2 @@

/// <reference path="mut-obj.d.ts" />
const {

@@ -11,2 +12,2 @@ defineProperty

});
} //# sourceMappingURL=mut-obj.js.map
}

@@ -0,3 +1,3 @@

/// <reference path="types.d.ts" />
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

@@ -1,1 +0,1 @@

//# sourceMappingURL=types.js.map
/// <reference path="types.d.ts" />
import { AddProperty } from './utils/types';
export { AddProperty };
/**
* Create an object with `proto` as prototype
* and `[key]: value` as the only own properties
* @note If you need own properties, use `setProperty` instead
* @note If `key` is a property setter in `proto` (such as `__proto__`), the setter will be invoked
* @param proto Prototype to extends upon
* @param key Property key
* @param value Property value
*/
export declare function addProperty<Proto extends object | null, Key extends string | number | symbol, Value>(proto: Proto, key: Key, value: Value): AddProperty<Proto, Key, Value>;
export default addProperty;
import { SingleDict, MaybeParam, MaybeReturn } from './utils/types';
/**
* Create a function that executes a particular method of an object
* @param name Method name
* @returns Function that executes method `[name]` of an object
*/
export declare function methodApplierOf<MethodName extends string | number | symbol>(name: MethodName): <Args extends readonly any[], Return>(object: SingleDict<MethodName, (...args: Args) => Return>, args: Args) => Return;
/**
* Create a function that executes a particular method of an object
* @param name Method name
* @returns Function that executes method `[name]` of an object
*/
export declare function methodCallerOf<MethodName extends string | number | symbol>(name: MethodName): <Args extends readonly any[], Return>(object: SingleDict<MethodName, (...args: Args) => Return>, ...args: Args) => Return;
/**
* Execute a method
* @param object Object that has the method
* @param name Name of the method
* @param args Arguments to pass to the method
* @returns Returning value of the method
*/
export declare const applyMethod: <Object_1 extends object, MethodName extends { [K in keyof Object_1]-?: import("utility-types").NonUndefined<Object_1[K]> extends Function ? K : never; }[keyof Object_1], Method extends Object_1[MethodName]>(object: Object_1, name: MethodName, args: Readonly<MaybeParam<Method>>) => MaybeReturn<Method>;
/**
* Execute a method
* @param object Object that has the method
* @param name Name of the method
* @param args Arguments to pass to the method
* @returns Returning value of the method
*/
export declare const callMethod: <Object_1 extends object, MethodName extends { [K in keyof Object_1]-?: import("utility-types").NonUndefined<Object_1[K]> extends Function ? K : never; }[keyof Object_1], Method extends Object_1[MethodName]>(object: Object_1, name: MethodName, ...args: MaybeParam<Method>) => MaybeReturn<Method>;
/**
* Get a method from and bind it to an object
* @param object Object to get method from
* @param name Name of the method
* @returns Bound method
*/
export declare const getMethod: <Object_1 extends object, MethodName extends { [K in keyof Object_1]-?: import("utility-types").NonUndefined<Object_1[K]> extends Function ? K : never; }[keyof Object_1], Method extends Object_1[MethodName]>(object: Object_1, name: MethodName) => OmitThisParameter<Method>;
/**
* Create a function that get methods of an object
* @param object Object to get methods from
* @returns A function that get object method
*/
export declare const methodGetter: <Object_1 extends object>(object: Object_1) => <MethodName extends { [K in keyof Object_1]-?: import("utility-types").NonUndefined<Object_1[K]> extends Function ? K : never; }[keyof Object_1], Method extends Object_1[MethodName]>(name: MethodName) => OmitThisParameter<Method>;
import { DeepPartialNonArray as DeepPartial, SimpleDeepMerge as DeepMergeWithoutCollision } from './utils/types';
export { DeepPartial, DeepMergeWithoutCollision };
/**
* Merge two objects of the same interface
* @param left Object or value to merge
* @param right Object or value to merge
* @param resolveConflict Function that resolves property conflict
* @returns Result of the merge
*/
export declare function deepMergeWithPreference<Value>(left: Value, right: Value, resolveConflict: PropertyConflictResolver): Value;
/**
* Merge two objects of the same interface
*
* `left` is prioritized for overlapping non-object properties
*
* @param left Object or value to merge
* @param right Object or value to merge
* @returns Result of the merge
*/
export declare function deepMergeOverwrite<Value>(left: Value, right: Value): Value;
/**
* Merge an object and a partial object of the same interface
* @param left Object to merge
* @param right Partial object to merge
* @param resolveConflict Function that resolves property conflict
* @returns Result of the merge
*/
export declare function deepMergePartial<Object>(left: Object, right: DeepPartial<Object>, resolveConflict: PropertyConflictResolver): Object;
/**
* Merge two objects
*
* The two objects are expected to not have overlapping non-object properties
*
* @param left Object to merge
* @param right Object to merge
* @param onerror Function to handle should error occurs
* @returns A merged object of `a` and `b`
*/
export declare function deepMergeWithoutCollision<Left extends object, Right extends object>(left: Left, right: Right, onerror?: ErrorProcessor): DeepMergeWithoutCollision<Left, Right>;
/**
* Decides which property should make it to the merged object
*/
export interface PropertyConflictResolver {
/**
* @param values Pair of conflicting properties
* @returns Property choice
*/
(values: [unknown, unknown]): PropertyPreference;
}
/**
* Choice to be made
*/
export declare const enum PropertyPreference {
/**
* Choose the left value (`values[0]`)
*/
Left = 0,
/**
* Choose the right value (`values[1]`)
*/
Right = 1
}
/**
* Process and transform errors of `deepMergeWithoutCollision`
*/
export interface ErrorProcessor {
/**
* @param param Error information
* @returns An error object
*/
(param: ErrorProcessorParam): unknown;
}
/**
* Param to pass to {@link ErrorProcessor} should {@link deepMergeWithoutCollision} fails
*/
export declare type ErrorProcessorParam = PropertyCollision;
/**
* Code of errors that `deepMergeWithoutCollision may cause
*/
export declare const enum ErrorType {
/**
* Indicates that two merging objects possess properties of same name
*/
PropertyCollision = 1
}
/**
* Param to pass to {@link ErrorProcessor} should two merging objects possess properties of same name
*/
export interface PropertyCollision {
/**
* Type of error
* @discriminator
*/
type: ErrorType.PropertyCollision;
/**
* Two merging object
*/
objects: [object, object];
/**
* Name of conflicting properties
*/
key: string;
/**
* Values of conflicting properties
*/
values: [unknown, unknown];
}
import { SingleDict } from './utils/types';
/**
* Create a function that accesses a particular key from an object
* @param key Property key
* @returns Function that accesses `[key]` of an object
*/
export declare const propertyOf: <Key extends string | number | symbol>(key: Key) => <Value>(object: SingleDict<Key, Value>) => Value;
/**
* Access a property from an object
* @param object Object to get property from
* @param key Property key
* @returns Property value
*/
export declare const getProperty: <Object_1 extends object, Key extends keyof Object_1 = keyof Object_1>(object: Object_1, key: Key) => Object_1[Key];
export interface PropertyGetter<Object> {
/**
* Access a property
* @param key Property key
* @returns Property value
*/
<Key extends keyof Object>(key: Key): Object[Key];
}
/**
* Create a function that lookups properties of an object
* @param object Object to get properties from
* @returns A function that lookup an object property
*/
export declare const propertyGetter: <Object_1 extends object>(object: Object_1) => PropertyGetter<Object_1>;
export * from './add-property';
export * from './set-property';
export * from './object-extends';
export * from './deep-merge';
export * from './get-property';
export * from './property-path';
export * from './call-method';
export * from './pick';
export * from './omit';
import { ObjectExtends } from './utils/types';
export { ObjectExtends };
/**
* Create an object with `proto` as prototype
* and `properties` as own properties
* @param proto Prototype to extends upon
* @param properties Properties to add
*/
export declare function objectExtends<Proto extends object | null, Properties extends object>(proto: Proto, properties: Properties): ObjectExtends<Proto, Properties>;
export default objectExtends;
/**
* Creates a shallow clone of an object without certain properties
* @param object Object to omit properties
* @param keys Property keys to not include
* @returns A shallow clone of `object` but without `keys`
*/
export declare function omit<Object, Key extends keyof Object>(object: Object, keys: Iterable<Key>): Omit<Object, Key> & Partial<Pick<Object, Key>>;
/**
* Creates a shallow clone of an object without one property
* @param object Object to omit property
* @param key Property key to not include
* @returns A shallow clone of `object` but without `key`
*/
export declare function omitOne<Object, Key extends keyof Object>(object: Object, key: Key): Omit<Object, Key>;
/**
* Pick properties from an object into a new object
* @param object Object to pick properties from
* @param keys Property keys
* @returns An object with only picked properties
*/
export declare function pick<Object, Key extends keyof Object>(object: Object, keys: Iterable<Key>): Partial<Pick<Object, Key>>;
/**
* Pick a single property from an object into a new object
* @param object Object to pick property from
* @param key Property key
* @returns An object with the picked property
*/
export declare const pickOne: <Object_1, Key extends keyof Object_1>(object: Object_1, key: Key) => Pick<Object_1, Key>;
declare type Key = string | symbol | number;
export declare function getPropertyPath(object: any, path: readonly Key[]): any;
export declare function setPropertyPath(object: any, path: readonly Key[], value: any): any;
export declare function deletePropertyPath(object: any, path: readonly Key[]): any;
export {};
import { AddProperty as SetProperty } from './utils/types';
export { SetProperty };
/**
* Shallow clone an object and alter one property
* @hint If you don't need remaining properties to be own properties, consider `addProperty` instead
* @param object Object to get remaining properties from
* @param key Property key
* @param value Property value
*/
export declare const setProperty: <Object_1 extends object, Key extends string | number | symbol, Value>(object: Object_1, key: Key, value: Value) => { [SoleKey in Key]: Pick<Pick<Object_1 extends null ? {} : Object_1, import("utility-types").SetDifference<keyof (Object_1 extends null ? {} : Object_1), keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; })>> & Pick<{ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }, Extract<keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }), keyof (Object_1 extends null ? {} : Object_1)> & Extract<keyof (Object_1 extends null ? {} : Object_1), keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; })>> & Pick<{ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }, import("utility-types").SetDifference<keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }), keyof (Object_1 extends null ? {} : Object_1)>>, import("utility-types").SetDifference<keyof (Object_1 extends null ? {} : Object_1), keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; })> | (Extract<keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }), keyof (Object_1 extends null ? {} : Object_1)> & Extract<keyof (Object_1 extends null ? {} : Object_1), keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; })>) | import("utility-types").SetDifference<keyof ({ [_ in SoleKey]: Value; } extends null ? {} : { [_ in SoleKey]: Value; }), keyof (Object_1 extends null ? {} : Object_1)>>; }[Key];
export default setProperty;
export declare const bindContext: <Fn extends Function>(fn: Fn, ctx: ThisParameterType<Fn>) => OmitThisParameter<Fn>;
export declare function mutObj<Object, Key extends string | number | symbol, Value>(object: Object, key: Key, value: Value): asserts object is Object & Record<Key, Value>;
import { Assign } from 'utility-types';
/**
* Turn `null` into `{}`
*/
declare type NullObject<X> = X extends null ? {} : X;
/**
* Create a dict of one key-value pair
*/
export declare type SingleDict<Key extends string | number | symbol, Value> = {
readonly [_ in Key]: Value;
};
/**
* Turn a type into a set of properties
*/
export declare type Properties<Type> = {
[key in keyof Type]: Type[key];
};
/**
* Merge two types
*/
export declare type SimpleDeepMerge<A, B> = Properties<A> & Properties<B>;
/**
* Make all properties in a dict optional
*/
export declare type DeepPartialNonArray<Object> = Object extends readonly any[] ? Object | undefined : Object extends object ? {
[Key in keyof Object]?: DeepPartialNonArray<Object[Key]>;
} : Object | undefined;
/**
* Return type of `objectExtends`
*/
export declare type ObjectExtends<Proto extends object | null, Properties extends object | null> = Assign<NullObject<Proto>, NullObject<Properties>>;
/**
* Return type of `addProperty`
*/
export declare type AddProperty<Proto extends object | null, Key extends string | number | symbol, Value> = {
[SoleKey in Key]: ObjectExtends<Proto, {
[_ in SoleKey]: Value;
}>;
}[Key];
/**
* Extract parameter types from `Fn` if it is a function
*/
export declare type MaybeParam<Fn> = Fn extends (...args: any[]) => any ? Parameters<Fn> : never;
/**
* Extract return type from `Fn` if it is a function
*/
export declare type MaybeReturn<Fn> = Fn extends (...args: any[]) => any ? ReturnType<Fn> : never;
export {};