@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
70 lines (69 loc) • 3.15 kB
TypeScript
/** Converts string to kebab-case notation */
export declare const toKebabCase: (str: string) => string;
/** Converts string to camelCase notation */
export declare const toCamelCase: (str: string) => string;
/** Makes the first non-indent (space, tab, newline) letter in the string capitalized */
export declare const capitalize: (str: string) => string;
/** Unwraps string from parenthesis */
export declare const unwrapParenthesis: (str: string) => string;
/**
* Serialize to boolean string (`'true'|'false'`)
* Preserve null, undefined and empty string
*/
export declare const toBooleanAttribute: (val: any) => string | null;
/** Parses `null` and `undefined` as an empty string */
export declare const parseString: (val: string | null) => string;
/** Parses string representation of the boolean value */
export declare const parseBoolean: (val: string | null) => boolean;
/**
* Parses number with the ability to pass an alternative fallback for NaN.
* Note: falsy values except 0 are treated as NaN
*/
export declare function parseNumber(str: string | number): number | undefined;
/**
* Parses number with the ability to pass an alternative fallback for NaN.
* Note: falsy values except 0 are treated as NaN
*/
export declare function parseNumber(str: string | number, nanValue: number): number;
/**
* Common function that returns coefficient aspect ratio
* Supported formats: w:h, w/h, coefficient
* @example
* `16:9`, `16/9`, `1.77`
* @param str - string to parse
* @returns aspect ratio coefficient
*/
export declare function parseAspectRatio(str: string): number;
/** Evaluates passed string or returns `defaultValue` */
export declare function evaluate(str: string, defaultValue?: any): any;
/** Default RegExp to match replacements in the string for the {@link format} function */
export declare const DEF_FORMAT_MATCHER: RegExp;
/** Replaces `{key}` patterns in the string from the source object */
export declare function format(str: string, source: Record<string, any>, matcher?: RegExp): string;
/**
* Parses time string ([CSS style](https://developer.mozilla.org/en-US/docs/Web/CSS/time))
* Less strict than CSS spec, allows empty string, numbers without units, ending dot.
* @example
* `.3s`, `4.5s`, `1000ms`
* @returns number - time in milliseconds
*/
export declare function parseTime(timeStr: string): number;
/**
* Restrictive time parser according to [CSS style](https://developer.mozilla.org/en-US/docs/Web/CSS/time) spec.
* @see {@link parseTime}
*/
export declare const parseCSSTime: (timeStr: string) => number;
/**
* Parses string of times ([CSS style](https://developer.mozilla.org/en-US/docs/Web/CSS/time))
* @example
* `.3s`, `4.5s,1000ms`, `1s, 5s`
* @returns number[] - array of times in milliseconds
*/
export declare function parseCSSTimeSet(timeStr: string): number[];
/**
* Common parser for lazy attribute. Case insensitive. Note:
* - empty string or unknown values are treated as `auto`.
* - `null` (or non string objects) is treated as `none`.
* - `manual` or `none` are treated as it is
*/
export declare function parseLazyAttr(value: string | null): 'auto' | 'manual' | 'none';