@spintax/core 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +1 -1
- package/dist/index.cjs +15 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1917,7 +1917,7 @@ var TLD_UPPER = "\\p{Lu}\\p{Lt}\\p{Lm}\\p{Lo}";
|
|
|
1917
1917
|
var TLD = `(?:${XN}[a-zA-Z0-9\\-\\u017F\\u212A]{2,59}|[${TLD_LOWER}][${TLD_LOWER}\\p{N}-]{1,62}|[${TLD_UPPER}][${TLD_UPPER}\\p{N}-]{1,62})`;
|
|
1918
1918
|
var DOMAIN_PART = `(?:${LABEL}\\.)+${TLD}`;
|
|
1919
1919
|
var URI_BODY = `[^\\x00${WS}<>"')\\]]`;
|
|
1920
|
-
var URI_RE = new RegExp(`(?:(?:https?|ftp)
|
|
1920
|
+
var URI_RE = new RegExp(`(?:(?:https?|ftp):\\/\\/${URI_BODY}*|(?:mailto|tel):${URI_BODY}+)`, "giu");
|
|
1921
1921
|
var MAILTEL_PREFIX_RE = /^(?:mailto|tel):/iu;
|
|
1922
1922
|
var DOMAIN_AT_RE = new RegExp(`${DOMAIN_PART}${WORD_BOUNDARY}`, "uy");
|
|
1923
1923
|
var DOMAIN_SCAN_RE = new RegExp(`${AFTER_NON_WORD}(?:(${DOMAIN_PART}${WORD_BOUNDARY})|(?:${LABEL}\\.)*${LABEL})`, "gu");
|
|
@@ -1966,12 +1966,15 @@ var SENTENCE_OPENERS = "\xBF\xA1";
|
|
|
1966
1966
|
var LEAD = `(?:<[^>]+>|[${SENTENCE_OPENERS}]|${S})*`;
|
|
1967
1967
|
var QUOTES = `"'\xAB\xBB\u2039\u203A\u201C\u201D\u2018\u2019`;
|
|
1968
1968
|
var CLOSER = `[)\\]]|[${QUOTES}]+(?=${S}|$|<|\\/?>|[.,;:!?\u2026)\\]\u2014\u2013])`;
|
|
1969
|
+
var DOT_TOKEN_RE = new RegExp(`(?<=^|${S}|[(\\[{>/\\\\${QUOTES}])\\.[\\p{L}\\p{N}][\\p{L}\\p{N}_.\\-]*`, "gu");
|
|
1969
1970
|
var SPACE_BEFORE_PUNCT_RE = new RegExp(`(?<!${S})${S}+([,;:!?.])`, "gu");
|
|
1970
1971
|
var SPACE_AFTER_COMMA_RE = new RegExp(`([,;:])(?!\\p{Nd})(?!${S}|$|<|${CLOSER})`, "gu");
|
|
1971
1972
|
var SPACE_AFTER_SENTENCE_RE = new RegExp(`(?<![.!?])([.!?]+)(?![.!?])(?!\\p{Nd})(?!${S}|$|<|${CLOSER})`, "gu");
|
|
1972
1973
|
var SPACE_AFTER_OPENER_RE = new RegExp(`([${SENTENCE_OPENERS}])${S}+`, "gu");
|
|
1973
1974
|
var CAP_FIRST_RE = new RegExp(`^(${LEAD})(\\p{Ll})`, "u");
|
|
1974
1975
|
var up = (ch) => ch.toUpperCase();
|
|
1976
|
+
var upTurkic = (ch) => ch === "i" ? "\u0130" : ch.toUpperCase();
|
|
1977
|
+
var TURKIC_LANGS = /* @__PURE__ */ new Set(["tr", "az"]);
|
|
1975
1978
|
function indexLeads(text) {
|
|
1976
1979
|
const n = text.length;
|
|
1977
1980
|
const leadEnd = new Int32Array(n + 1);
|
|
@@ -2004,7 +2007,7 @@ function leadEndFrom(text, i, leads) {
|
|
|
2004
2007
|
}
|
|
2005
2008
|
return j < text.length ? leads().leadEnd[j] : j;
|
|
2006
2009
|
}
|
|
2007
|
-
function capitalizeAfter(text, lower, next, context) {
|
|
2010
|
+
function capitalizeAfter(text, lower, next, context, upper) {
|
|
2008
2011
|
const leads = () => {
|
|
2009
2012
|
if (context.leads === null || context.leads.leadEnd.length !== text.length + 1) context.leads = indexLeads(text);
|
|
2010
2013
|
return context.leads;
|
|
@@ -2019,7 +2022,7 @@ function capitalizeAfter(text, lower, next, context) {
|
|
|
2019
2022
|
if (cp === void 0) continue;
|
|
2020
2023
|
const ch = String.fromCodePoint(cp);
|
|
2021
2024
|
if (!lower.test(ch)) continue;
|
|
2022
|
-
out += text.slice(emitted, at) +
|
|
2025
|
+
out += text.slice(emitted, at) + upper(ch);
|
|
2023
2026
|
emitted = at + ch.length;
|
|
2024
2027
|
from = emitted;
|
|
2025
2028
|
}
|
|
@@ -2052,7 +2055,7 @@ var afterLineBreak = (text, from) => {
|
|
|
2052
2055
|
const at = text.indexOf("\n", from);
|
|
2053
2056
|
return at === -1 ? null : { leadStart: at + 1, resume: at + 1 };
|
|
2054
2057
|
};
|
|
2055
|
-
var SHIELD_PREFIXES = ["URL", "URI", "EMAIL", "DOM", "NUM", "ABBR"];
|
|
2058
|
+
var SHIELD_PREFIXES = ["URL", "URI", "EMAIL", "DOTTOK", "DOM", "NUM", "ABBR"];
|
|
2056
2059
|
var RESTORE_RE2 = new RegExp(`\\x00(?:${SHIELD_PREFIXES.join("|")})_\\d+\\x00`, "gu");
|
|
2057
2060
|
function restore(text, input, placeholders) {
|
|
2058
2061
|
if (!input.includes("\0")) {
|
|
@@ -2087,7 +2090,8 @@ function restoreAsTheLoopDoes(text, placeholders) {
|
|
|
2087
2090
|
}
|
|
2088
2091
|
return out;
|
|
2089
2092
|
}
|
|
2090
|
-
function postProcess(input) {
|
|
2093
|
+
function postProcess(input, locale = "") {
|
|
2094
|
+
const upper = TURKIC_LANGS.has(normalizeBaseLang(locale)) ? upTurkic : up;
|
|
2091
2095
|
const placeholders = /* @__PURE__ */ new Map();
|
|
2092
2096
|
let counter = 0;
|
|
2093
2097
|
const store = (value, prefix) => {
|
|
@@ -2107,6 +2111,7 @@ function postProcess(input) {
|
|
|
2107
2111
|
(m) => storeWithTrailingPunct(m, MAILTEL_PREFIX_RE.test(m) ? "URI" : "URL")
|
|
2108
2112
|
);
|
|
2109
2113
|
text = shieldEmails(text, (m) => store(m, "EMAIL"));
|
|
2114
|
+
text = text.replace(DOT_TOKEN_RE, (m) => storeWithTrailingPunct(m, "DOTTOK"));
|
|
2110
2115
|
text = shieldDomains(text, (m) => store(m, "DOM"));
|
|
2111
2116
|
text = text.replace(DECIMAL_RE, (m) => store(m, "NUM"));
|
|
2112
2117
|
text = text.replace(MULTI_ABBR_RE, (m) => store(m, "ABBR"));
|
|
@@ -2116,11 +2121,11 @@ function postProcess(input) {
|
|
|
2116
2121
|
text = text.replace(SPACE_AFTER_COMMA_RE, "$1 ");
|
|
2117
2122
|
text = text.replace(SPACE_AFTER_SENTENCE_RE, "$1 ");
|
|
2118
2123
|
text = text.replace(SPACE_AFTER_OPENER_RE, "$1");
|
|
2119
|
-
text = text.replace(CAP_FIRST_RE, (_m, lead, ch) => lead +
|
|
2124
|
+
text = text.replace(CAP_FIRST_RE, (_m, lead, ch) => lead + upper(ch));
|
|
2120
2125
|
const leadContext = { leads: null };
|
|
2121
|
-
text = capitalizeAfter(text, LOWER_RE, afterSentenceEnd, leadContext);
|
|
2122
|
-
text = capitalizeAfter(text, LOWER_RE, afterBlockTag(), leadContext);
|
|
2123
|
-
text = capitalizeAfter(text, LOWER_RE, afterLineBreak, leadContext);
|
|
2126
|
+
text = capitalizeAfter(text, LOWER_RE, afterSentenceEnd, leadContext, upper);
|
|
2127
|
+
text = capitalizeAfter(text, LOWER_RE, afterBlockTag(), leadContext, upper);
|
|
2128
|
+
text = capitalizeAfter(text, LOWER_RE, afterLineBreak, leadContext, upper);
|
|
2124
2129
|
return restore(text, input, placeholders).trim();
|
|
2125
2130
|
}
|
|
2126
2131
|
|
|
@@ -2141,7 +2146,7 @@ function renderWith(input, rng, opts = {}) {
|
|
|
2141
2146
|
};
|
|
2142
2147
|
const ast = resolveAst(input);
|
|
2143
2148
|
let out = renderAst(ast, ctx);
|
|
2144
|
-
if (opts.postProcess !== false) out = postProcess(out);
|
|
2149
|
+
if (opts.postProcess !== false) out = postProcess(out, ctx.locale);
|
|
2145
2150
|
return safetyRestore(out);
|
|
2146
2151
|
}
|
|
2147
2152
|
function resolveAst(input) {
|