🚀 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.0
to
0.0.1
+30
call-method.d.ts
import { MaybeParam, MaybeReturn } from './utils/types';
/**
* 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]: 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]: 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]: 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]: Object_1[K] extends Function ? K : never; }[keyof Object_1], Method extends Object_1[MethodName]>(name: MethodName) => OmitThisParameter<Method>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const bind_1 = require("./utils/bind");
/**
* 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
*/
exports.applyMethod = (object, name, args) => object[name](...args);
/**
* 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
*/
exports.callMethod = (object, name, ...args) => object[name](...args);
/**
* 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
*/
exports.getMethod = (object, name) => bind_1.bindContext(object[name], object);
/**
* Create a function that get methods of an object
* @param object Object to get methods from
* @returns A function that get object method
*/
exports.methodGetter = (object) => (name) => exports.getMethod(object, name);
//# sourceMappingURL=call-method.js.map
import { bindContext } from './utils/bind';
/**
* 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 const applyMethod = (object, name, args) => object[name](...args);
/**
* 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 const callMethod = (object, name, ...args) => object[name](...args);
/**
* 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 const getMethod = (object, name) => bindContext(object[name], object);
/**
* Create a function that get methods of an object
* @param object Object to get methods from
* @returns A function that get object method
*/
export const methodGetter = (object) => (name) => getMethod(object, name);
//# sourceMappingURL=call-method.js.map
/**
* 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>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Access a property from an object
* @param object Object to get property from
* @param key Property key
* @returns Property value
*/
exports.getProperty = (object, 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
*/
exports.propertyGetter = (object) => (key) => object[key];
//# sourceMappingURL=get-property.js.map
/**
* Access a property from an object
* @param object Object to get property from
* @param key Property key
* @returns Property value
*/
export const getProperty = (object, 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 const propertyGetter = (object) => (key) => object[key];
//# sourceMappingURL=get-property.js.map
export declare const bindContext: <Fn extends Function>(fn: Fn, ctx: ThisParameterType<Fn>) => OmitThisParameter<Fn>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const protoBind = Function.prototype.bind;
exports.bindContext = (fn, ctx) => protoBind.call(fn, ctx);
//# sourceMappingURL=bind.js.map
const protoBind = Function.prototype.bind;
export const bindContext = (fn, ctx) => protoBind.call(fn, ctx);
//# sourceMappingURL=bind.js.map
+2
-0
export * from './add-property';
export * from './object-extends';
export * from './get-property';
export * from './call-method';

@@ -6,2 +6,4 @@ "use strict";

tslib_1.__exportStar(require("./object-extends"), exports);
tslib_1.__exportStar(require("./get-property"), exports);
tslib_1.__exportStar(require("./call-method"), exports);
//# sourceMappingURL=index.js.map
export * from './add-property';
export * from './object-extends';
export * from './get-property';
export * from './call-method';
//# sourceMappingURL=index.js.map
+1
-1
{
"name": "@tsfun/object",
"version": "0.0.0",
"version": "0.0.1",
"description": "Utilities related to objects",

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

@@ -15,5 +15,13 @@ import { Assign } from 'utility-types';

[SoleKey in Key]: ObjectExtends<Proto, {
[key in SoleKey]: Value;
[_ 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 {};