idea-toolbox
Version:
IDEA's utility functions
79 lines (78 loc) • 3.44 kB
TypeScript
import { markdown } from './markdown';
import { ISODateString, ISOString } from './epoch';
/**
* Get the ISO string version of a date in the format `YYYY-MM-DDTHH:mm:ss.sssZ`.
* The timezone is always UTC, as denoted by the suffix `Z`.
*/
export declare const toISOString: (input: Date | number | ISOString | ISODateString) => ISOString | null;
/**
* Get the current date and time in the format `YYYY-MM-DDTHH:mm:ss.sssZ`.
* The timezone is always UTC, as denoted by the suffix `Z`.
*/
export declare const nowISOString: () => ISOString;
/**
* Get the ISO string version of a date in the format `YYYY-MM-DD`.
* It doesn't say anything about the timezone.
*/
export declare const toISODateString: (input: Date | number | ISOString | ISODateString) => ISODateString | null;
/**
* @deprecated use toISODateString instead
*/
export declare const toISODate: (input: Date | number | ISOString | ISODateString) => ISODateString | null;
/**
* Get the current date in the format `YYYY-MM-DD`.
* It doesn't say anything about the timezone.
*/
export declare const nowISODateString: () => ISODateString;
/**
* Clean a string to use it within filenames and so.
* @param str the string to clean
* @param separator optional, separator char
* @returns cleaned string
*/
export declare const cleanStr: (str: string, separator?: string) => string;
/**
* Join two arrays by a common column, selecting which data to extract.
* @param mainTable the main array
* @param lookupTable the lookup array
* @param mainKey mainTable's column for the join condition
* @param lookupKey lookupTable's column for the join condition
* @param selectFunction defines which
* attributes we want to retain in the joined array; null values generated by the
* function are ignored
* @returns the joined array
*/
export declare const joinArraysOnKeys: (mainTable: any[], lookupTable: any[], mainKey: string, lookupKey: string, selectFunction: (attrMainTable: string, attrLookupTable: string) => any[]) => any[];
/**
* Check if a field (/variable) is empty or invalid, based on its type.
* If the type isn't passed as a parameter, it will be auto-detected.
* @param field the field to check
* @param fieldType set to force a type check
* @returns return if the field is empty/invalid or not
*/
export declare const isEmpty: (field: any, fieldType?: isEmptyFieldTypes) => boolean;
export type isEmptyFieldTypes = 'string' | 'number' | 'positiveNumber' | 'boolean' | 'object' | 'date' | 'email' | 'phone' | 'url' | 'domain';
/**
* Convert a markdown string to HTML.
*/
export declare const mdToHtml: (mdString: markdown | string) => string;
/**
* @deprecated Get an array to iterate containing the keys of a string enum.
*/
export declare const loopStringEnumKeys: (theEnum: any) => string[];
/**
* @deprecated Get an array to iterate containing the values of a string enum.
*/
export declare const loopStringEnumValues: (theEnum: any) => string[];
/**
* @deprecated Get an array to iterate containing the keys of a numeric enum.
*/
export declare const getStringEnumKeyByValue: (theEnum: any, value: string) => string;
/**
* @deprecated Get an array to iterate containing the keys of a numeric enum.
*/
export declare const loopNumericEnumKeys: (theEnum: any) => number[];
/**
* @deprecated Get an array to iterate containing the values of a numeric enum.
*/
export declare const loopNumericEnumValues: (theEnum: any) => string[];