!function(e, t) { "object" == typeof exports && "undefined" != typeof module ? t(exports) : "function" == typeof define && define.amd ? define([ "exports" ], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).StringNaturalCompare = {}); }(this, (function(e) { "use strict"; const t = {}, r = []; function isNumberCode(e) { return e >= 48 && e <= 57; } function naturalCompare(e, t, a) { const n = _strLength(e, "a"), o = _strLength(t, "b"); let u = 0, d = 0, l = r, p = 0; for (a && (a.caseInsensitive && (e = e.toLowerCase(), t = t.toLowerCase()), a.alphabet && (l = buildAlphabetIndexMap(a.alphabet))); u < n && d < o; ) { let r, a = e.charCodeAt(u), i = t.charCodeAt(d); if (isNumberCode(a)) { if (!isNumberCode(i)) return a - i; let l = u, f = d; for (;48 === a && ++l < n; ) a = e.charCodeAt(l); for (;48 === i && ++f < o; ) i = t.charCodeAt(f); l !== f && 0 === p && (p = l - f); let b = _indexOfNumEnd(e, n, l), m = _indexOfNumEnd(t, o, f); if (r = b - l - m + f, 0 !== r) return r; for (;l < b; ) if (r = e.charCodeAt(l++) - t.charCodeAt(f++), 0 !== r) return r; u = b, d = m; } else { if (0 !== (r = _alphabetCompare(a, i, l))) return r; ++u, ++d; } } return u < n ? 1 : d < o ? -1 : p; } function buildAlphabetIndexMap(e) { const r = t[e]; if (void 0 !== r) return r; const a = [], n = e.split("").reduce(((e, t) => Math.max(e, t.charCodeAt(0))), 0); for (let e = 0; e <= n; e++) a.push(-1); for (let t = 0; t < e.length; t++) a[e.charCodeAt(t)] = t; return t[e] = a; } function _indexOfNumEnd(e, t, r) { for (;r < t && isNumberCode(e.charCodeAt(r)); ) ++r; return r; } function _alphabetCompare(e, t, r) { return e !== t ? e < r.length && t < r.length && -1 !== r[e] && -1 !== r[t] ? r[e] - r[t] : e - t : 0; } function _strLength(e, t) { if ("string" != typeof e) throw new TypeError(`The ${t} argument must be a string. Received type '${typeof e}'`); return e.length; } Object.defineProperty(naturalCompare, "__esModule", { value: !0 }), Object.defineProperty(naturalCompare, "naturalCompare", { value: naturalCompare }), Object.defineProperty(naturalCompare, "default", { value: naturalCompare }), Object.defineProperty(naturalCompare, "isNumberCode", { value: isNumberCode }), Object.defineProperty(naturalCompare, "buildAlphabetIndexMap", { value: buildAlphabetIndexMap }), Object.defineProperty(naturalCompare, "_indexOfNumEnd", { value: _indexOfNumEnd }), Object.defineProperty(naturalCompare, "_alphabetCompare", { value: _alphabetCompare }), Object.defineProperty(naturalCompare, "_strLength", { value: _strLength }), e._alphabetCompare = _alphabetCompare, e._indexOfNumEnd = _indexOfNumEnd, e._strLength = _strLength, e.buildAlphabetIndexMap = buildAlphabetIndexMap, e.default = naturalCompare, e.isNumberCode = isNumberCode, e.naturalCompare = naturalCompare, Object.defineProperty(e, "__esModule", { value: !0 }); })); //# sourceMappingURL=index.umd.production.min.cjs.map