UNPKG

@technobuddha/library

Version:
17 lines (16 loc) 592 B
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;