export function removePattern(text, regexp) {
return text.replace(regexp, "");
}
Awesome ICS v0.1.0
http://bandraszyk.github.io/awesome-ico/
(c) 2015 Bandro
Awesome ICS may be freely distributed under the MIT license.
export function removePattern(text, regexp) {
return text.replace(regexp, "");
}
export function trim(text) {
let trimmedBeginning = removePattern(text, /^\s+/g);
return removePattern(trimmedBeginning, /\s+$/g);
}
export function mapToString(object) {
return object && object.toString() || "";
}
export function mapToJSON(object) {
return object && object.toJSON() || null;
}
Splits the specified text with the use of separator taking into consideration quotation marks
export function splitSafe(text, separator) {
let parts = text.split(separator);
if (parts.length === 1) { return parts; }
for (let currentLineIndex = 0; currentLineIndex < parts.length - 1; currentLineIndex++) {
let line = parts[currentLineIndex];
let matchQuotationMarks = line.match(/"/g);
let shouldBeContinued = !matchQuotationMarks || (matchQuotationMarks.length % 2 === 0);
if (shouldBeContinued) { continue; }
Merge with previous line and remove from array current element
parts[currentLineIndex] = `${line}${separator}${parts[currentLineIndex + 1]}`;
parts.splice(currentLineIndex + 1, 1);
}
return parts;
}
Splits the specified for lines taking into consideration multi line text that start with empty space
export function splitSafeLines(text, format) {
let lines = text.split(format && format.newLine || "\n");
for (let currentLineIndex = 1; currentLineIndex < lines.length;) {
let line = lines[currentLineIndex];
let isContinuation = line[0] === (format && format.multiLineBegin || " ");
if (isContinuation) {
Merge with previous line and remove from array current element
lines[currentLineIndex - 1] = `${lines[currentLineIndex - 1]}${line.slice(1)}`;
lines.splice(currentLineIndex, 1);
continue;
}
currentLineIndex++;
}
return lines.filter(function(line) { return line; });
}
export function isEmptyString(text) {
return text === undefined || text === null || text.trim() === "";
}