UNPKG

foremark

Version:

A technology for writing semi-plain text documents that extends upon the concept of Markdeep.

65 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Removes the prefix `prefix` from a string `s` with a graceful error handling. */ function removePrefix(s, prefix) { var i = 0; while (i < prefix.length && i < s.length) { if (s.charCodeAt(i) != prefix.charCodeAt(i)) { break; } ++i; } return s.substr(i); } exports.removePrefix = removePrefix; /** * Analyze the change in the indentation level. * * # Examples * * - `analyzeIndent("\t\t", "\t")` returns `Indent`. In this case, `indent` * has a prefix `ref` and an extra character. * - `analyzeIndent("\t", "\t\t")` returns `Outdent`. In this case, `indent` * is a prefix of `ref` and is shorter than `ref`. * - `analyzeIndent("\t\t", "\t\t")` returns `Preserve`. * - `analyzeIndent("\t\t", " ")` returns `Outdent`. In this case, the common * longest prefix of `indent` and `ref` is shorter than `ref`. */ function analyzeIndent(indent, ref) { var i = 0; while (i < indent.length && i < ref.length) { if (ref.charCodeAt(i) != indent.charCodeAt(i)) { break; } ++i; } if (i < ref.length) { return 2 /* Outdent */; } else if (indent.length == ref.length) { return 0 /* Preserve */; } else if (indent.length > ref.length) { return 1 /* Indent */; } else { throw new Error(); } } exports.analyzeIndent = analyzeIndent; function escapeRegExp(x) { return x.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); } exports.escapeRegExp = escapeRegExp; function truncateStringWithEllipsisSign(x, len) { if (x.length > len) { return x.substr(0, len) + '…'; } else { return x; } } exports.truncateStringWithEllipsisSign = truncateStringWithEllipsisSign; //# sourceMappingURL=string.js.map