@technobuddha/library
Version:
A large library of useful functions
25 lines (24 loc) • 947 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.root = void 0;
var isNil_1 = __importDefault(require("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
*/
function root(input, _a) {
var _b = _a === void 0 ? {} : _a, prefix = _b.prefix, suffix = _b.suffix;
if (!isNil_1.default(prefix) && input.startsWith(prefix))
input = input.slice(prefix.length);
if (!isNil_1.default(suffix) && input.endsWith(suffix))
input = input.slice(0, Math.max(0, input.length - suffix.length));
return input;
}
exports.root = root;
exports.default = root;