typedash
Version:
modern, type-safe collection of utility functions
26 lines (24 loc) • 670 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
Object.defineProperty(exports, 'ensurePrefix', {
enumerable: true,
get: function () {
return ensurePrefix;
}
});
//# sourceMappingURL=ensurePrefix-CvE5Qf1u.cjs.map