object-x
v2.0.5
Published
Utility functions for JavaScript values and objects
Downloads
16
Readme
object-x.js
Utility functions for JavaScript values and objects
API
type SystemObj = Object;
declare namespace X {
type Mapper = (value: any, key: any) => any;
type Predicate = (value: any, key: any) => boolean;
type Accumulator<T> = (accumulatedValue: T, currentValue: T, key: any) => T;
class Object implements SystemObj {
constructor(obj: SystemObj | any[]);
put(key: any, value: any): Object;
remove(key: any): Object;
toObject(): SystemObj;
toArray(): any[]; // makeArray if
count(): number;
select(func?: Mapper): Object;
where(func?: Predicate): Object;
accumulate<T>(initial: T, accum?: Accumulator<T>): T;
/**
* Performs the specified action for each element in an array.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
forEach(func: (value: any, index: number) => void): void;
distinct(): Object;
union(obj: SystemObj): Object;
/**
* Determines whether all the members of an array satisfy the specified test.
* @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
all(func?: Predicate): boolean;
/**
* Determines whether the specified callback function returns true for any element of an array.
* @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
any(func?: Predicate): boolean;
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
* @param fromIndex The position in this array at which to begin searching for searchElement.
*/
contains(obj: any): boolean;
toCase(_case: "camel" | "snake" | "slug" | "pascal", depth?: number): Object;
stripKeys(keys?: string | any[]): Object;
stringify(maxDepth?: number, format?: boolean): string;
// JSON stringify and base64 encode
encode(): string;
static encode(val: any): string
// base64 decode and JSON parse
static decode(val: string): Object;
/** Returns a string representation of an object. */
toString(): string;
/** Returns a date converted to a string using the current locale. */
toLocaleString(): string;
/** Returns the primitive value of the specified object. */
valueOf(): Object;
/**
* Determines whether an object has a property with the specified name.
* @param v A property name.
*/
hasOwnProperty(v: string): boolean;
/**
* Determines whether an object exists in another object's prototype chain.
* @param v Another object whose prototype chain is to be checked.
*/
isPrototypeOf(v: Object): boolean;
/**
* Determines whether a specified property is enumerable.
* @param v A property name.
*/
propertyIsEnumerable(v: string): boolean;
}
}