UNPKG

@kwiz/common

Version:

KWIZ common utilities and helpers for M365 platform

54 lines (53 loc) 3.51 kB
import { primitiveTypes } from "./typecheckers"; /** global window, safe for testing and environments without a browser */ export declare var $w: Window; /** wrapper for hasOwnProperty that satisfies https://eslint.org/docs/latest/rules/no-prototype-builtins */ export declare function hasOwnProperty(obj: any, prop: string): any; /** empty async function */ export declare var noop: () => Promise<void>; /** empty sync function */ export declare var noops: () => void; /** get or create kwizcom object from top window or current window, set allowFromTop if you want to try to get from window.top */ export declare function getKWizComGlobal(allowFromTop?: boolean): IKWizComGlobals; /** get or create kwizcom.globals dictionary from top window or current window. Add or return key:name initialize as defaults or blank object if does not already exist */ export declare function getGlobal<T>(name: string, defaults?: T, notFromTop?: boolean): T; /** * Automatically bind all functions of instance to instance * Note: if you use knockout, you should skip ko.isObservable * @param instance */ export declare function autoBind(instance: any, skip?: (name: string, f: Function) => boolean): void; /** Implements Object.assign which does not exist in IE * Copies properties over from overrides into original object * Merge default and override settings: var merged = assign({},defaults,props) * Create deep copy of object by var copy = assign({},obj) */ export declare function assign<T>(original: Partial<T>, ...overrides: Partial<T>[]): T; export declare function primitivesEqual(o1: primitiveTypes, o2: primitiveTypes): boolean; export declare function objectsEqual<T extends object>(o1: T, o2: T, ignoreKeys?: string[]): boolean; export declare function jsonClone<T>(obj: T): T; /** if an object in this path doesnt exist under parent - creates it.*/ export declare function ensureObjectPath(objectPath: string, defaultValue?: any, parent?: any): void; /** If o has propb and not propa - will copy propb into propa and remove propb */ export declare function keepOne(o: any, propa: string, propb: string): void; /**return all members and functions of an object, including inherited ones from its base class, excluding the constructor * send prototypeLevels to limit the number of prototype climbs to get functions from. 0 means unlimited. */ export declare function getAllMemberNames(instance: any, prototypeLevels: number): string[]; /**return all functions of an object, including inherited ones from its base class, excluding the constructor * send prototypeLevels to limit the number of prototype climbs to get functions from. 0 means unlimited. */ export declare function getAllFunctionNames(instance: any, prototypeLevels: number): string[]; /** generic implementation of Object.values */ export declare function objectValues<T = any>(obj: any): T[]; export declare class DefaultProp<T> { private _value; private _defaultValue; private isValid; set value(newValue: T); get value(): T; constructor(defaultValue: T | (() => T), initialValue?: T, isValid?: (value: T) => boolean); } /** creates a safe property, if the value is null/undefined or empty string - it will return the default value. */ export declare function GetDefaultProp<T>(defaultValue: T | (() => T), initialValue?: T, isValid?: (value: T) => boolean): DefaultProp<T>; /** Get string error message from an error object */ export declare function GetError(error: any, defaultError?: string): string;