UNPKG

@tempots/std

Version:

Std library for TypeScript. Natural complement to the Tempo libraries.

200 lines (199 loc) 8.44 kB
import { MissingImplementationError as p } from "./error.js"; import { mapRegExp as l } from "./regexp.js"; const Z = (t, n) => { const e = t.indexOf(n); return e < 0 ? "" : t.substring(e + n.length); }, D = (t, n) => { const e = t.lastIndexOf(n); return e < 0 ? "" : t.substring(e + n.length); }, P = (t, n) => { const e = t.indexOf(n); return e < 0 ? "" : t.substring(0, e); }, R = (t, n) => { const e = t.lastIndexOf(n); return e < 0 ? "" : t.substring(0, e); }, g = (t) => t.substring(0, 1).toUpperCase() + t.substring(1), f = (t) => t.toUpperCase(), F = (t, n = !1) => n ? l(g(t), _, f) : l(g(t), z, f), G = (t) => t.replace($, ` `), Q = (t, n) => t == null && n == null ? 0 : t == null ? -1 : n == null ? 1 : b(t.toLowerCase(), n.toLowerCase()), K = (t, n) => t.substring(t.length - n.length).toLowerCase() === n.toLowerCase(), q = (t, n) => t.substring(0, n.length).toLowerCase() === n.toLowerCase(), J = (t, n) => S( t.toLowerCase(), n.map((e) => e.toLowerCase()) ), V = (t, n) => y( t.toLowerCase(), n.map((e) => e.toLowerCase()) ), X = (t) => t.trim().replace(d, " "), b = (t, n) => t < n ? -1 : t > n ? 1 : 0, h = (t, n) => t.toLowerCase().includes(n.toLowerCase()), Y = (t, n) => t.split(n).length - 1, v = (t, n) => n.some((e) => h(t, e)), tt = (t, n) => n.some((e) => t.includes(e)), nt = (t, n) => n.every((e) => h(t, e)), et = (t, n) => n.every((e) => t.includes(e)), rt = (t) => t.replace(/_/g, "-"), st = (t, n) => { if (t === n) return -1; const e = Math.min(t.length, n.length); for (let r = 0; r < e; r++) if (t.substring(r, r + 1) !== n.substring(r, r + 1)) return r; return e; }, A = (t, n = 20, e = "…") => { const r = t.length, s = e.length; return r > n ? n < s ? e.slice(s - n, n) : t.slice(0, n - s) + e : t; }, it = (t, n = 20, e = "…") => { const r = t.length, s = e.length; if (r > n) { if (n <= s) return A(t, n, e); const c = Math.ceil((n - s) / 2), u = Math.floor((n - s) / 2); return t.slice(0, c) + e + t.slice(r - u); } else return t; }, S = (t, n) => n.some((e) => t.endsWith(e)), ot = (t, n) => Array.from(t).filter(n).join(""), ct = (t, n) => x(t).filter(n).map((r) => String.fromCharCode(r)).join(""), ut = (t, n = 2166136261) => { let e = n; for (let r = 0, s = t.length; r < s; r++) e ^= t.charCodeAt(r), e += (e << 1) + (e << 4) + (e << 7) + (e << 8) + (e << 24); return e >>> 0; }, lt = (t) => t != null && t.length > 0, gt = (t) => E(t).split("_").join(" "), ft = (t) => t.length > 0 && !N.test(t), at = (t) => M.test(t), pt = (t) => !T.test(t), ht = (t) => t.toLowerCase() === t, dt = (t) => t.toUpperCase() === t, Ct = (t, n) => t != null && t !== "" ? t : n, bt = (t) => U.test(t), At = (t) => t == null || t === "", St = (t) => t.substring(0, 1).toLowerCase() + t.substring(1), L = (t, n = 1) => { const e = Math.floor((t.length - n + 1) * Math.random()); return t.substring(e, e + n); }, m = (t, n) => Array.from({ length: n }, () => L(t)).join(""), Lt = (t) => m(j, t), mt = (t, n) => Array.from(n).map(t), wt = (t, n) => t.split(n).join(""), It = (t, n) => t.endsWith(n) ? t.substring(0, t.length - n.length) : t, yt = (t, n, e) => t.substring(0, n) + t.substring(n + e), xt = (t, n) => t.startsWith(n) ? t.substring(n.length) : t, Ot = (t, n) => { const e = t.indexOf(n); return e < 0 ? t : t.substring(0, e) + t.substring(e + n.length); }, Wt = (t) => { const n = Array.from(t); return n.reverse(), n.join(""); }, w = (t, n = "'") => n === "'" ? t.includes("'") ? t.includes('"') ? "'" + t.split("'").join("\\'") + "'" : '"' + t + '"' : "'" + t + "'" : t.includes('"') ? t.includes("'") ? '"' + t.split('"').join('\\"') + '"' : "'" + t + "'" : '"' + t + '"', I = (t, n = "'") => n + t.split(n).join("\\" + n) + n, Et = (t, n = "'") => t.indexOf(` `) >= 0 ? I(t, "`") : w(t, n), Bt = (t, n) => { const e = t.indexOf(n); return e < 0 ? [t] : [t.substring(0, e), t.substring(e + n.length)]; }, y = (t, n) => n.some((e) => t.startsWith(e)), jt = (t, n, e = n) => `${n}${t}${e}`, x = (t) => Array.from({ length: t.length }, (n, e) => t.charCodeAt(e)), zt = (t, n) => { const e = []; for (; t.length > 0; ) e.push(t.substring(0, n)), t = t.substring(n); return e; }, Tt = (t) => t.split(C), Nt = (t, n) => W(O(t, n), n), O = (t, n) => { let e = 0; for (let r = 0; r < t.length && n.includes(t.charAt(r)); r++) e++; return t.substring(e); }, W = (t, n) => { const e = t.length; let r = e, s; for (let c = 0; c < e && (s = e - c - 1, n.includes(t.charAt(s))); c++) r = s; return t.substring(0, r); }, E = (t) => (t = t.replace(/::/g, "/"), t = t.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2"), t = t.replace(/([a-z\d])([A-Z])/g, "$1_$2"), t = t.replace(/-/g, "_"), t.toLowerCase()), _t = (t) => t.substring(0, 1).toUpperCase() + t.substring(1), Mt = (t, n = 78, e = "", r = ` `) => t.split(C).map( (s) => B(s.replace(d, " ").trim(), n, e, r) ).join(r), a = (t, n) => { if (n < 0 || n >= t.length) return !1; const e = t.charCodeAt(n); return e === 9 || e === 10 || e === 11 || e === 12 || e === 13 || e === 32; }, Ut = (t) => { if (typeof Buffer < "u") return Buffer.from(t).toString("base64"); if (typeof btoa < "u") return btoa(t); throw new p( "No implementation found for base64 encoding" ); }, $t = (t) => { if (typeof Buffer < "u") return Buffer.from(t, "base64").toString("utf8"); if (typeof atob < "u") return atob(t); throw new p( "No implementation found for base64 decoding" ); }, B = (t, n, e, r) => { const s = [], c = t.length, u = e.length; let o = 0; for (n -= u; ; ) { if (o + n >= c - u) { s.push(t.substring(o)); break; } let i = 0; for (; !a(t, o + n - i) && i < n; ) i++; if (i === n) { for (i = 0; !a(t, o + n + i) && o + n + i < c; ) i++; s.push(t.substring(o, o + n + i)), o += n + i + 1; } else s.push(t.substring(o, o + n - i)), o += n - i + 1; } return e + s.join(r + e); }, kt = (t, n, e) => { const r = e - t.length; return r > 0 ? n.repeat(r) + t : t; }, Ht = (t, n, e) => { const r = e - t.length; return r > 0 ? t + n.repeat(r) : t; }, Zt = (t, n) => { const e = t.lastIndexOf(n); return e >= 0 ? [t.substring(0, e), t.substring(e + n.length)] : [t]; }, Dt = (t, n) => { const e = t.indexOf(n); return e >= 0 ? [t.substring(0, e), t.substring(e + n.length)] : [t]; }, j = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", z = /[^a-zA-Z]([a-z])/g, T = /[^\t\n\r ]/, N = /[^a-zA-Z]/, _ = /[ \t\r\n][a-z]/g, M = /^[a-z0-9]+$/i, U = /^[0-9]+$/, d = /[ \t\r\n]+/g, C = /\r\n|\n\r|\n|\r/g, $ = /\r\n|\n\r|\r/g; export { G as canonicalizeNewlines, g as capitalize, F as capitalizeWords, zt as chunkString, X as collapseText, Q as compareCaseInsensitive, b as compareStrings, et as containsAllText, nt as containsAllTextCaseInsensitive, tt as containsAnyText, v as containsAnyTextCaseInsensitive, Y as countStringOccurrences, rt as dasherize, $t as decodeBase64, Ot as deleteFirstFromString, It as deleteStringAfter, xt as deleteStringBefore, wt as deleteSubstring, A as ellipsis, it as ellipsisMiddle, Ut as encodeBase64, ct as filterCharcodes, ot as filterChars, gt as humanize, Ct as ifEmptyString, ft as isAlpha, at as isAlphaNum, pt as isBreakingWhitespace, bt as isDigitsOnly, At as isEmptyString, ht as isLowerCase, a as isSpaceAt, dt as isUpperCase, Et as jsQuote, St as lowerCaseFirst, kt as lpad, mt as mapChars, I as quote, m as randomStringSequence, Lt as randomStringSequenceBase64, L as randomSubString, Wt as reverseString, Ht as rpad, w as smartQuote, Dt as splitStringOnFirst, Zt as splitStringOnLast, Bt as splitStringOnce, S as stringEndsWithAny, lt as stringHasContent, ut as stringHashCode, y as stringStartsWithAny, x as stringToCharcodes, st as stringsDifferAtIndex, Z as substringAfter, D as substringAfterLast, P as substringBefore, R as substringBeforeLast, jt as surroundString, h as textContainsCaseInsensitive, J as textEndsWithAnyCaseInsensitive, K as textEndsWithCaseInsensitive, V as textStartsWithAnyCaseInsensitive, q as textStartsWithCaseInsensitive, Tt as textToLines, Nt as trimChars, O as trimCharsLeft, W as trimCharsRight, yt as trimStringSlice, E as underscore, _t as upperCaseFirst, Mt as wrapColumns, B as wrapLine };