typedash
Version:
modern, type-safe collection of utility functions
20 lines (19 loc) • 575 B
JavaScript
//#region src/functions/ensurePrefix/ensurePrefix.ts
/**
* Ensures that the string starts with the given prefix.
* @param string The string to ensure the prefix of.
* @param prefix The prefix to ensure.
* @returns The string with the given prefix.
* @example
* ```ts
* ensurePrefix('foo', 'bar'); // 'barfoo'
* ensurePrefix('foobar', 'foo'); // 'foobar'
* ```
*/
function ensurePrefix(string, prefix) {
if (string.startsWith(prefix)) return string;
return `${prefix}${string}`;
}
//#endregion
export { ensurePrefix as t };
//# sourceMappingURL=ensurePrefix-DpzCB3QE.js.map