@open-tender/utils
Version:
A library of utils for use with Open Tender applications that utilize our cloud-based Order API.
64 lines (63 loc) • 3.44 kB
TypeScript
import { Announcements, CheckoutFormCustomer, ContentImages, DateString, Images, RequestError, RequestStatus } from '@open-tender/types';
export declare const isString: (str: any) => boolean;
export declare const isObject: (obj: any) => boolean;
export declare const isEmpty: (obj?: object | null) => boolean;
export declare const isNum: (s: string) => boolean;
/**
* @deprecated please use `containsAll` or `containsAny` instead
* @returns true if first argument contains any of the values in the second argument
*/
export declare const contains: (arr: Array<any> | string, values: Array<any>) => boolean;
/**
* @returns true if first argument contains any of the values in the second argument
*/
export declare const containsAny: <T>(arr: T[], values: T[]) => boolean;
/**
* @returns true if first argument contains all of the values of the second argument
*/
export declare const containsAll: <T>(arr: T[], values: T[]) => boolean;
export declare const slugify: (text: string) => string;
export declare const stripTags: (s: string) => string;
export declare const serialize: (obj: Record<string | number, string | number | boolean>) => string;
export declare const capitalize: (s: string) => string;
export declare const cleanPhone: (phone: string) => string;
export declare const makePhone: (phone: string) => string;
export declare const validatePhone: (phone: string) => boolean;
export declare const makeBirthDate: (birthDate: string) => string | null;
export declare const slashesToDashes: (birthDate: string) => DateString | null;
export declare const dashesToSlashes: (birthDate?: string | null) => string | null;
export declare const validateEmail: (email: string) => boolean;
export declare const checkEmpty: (data: Record<string | number, unknown>) => boolean;
export declare const checkGuestData: (data: CheckoutFormCustomer, email: string) => {
guestData: {
first_name: string | undefined;
last_name: string | undefined;
phone: string | undefined;
email: string;
};
guestIncomplete: boolean;
};
export declare const checkNotFound: (errors: Record<string, string>) => boolean | null;
export declare const makeRandomNumberString: () => string;
export declare const getWidth: () => number;
export declare const getHeight: () => number;
export declare const makeImageMap: (images: Images) => {
APP_IMAGE?: string | undefined;
LARGE_IMAGE?: string | undefined;
SMALL_IMAGE?: string | undefined;
};
export declare const makeImageUrl: (images: ContentImages, isMobile: boolean) => string | null | undefined;
export declare const makeSlides: (items: Announcements, isMobile: boolean) => Announcements | null;
export declare const displayPrice: (price: string) => string;
export declare const addCommas: (x: number, d?: number) => string;
export declare const formatQuantity: (n: string) => string;
export declare const formatPercentage: (n: string, d?: number) => string;
export declare const formatDollars: (str: string, space?: string, decimals?: number) => string;
export declare const convertStringToArray: (str: string | null) => string[];
export declare const hasEntities: <T extends unknown[]>(reducer: {
entities: T | null;
loading: RequestStatus;
error: RequestError;
}) => number | false;
export declare const range: (start: number, end?: number, step?: number) => number[];
export declare const sample: <T>(collection: T[]) => T | undefined;