UNPKG

@visulima/string

Version:

Functions for manipulating strings.

102 lines (99 loc) 5.51 kB
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"); export { RE_GURMUKHI as A, RE_KANNADA as B, RE_TAMIL as C, RE_TELUGU as D, RE_MALAYALAM as E, RE_SINHALA as F, RE_THAI as G, RE_LAO as H, RE_TIBETAN as I, RE_MYANMAR as J, RE_ETHIOPIC as K, RE_KHMER as L, RE_ORIYA as M, RE_ANSI_LINK_END as N, RE_CONTROL as O, ESCAPES as P, ANSI_ESCAPE_LINK as Q, RE_FAST_ANSI as R, ANSI_SGR_TERMINATOR as S, ANSI_ESCAPE_BELL as T, ANSI_CSI as U, RE_ESCAPE_PATTERN as V, ANSI_RESET_CODES as W, END_CODE as X, RE_ZERO_WIDTH as Y, RE_VALID_ANSI_PAIRS as a, RE_VALID_HYPERLINKS as b, RE_ANSI as c, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as d, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as e, RE_LEADING_NEWLINE as f, RE_TRAILING_NEWLINE as g, RE_MATCH_NEWLINES as h, RE_DETECT_INDENTATION as i, RE_EMOJI as j, RE_SEPARATORS as k, RE_CYRILLIC as l, RE_LATIN as m, RE_GREEK as n, RE_GREEK_LATIN_SPLIT as o, RE_KANJI as p, RE_HEBREW as q, RE_ARABIC as r, stripEmoji as s, RE_HANGUL as t, RE_UZBEK_LATIN_MODIFIER as u, RE_KATAKANA as v, RE_HIRAGANA as w, RE_DEVANAGARI as x, RE_BENGALI as y, RE_GUJARATI as z };