@technobuddha/library
Version:
A large library of useful functions
17 lines (16 loc) • 592 B
JavaScript
import isNil from 'lodash/isNil';
/**
* Extract the root word, removing a prefix and/or suffix
*
* @param input The word, which might have {@code prefix} before it, and {@code suffix} after it.
* @param __namedParameters see {@link Options}
* @returns The root word
*/
export function root(input, { prefix, suffix } = {}) {
if (!isNil(prefix) && input.startsWith(prefix))
input = input.slice(prefix.length);
if (!isNil(suffix) && input.endsWith(suffix))
input = input.slice(0, Math.max(0, input.length - suffix.length));
return input;
}
export default root;