@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
97 lines (96 loc) • 3.38 kB
TypeScript
/**
* Generic string type but with the given suffix appended to it.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export type WithSuffix<Suffix extends string> = `${string}${Suffix}`;
/**
* Suffix for {@link addPercent} and {@link removePercent}.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare const percentSuffix = "%";
/**
* Suffix for {@link addPx} and {@link removePx}.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare const pxSuffix = "px";
/**
* Generic string type but with the `'px'` suffix appended to it.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export type WithPx = WithSuffix<typeof pxSuffix>;
/**
* Generic string type but with the `'%'` suffix appended to it.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export type WithPercent = WithSuffix<typeof percentSuffix>;
/**
* Adds the `'px'` suffix to a string if it does not already exist.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function addPx(input: number | string): WithPx;
/**
* Removes the `'px'` suffix from a string if it exists.
*
* @category String
* @category Package : @augment-vir/common
* @throws `TypeError` if the input can't be converted into a number.
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function removePx(input: string): number;
/**
* Adds the `'%'` suffix to a string if it does not already exist.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function addPercent(input: number | string): WithPercent;
/**
* Removes the `'%'` suffix from a string if it exists.
*
* @category String
* @category Package : @augment-vir/common
* @throws `TypeError` if the input can't be converted into a number.
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function removePercent(input: string): number;
/**
* Adds a suffix to a string if it does not already exist.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function addSuffix<const Suffix extends string>({ value, suffix, }: {
value: unknown;
suffix: Suffix;
}): WithSuffix<Suffix>;
/**
* Removes a suffix from a string if it exists.
*
* @category String
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function removeSuffix<const Suffix extends string>({ value, suffix, }: {
value: string;
suffix: Suffix;
}): string;