@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
18 lines (17 loc) • 561 B
JavaScript
/**
* Capitalises the characters of a provided string between the given start and end indexes
*/
export function capitalise(value, options) {
const { length } = value;
let { start, end } = { start: 0, end: length, ...options };
if (start < 0) {
start = 0;
}
if (end > length) {
end = length;
}
const stringStart = value.substring(0, start);
const capitalise = value.substring(start, end);
const stringEnd = value.substring(end, length);
return `${stringStart}${capitalise.toUpperCase()}${stringEnd}`;
}