useUtils
Introduction
- useUtils provides awesome functions that you may need.
const {
isBrowser,
emptyFunction,
ArrayToJSON,
...
} = useUtils();
Getting Started
- You need to import useUtils.
From Collection
import { useUtils } from "@reactivers/hooks";
From Package
import { useUtils } from "@reactivers/use-utils";
Interfaces
declare const isBrowser: () => boolean;
declare const emptyFunction: () => void;
declare const setIfNotEqual: (variable: any, value: any) => void;
declare const tryJSONparse: (obj: any) => any;
declare const tryJSONStringify: (obj: any) => any;
declare const transform: (value: number, actualRange: [number, number], targetRange: [number, number]) => number;
declare const memoComparer: <T>(prevProps: T, nextProps: T, props: Array<keyof T>) => boolean;
declare const isPointInRect: (point: {
x: number;
y: number;
}, rect: {
top: number;
right: number;
bottom: number;
left: number;
}, includeBorders?: boolean) => boolean;
declare type Grow<T, A extends Array<T>> = ((x: T, ...xs: A) => void) extends (...a: infer X) => void ? X : never;
declare type GrowToSize<T, A extends Array<T>, N extends number> = {
0: A;
1: GrowToSize<T, Grow<T, A>, N>;
}[A['length'] extends N ? 0 : 1];
declare type FixedArray<T, N extends number> = GrowToSize<T, [], N>;
declare const isInRange: (range: FixedArray<number, 2>, num: number, includeFrom?: boolean, includeTo?: boolean) => boolean;
declare const deepCompare: (obj1: object | JSON | ArrayLike<JSON>, obj2: object | JSON | ArrayLike<JSON>) => boolean;
declare const getIsWebkit: () => boolean;
declare const isEqualJSON: (json1?: {}, json2?: {}) => boolean;
declare const deepCopy: (json?: {}) => any;
declare const combineReducers: (reducers: any) => (state: {}, action: any) => {};
declare const transformObj: (obj: any) => {};
declare const JSONToArray: (json: {}, key: any, valueKey: any) => any[];
declare const EnumToArray: (enums: any, valueKey: any, descriptionKey: any) => {
[x: number]: any;
}[];
declare const download: (newBlob: any, type: any) => void;
declare const downloadQRCodeById: (id: any) => void;
declare const downloadQRCodeBySVGElement: (QRCodeSVGElement: any, type?: string, size?: {
width?: number;
height?: number;
}) => void;
declare const downloadByDataURL: (dataURL: any, type: any) => void;
declare const bytesToSize: (bytes: any) => string;
declare const sum: (array?: any[]) => any;
declare const ArrayToJSON: (array: any, keyName: any, valueName: any) => {};
declare const isJSONEmpty: (json?: {}) => boolean;
declare const isArrayEmpty: (array?: any[]) => boolean;
declare const guid: () => string;
interface Province {
name: string;
}
interface District {
name: string;
}
interface Address {
province: Province;
district: District;
}
declare const getAddressText: (address: Address) => string;
declare const getUriFromImageObject: (host: string, image?: {
base64Data: any;
fileType: any;
id: any;
}) => string;
declare const updateObjectByName: (oldObject: {}, name: any, value: any) => {};
declare const getFirstLetters: (string?: string) => string;
declare const hashCode: (str: any) => number;
declare const generatedColorFromString: (_i: any) => string;
declare const destructArray: (array?: any[]) => any[];
declare const takeUndefinedAsTrue: (parameter: any) => any;
declare type ResponseContentType = "JSON" | "BLOB" | "FORM-DATA" | "TEXT" | "ARRAY-BUFFER" | "RAW";
interface IFetch extends RequestInit {
url: string;
body?: any;
method?: string;
onSuccess: (response: any) => void;
onError: (error: any) => void;
stringify?: boolean;
responseContentType?: ResponseContentType;
}
export declare const applicationJSONHeader: {
"Content-Type": string;
};
declare const iFetch: (payload: IFetch) => Promise<Response>;
declare const changeColor: (color: any, amt: any) => string;
declare const takeIf: (condition: any, value: any, defaultValue?: any) => any;
declare const spliceString: (string: any, startCount: any, deleteCount: any) => any;
declare const isNullOrUndefined: (item: any) => boolean;
declare const coalasce: (first: any, second: any) => any;
declare const numberShouldStartWithZero: (number: any) => any;
declare const getTodayYear: () => number;
declare const getTodayMonth: () => number;
declare const monthsNumberArray: number[];
declare const isArrayContains: (array: any, value: any, key: any) => boolean;
declare const JSONArrayIndexOf: (array: any, value: any, key: any) => any;
declare const cos: (degree: number) => number;
declare const insertOrUpdateElementInArrayByKey: (array: any, idKey: any, id: any, item: any) => any;
declare const deleteElementFromArrayByKey: (array: any, idKey: any, id: any) => any;
declare const findLastIndex: (array: Array<any>, predicate: (c: any) => boolean) => number;
Example