UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

31 lines (30 loc) 797 B
/** * Adds a prefix 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 function addPrefix({ value, prefix, }) { if (String(value).startsWith(prefix)) { return String(value); } else { return `${prefix}${String(value)}`; } } /** * Removes a prefix 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 function removePrefix({ value, prefix, }) { if (value.startsWith(prefix)) { return value.slice(prefix.length); } else { return value; } }