UNPKG

@churchapps/apihelper

Version:

Library of helper functions not specific to any one ChurchApps project or framework.

35 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SlugHelper = void 0; class SlugHelper { static slugifyString(string, removeCharacters) { const charactersToRemove = removeCharacters ? removeCharacters : ["for", "and", "nor", "but", "or", "yet", "so", "the", "a", "an"]; const characStr = charactersToRemove.join("|"); const regex = new RegExp('\\b(' + characStr + ')\\b', 'gi'); const cleaned = string.replace(regex, ''); const initialSlug = cleaned.replace(/ /g, "-").toLowerCase(); const verfiedSlug = this.numerifySlug(initialSlug); return verfiedSlug; } //remove multiple numbers in sequence static numerifySlug(slug) { let initialString = slug; const regex = /\d+(?:-\d+)+|\d+/g; const matchedArray = initialString.match(regex); if (matchedArray) { matchedArray.forEach((data) => { const length = data.length; let splitResult = data; if (length > 1) { const array = data.split(""); splitResult = array[0]; } const replacedString = initialString.replace(data, splitResult); initialString = replacedString; }); } return initialString; } } exports.SlugHelper = SlugHelper; //# sourceMappingURL=SlugHelper.js.map