@visulima/string
Version:
Functions for manipulating strings.
154 lines (150 loc) • 6.49 kB
JavaScript
;
var __defProp$1 = Object.defineProperty;
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
const r = String.raw;
const seq = r`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`;
const sTags = r`\u{E0061}-\u{E007A}`;
const emojiRegex = /* @__PURE__ */ __name$1(() => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, "gu"), "default");
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const ESCAPES = /* @__PURE__ */ new Set(["\x1B", ""]);
const ANSI_ESCAPE_BELL = "\x07";
const ANSI_CSI = "[";
const ANSI_SGR_TERMINATOR = "m";
const ANSI_ESCAPE_LINK = `]8;;`;
const END_CODE = 39;
const RE_ZERO_WIDTH = /[\u200B\uFEFF\u2060-\u2064]/g;
const RE_ESCAPE_PATTERN = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`);
const ANSI_RESET_CODES = Object.freeze(
/* @__PURE__ */ new Map([
[0, 0],
// Reset all
[1, 22],
// Bold → Not bold
[2, 22],
// Dim → Not bold
[3, 23],
// Italic → Not italic
[4, 24],
// Underline → Not underline
[7, 27],
// Inverse → Not inverse
[8, 28],
// Hidden → Not hidden
[9, 29],
// Strikethrough → Not strikethrough
[30, 39],
// Foreground colors → Default foreground
[31, 39],
[32, 39],
[33, 39],
[34, 39],
[35, 39],
[36, 39],
[37, 39],
[40, 49],
// Background colors → Default background
[41, 49],
[42, 49],
[43, 49],
[44, 49],
[45, 49],
[46, 49],
[47, 49],
[90, 39]
// Bright foreground → Default foreground
])
);
const RE_LEADING_NEWLINE = /^[ \t]*(?:\r\n|\r|\n)/;
const RE_TRAILING_NEWLINE = /(?:\r\n|\r|\n)[ \t]*$/;
const RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = /^(?:[\r\n]|$)/;
const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
const RE_ANSI = /[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g;
const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
const RE_VALID_HYPERLINKS = /\u001B\]8;;[^\u0007]*\u0007[^\u001B]*(?:\u001B\]8;;\u0007|$)/g;
const RE_ANSI_LINK_END = /\u001B\]8;;\u0007/y;
const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
const RE_EMOJI = emojiRegex();
const RE_SEPARATORS = /[-_./\s]+/g;
const RE_FAST_ANSI = /(\u001B\[[0-9;]*[a-z])/i;
const RE_ARABIC = new RegExp("\\p{Script=Arabic}", "u");
const RE_BENGALI = new RegExp("\\p{Script=Bengali}", "u");
const RE_CYRILLIC = new RegExp("\\p{Script=Cyrillic}", "u");
const RE_DEVANAGARI = new RegExp("\\p{Script=Devanagari}", "u");
const RE_ETHIOPIC = new RegExp("\\p{Script=Ethiopic}", "u");
const RE_GREEK = new RegExp("\\p{Script=Greek}", "u");
const RE_GREEK_LATIN_SPLIT = new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+", "gu");
const RE_GUJARATI = new RegExp("\\p{Script=Gujarati}", "u");
const RE_GURMUKHI = new RegExp("\\p{Script=Gurmukhi}", "u");
const RE_HANGUL = new RegExp("\\p{Script=Hangul}", "u");
const RE_HEBREW = new RegExp("\\p{Script=Hebrew}", "u");
const RE_HIRAGANA = new RegExp("\\p{Script=Hiragana}", "u");
const RE_KANJI = new RegExp("\\p{Script=Han}", "u");
const RE_KANNADA = new RegExp("\\p{Script=Kannada}", "u");
const RE_KATAKANA = new RegExp("\\p{Script=Katakana}", "u");
const RE_KHMER = new RegExp("\\p{Script=Khmer}", "u");
const RE_LAO = new RegExp("\\p{Script=Lao}", "u");
const RE_LATIN = new RegExp("\\p{Script=Latin}", "u");
const RE_MALAYALAM = new RegExp("\\p{Script=Malayalam}", "u");
const RE_MYANMAR = new RegExp("\\p{Script=Myanmar}", "u");
const RE_ORIYA = new RegExp("\\p{Script=Oriya}", "u");
const RE_SINHALA = new RegExp("\\p{Script=Sinhala}", "u");
const RE_TAMIL = new RegExp("\\p{Script=Tamil}", "u");
const RE_TELUGU = new RegExp("\\p{Script=Telugu}", "u");
const RE_THAI = new RegExp("\\p{Script=Thai}", "u");
const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
const stripEmoji = /* @__PURE__ */ __name((stringValue) => stringValue.replace(RE_EMOJI, ""), "stripEmoji");
exports.ANSI_CSI = ANSI_CSI;
exports.ANSI_ESCAPE_BELL = ANSI_ESCAPE_BELL;
exports.ANSI_ESCAPE_LINK = ANSI_ESCAPE_LINK;
exports.ANSI_RESET_CODES = ANSI_RESET_CODES;
exports.ANSI_SGR_TERMINATOR = ANSI_SGR_TERMINATOR;
exports.END_CODE = END_CODE;
exports.ESCAPES = ESCAPES;
exports.RE_ANSI = RE_ANSI;
exports.RE_ANSI_LINK_END = RE_ANSI_LINK_END;
exports.RE_ARABIC = RE_ARABIC;
exports.RE_BENGALI = RE_BENGALI;
exports.RE_CONTROL = RE_CONTROL;
exports.RE_CYRILLIC = RE_CYRILLIC;
exports.RE_DETECT_INDENTATION = RE_DETECT_INDENTATION;
exports.RE_DEVANAGARI = RE_DEVANAGARI;
exports.RE_EMOJI = RE_EMOJI;
exports.RE_ESCAPE_PATTERN = RE_ESCAPE_PATTERN;
exports.RE_ETHIOPIC = RE_ETHIOPIC;
exports.RE_FAST_ANSI = RE_FAST_ANSI;
exports.RE_GREEK = RE_GREEK;
exports.RE_GREEK_LATIN_SPLIT = RE_GREEK_LATIN_SPLIT;
exports.RE_GUJARATI = RE_GUJARATI;
exports.RE_GURMUKHI = RE_GURMUKHI;
exports.RE_HANGUL = RE_HANGUL;
exports.RE_HEBREW = RE_HEBREW;
exports.RE_HIRAGANA = RE_HIRAGANA;
exports.RE_KANJI = RE_KANJI;
exports.RE_KANNADA = RE_KANNADA;
exports.RE_KATAKANA = RE_KATAKANA;
exports.RE_KHMER = RE_KHMER;
exports.RE_LAO = RE_LAO;
exports.RE_LATIN = RE_LATIN;
exports.RE_LEADING_NEWLINE = RE_LEADING_NEWLINE;
exports.RE_MALAYALAM = RE_MALAYALAM;
exports.RE_MATCH_NEWLINES = RE_MATCH_NEWLINES;
exports.RE_MYANMAR = RE_MYANMAR;
exports.RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE;
exports.RE_ORIYA = RE_ORIYA;
exports.RE_SEPARATORS = RE_SEPARATORS;
exports.RE_SINHALA = RE_SINHALA;
exports.RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY = RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY;
exports.RE_TAMIL = RE_TAMIL;
exports.RE_TELUGU = RE_TELUGU;
exports.RE_THAI = RE_THAI;
exports.RE_TIBETAN = RE_TIBETAN;
exports.RE_TRAILING_NEWLINE = RE_TRAILING_NEWLINE;
exports.RE_UZBEK_LATIN_MODIFIER = RE_UZBEK_LATIN_MODIFIER;
exports.RE_VALID_ANSI_PAIRS = RE_VALID_ANSI_PAIRS;
exports.RE_VALID_HYPERLINKS = RE_VALID_HYPERLINKS;
exports.RE_ZERO_WIDTH = RE_ZERO_WIDTH;
exports.stripEmoji = stripEmoji;