@spintax/core 0.9.0 → 0.11.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/dist/index.d.cts CHANGED
@@ -206,8 +206,8 @@ interface Analysis extends ExtractResult {
206
206
  */
207
207
  declare function normalizeBaseLang(locale?: string | null): string;
208
208
  /**
209
- * How many `{plural …}` forms this locale takes — 3 for the Slavic one/few/other
210
- * family (ru/uk/be + sr/hr/bs), 2 for everything else.
209
+ * How many `{plural …}` forms this locale takes — 6 for Arabic (zero/one/two/few/many/other),
210
+ * 3 for the Slavic one/few/other family (ru/uk/be + sr/hr/bs), 2 for everything else.
211
211
  *
212
212
  * Takes a RAW locale and normalizes internally, unlike the internal helper of the
213
213
  * same name: a public function that silently answered 2 for `sr-Latn` would be a
package/dist/index.d.ts CHANGED
@@ -206,8 +206,8 @@ interface Analysis extends ExtractResult {
206
206
  */
207
207
  declare function normalizeBaseLang(locale?: string | null): string;
208
208
  /**
209
- * How many `{plural …}` forms this locale takes — 3 for the Slavic one/few/other
210
- * family (ru/uk/be + sr/hr/bs), 2 for everything else.
209
+ * How many `{plural …}` forms this locale takes — 6 for Arabic (zero/one/two/few/many/other),
210
+ * 3 for the Slavic one/few/other family (ru/uk/be + sr/hr/bs), 2 for everything else.
211
211
  *
212
212
  * Takes a RAW locale and normalizes internally, unlike the internal helper of the
213
213
  * same name: a public function that silently answered 2 for `sr-Latn` would be a
package/dist/index.js CHANGED
@@ -742,6 +742,8 @@ function normalizeBaseLang(locale) {
742
742
  }
743
743
  function pluralArity(baseLang) {
744
744
  switch (baseLang) {
745
+ case "ar":
746
+ return 6;
745
747
  case "ru":
746
748
  case "uk":
747
749
  case "be":
@@ -759,6 +761,13 @@ function pluralFor(baseLang, n, forms) {
759
761
  const mod10 = abs % 10;
760
762
  const mod100 = abs % 100;
761
763
  switch (baseLang) {
764
+ case "ar":
765
+ if (abs === 0) return forms[0] ?? "";
766
+ if (abs === 1) return forms[1] ?? "";
767
+ if (abs === 2) return forms[2] ?? "";
768
+ if (mod100 >= 3 && mod100 <= 10) return forms[3] ?? "";
769
+ if (mod100 >= 11) return forms[4] ?? "";
770
+ return forms[5] ?? "";
762
771
  case "ru":
763
772
  case "uk":
764
773
  case "be":
@@ -1793,10 +1802,11 @@ function joinWithSeparators(elements, globalSep, globalLastsep) {
1793
1802
  }
1794
1803
  return joinFragments(pieces);
1795
1804
  }
1805
+ var UNSPACED_SCRIPT_RE = /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}ーー]+$/u;
1796
1806
  function padSeparator(sep) {
1797
1807
  const trimmed = phpTrim(sep);
1798
1808
  if (trimmed === "") return sep;
1799
- if (/^\p{L}+$/u.test(trimmed)) return ` ${trimmed} `;
1809
+ if (/^\p{L}+$/u.test(trimmed) && !UNSPACED_SCRIPT_RE.test(trimmed)) return ` ${trimmed} `;
1800
1810
  return sep;
1801
1811
  }
1802
1812
 
@@ -1909,9 +1919,11 @@ function trailingPunctuationStart(value) {
1909
1919
  }
1910
1920
  var SENTENCE_OPENERS = "\xBF\xA1";
1911
1921
  var LEAD = `(?:<[^>]+>|[${SENTENCE_OPENERS}]|${S})*`;
1922
+ var QUOTES = `"'\xAB\xBB\u2039\u203A\u201C\u201D\u2018\u2019`;
1923
+ var CLOSER = `[)\\]]|[${QUOTES}]+(?=${S}|$|<|\\/?>|[.,;:!?\u2026)\\]\u2014\u2013])`;
1912
1924
  var SPACE_BEFORE_PUNCT_RE = new RegExp(`(?<!${S})${S}+([,;:!?.])`, "gu");
1913
- var SPACE_AFTER_COMMA_RE = new RegExp(`([,;:])(?!\\p{Nd})(?!${S}|$|<)`, "gu");
1914
- var SPACE_AFTER_SENTENCE_RE = new RegExp(`(?<![.!?])([.!?]+)(?![.!?])(?!\\p{Nd})(?!${S}|$|<)`, "gu");
1925
+ var SPACE_AFTER_COMMA_RE = new RegExp(`([,;:])(?!\\p{Nd})(?!${S}|$|<|${CLOSER})`, "gu");
1926
+ var SPACE_AFTER_SENTENCE_RE = new RegExp(`(?<![.!?])([.!?]+)(?![.!?])(?!\\p{Nd})(?!${S}|$|<|${CLOSER})`, "gu");
1915
1927
  var SPACE_AFTER_OPENER_RE = new RegExp(`([${SENTENCE_OPENERS}])${S}+`, "gu");
1916
1928
  var CAP_FIRST_RE = new RegExp(`^(${LEAD})(\\p{Ll})`, "u");
1917
1929
  var up = (ch) => ch.toUpperCase();