yogeshs-utilities
Version:
115 lines • 4.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValid = exports.replaceString = exports.replaceHtmlKeyCode = exports.replaceWithHtmlKeyCode = exports.stripHtmlTags = exports.getLineComment = exports.containsWholeWord = exports.safeReplace = void 0;
String.prototype.camelCase = function (line) {
return line.toLowerCase().replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
}).replace(/\s+/g, '');
};
function safeReplace(input, matchWholeWord, find, replacement = "") {
const textToFind = matchWholeWord ? `\\b${find}\\b` : find;
const regex = new RegExp(textToFind, 'g');
return input.replace(regex, replacement);
}
exports.safeReplace = safeReplace;
;
function containsWholeWord(input, find, matchWholeWord = true) {
let textToFind = matchWholeWord ? `\\b${find}\\b` : find;
const regex = new RegExp(textToFind, 'g');
return regex.test(input);
}
exports.containsWholeWord = containsWholeWord;
;
function getLineComment(input) {
const regEx = new RegExp('(?:[\\;\\*][\\;\\s\\*]+)(.*)', 'i');
if (!regEx.test(input))
return "";
const match = regEx.exec(input);
return match && match.length >= 2 ? match[1] : "";
}
exports.getLineComment = getLineComment;
;
function stripHtmlTags(input, ...tagNames) {
if (!input)
return "";
let original = input;
for (const tagName of tagNames) {
original = original.replace(new RegExp(`</?${tagName}( [^>]*|/)?>`, 'gi'), '');
original = original.replace(/ /g, ' ');
}
return original;
}
exports.stripHtmlTags = stripHtmlTags;
;
function replaceWithHtmlKeyCode(input) {
if (!input)
return "";
return input.replace(/&|>|<|'|"/g, (match) => {
switch (match) {
case '&': return '&';
case '>': return '>';
case '<': return '<';
case "'": return ''';
case '"': return '"';
default: return match;
}
});
}
exports.replaceWithHtmlKeyCode = replaceWithHtmlKeyCode;
;
function replaceHtmlKeyCode(input) {
if (!input)
return "";
return input.replace(/>|<|'|"|&/g, (match) => {
switch (match) {
case '>': return '>';
case '<': return '<';
case ''': return "'";
case '"': return '"';
case '&': return '&';
default: return match;
}
});
}
exports.replaceHtmlKeyCode = replaceHtmlKeyCode;
;
function replaceString(input) {
if (!input)
return input;
input = input.replace(" >= ", " greater than or equal to ");
input = input.replace(" <= ", " less than or equal to ");
input = input.replace(" => ", " equal to or greater than ");
input = input.replace(" =< ", " equal to or less than ");
input = input.replace(">= ", " greater than or equal to ");
input = input.replace("<= ", " less than or equal to ");
input = input.replace("=> ", " equal to or greater than ");
input = input.replace("=< ", " equal to or less than ");
input = input.replace(" != ", " not equal to ");
input = input.replace(" Ne ", " not equal to ");
input = input.replace(" <> ", " not equal to ");
input = input.replace(" Gt ", " greater than ");
input = input.replace(" GE ", " greater or equal to ");
input = input.replace(" LE ", " less than or equal to ");
input = input.replace(" Lt ", " less than ");
input = input.replace(" > ", " greater than ");
input = input.replace(" < ", " less than ");
input = input.replace(" = ", " equal to ");
input = input.replace(" Not= ", " not equal to ");
input = input.replace(" NE ", " not equal to ");
input = input.replace(")NE ", ") not equal to ");
input = input.replace(" == ", " is equal to ");
input = input.replace(" || ", " OR ");
input = input.replace(" && ", " AND ");
return input;
}
exports.replaceString = replaceString;
;
function isValid(input) {
const valid = /(?:[\;\*][\;\s\*]+)/.test(input);
if (valid && !input.includes(';'))
return false;
return valid;
}
exports.isValid = isValid;
;
//# sourceMappingURL=string-extensions.js.map