UNPKG

mjstl

Version:

JS USEABLE DATEUTIL HELPER LIB

123 lines (122 loc) 4.32 kB
import { MESearchBuilder } from "./utils"; export interface INumeralOptions { fraction?: number; thousandSeperator?: boolean; } export interface NumeralValidity { gte?: number; gt?: number; lte?: number; lt?: number; } export interface NumeralUtil { currency: (value: number, code?: string | null, thousandSeperator?: boolean | null, direction?: "ltr" | "rtl") => string; format: (value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number) => string; parseRaw: (value: string, code?: string | null, fraction?: number) => string; toNumber: (value: string | number, fraction?: number) => number; toFloat: (value: string | number, fraction?: number) => number; toInt: (value: string | number) => number; } export interface ICurrencySlotProps { direction?: "ltr" | "ltr"; value: number; code?: string; thousandSeperator?: boolean | null; fraction?: number; } export interface NumeralSlotProps { value: number; code?: string; thousandSeperator?: boolean | null; fraction?: number; } export declare enum PhoneType { ANY = "ANY", MOBILE = "MOBILE", LAND = "LAND" } export interface PhoneRaw { aa2: string; code: number; nn: string; example?: string; } export interface PhoneUtil { parseRaw: (phone: string, phoneType?: PhoneType) => PhoneRaw | null; parseRawByCountryCode: (code: string, phone: string, phoneType?: PhoneType) => PhoneRaw | null; pretty: (phone: string, phoneType?: PhoneType) => string; } export type MGLatLng = { latitude: number; longitude: number; }; export interface IGeoBounds { valid: () => boolean; getCenter?: () => MGLatLng; getSouthWest?: () => MGLatLng; getSouthEast?: () => MGLatLng; getNorthWest?: () => MGLatLng; getNorthEast?: () => MGLatLng; getWest?: () => number; getSouth?: () => number; getEast?: () => number; getNorth?: () => number; } export interface IGeoUtil { encode: (path: MGLatLng[]) => string; decode: (encoded: string) => MGLatLng[]; mcoord: (lat: number, lng: number) => MGLatLng; Distance: (lat1: number, lon1: number, lat2: number, lon2: number, abs?: boolean) => { V1: () => number; V2: () => number; V3: () => number; }; findCenter: (points: MGLatLng[]) => MGLatLng; calcBounds: (points: MGLatLng[]) => IGeoBounds; } export interface IIdUtil { uid: () => number; uid2: () => string; uuid: () => string; ulid: () => string; } export interface IDeviceUtil { isMobileOrTablet: () => boolean; } export interface ISafeSaniItem { safe: () => string; check: () => boolean; log: () => void; } export interface ISafeSani { url: (url: string) => ISafeSaniItem; input: (value: string | any) => ISafeSaniItem; } export type SfAccFn<T, R = any> = (item: T, index: number, arr?: Array<T>) => R; export type SfAccType<T, R = any> = string | string[] | SfAccFn<T, R> | null; export type SfCompareFnn<T> = (a: T, b: T) => number; export type SfSortDirectionType = "asc" | "desc"; export type SfSortCompareType = "String" | "Number" | "Date" | "Boolean"; export type SfCallbackFn<T, R> = (item: T, index: number, arr?: Array<T>) => R; export type SfReduceCallbackFn<T, R> = (pre: R, item: T, index: number, arr?: Array<T>) => R; export interface MArray<T> { sfSort<R>(type: SfSortCompareType, acc: SfAccType<T, R> | null, direction?: SfSortDirectionType): this; sfSortUF<R>(type: SfSortCompareType, acc: SfAccType<T, R> | null, direction?: SfSortDirectionType): this; sfMap<R>(acc: SfCallbackFn<T, R>): Array<R>; sfEach(acc: SfCallbackFn<T, void>): this; sfFilter(acc: SfCallbackFn<T, any>): Array<T>; sfFind(acc: SfCallbackFn<T, any>): T | null; sfFindIndex(acc: SfCallbackFn<T, boolean>): number; sfExist(acc: SfCallbackFn<T, boolean>): boolean; sfReduce<R>(acc: SfReduceCallbackFn<T, R>, value: R): R; } export type MESearchBuilderLike<T> = MESearchBuilder<T>; export interface IMSearch { search: <T>(arr: T[]) => MESearchBuilderLike<T>; } export interface IDash { lget<E, T>(obj: E, path: string | string[], defaultValue?: T extends unknown ? any : T): T extends unknown ? any : T; } export interface IAdx { stripHtmlTags(html: string): string; }