@shaxpir/duiduidui-models 1.17.0 → 1.17.1

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.
@@ -59,8 +59,8 @@ exports.PinyinParser = {
59
59
  if (!text || text.length === 0)
60
60
  return [];
61
61
  let normalized = this.normalizeApostrophes(text.toLowerCase().trim());
62
- // Expand 'r (erhua via apostrophe) to 'er before splitting
63
- normalized = normalized.replace(/'r/g, "'er");
62
+ // Expand 'r (erhua via apostrophe) to 'er, but not when followed by a vowel
63
+ normalized = normalized.replace(/'r(?![aeiouāáǎàēéěèīíǐìōóǒòūúǔùǖǘǚǜüv])/gi, "'er");
64
64
  if (normalized.includes("'")) {
65
65
  return this._parseApostropheSplit(normalized, true);
66
66
  }
@@ -87,8 +87,9 @@ exports.PinyinParser = {
87
87
  ensurePinyinSpacing(text) {
88
88
  // Normalize apostrophes and lowercase
89
89
  text = this.normalizeApostrophes(text).toLowerCase();
90
- // Expand 'r (erhua via apostrophe) to 'er, then replace apostrophes with spaces
91
- text = text.replace(/'r/g, "'er");
90
+ // Expand 'r (erhua via apostrophe) to 'er, but not when 'r is followed by
91
+ // a vowel (which would mean 'r starts a syllable like 'rén, not erhua).
92
+ text = text.replace(/'r(?![aeiouāáǎàēéěèīíǐìōóǒòūúǔùǖǘǚǜüv])/gi, "'er");
92
93
  text = text.replace(/'/g, ' ');
93
94
  text = text.replace(/ +/g, ' ');
94
95
  const parts = [];
@@ -24,7 +24,10 @@ export declare const PinyinValidator: {
24
24
  */
25
25
  removeAccentMarks(text: string): string;
26
26
  /**
27
- * Check if a string is a valid pinyin syllable (with or without tone marks)
27
+ * Check if a string is a valid pinyin syllable (with or without tone marks).
28
+ * A valid single syllable has at most one tone mark — two tone marks means
29
+ * two syllables have been merged (e.g. "zhùān" looks like "zhuan" after
30
+ * stripping tones, but the two marks prove it's "zhù" + "ān").
28
31
  */
29
32
  isValidPinyin(text: string): boolean;
30
33
  /**
@@ -244,11 +244,18 @@ exports.PinyinValidator = {
244
244
  });
245
245
  },
246
246
  /**
247
- * Check if a string is a valid pinyin syllable (with or without tone marks)
247
+ * Check if a string is a valid pinyin syllable (with or without tone marks).
248
+ * A valid single syllable has at most one tone mark — two tone marks means
249
+ * two syllables have been merged (e.g. "zhùān" looks like "zhuan" after
250
+ * stripping tones, but the two marks prove it's "zhù" + "ān").
248
251
  */
249
252
  isValidPinyin(text) {
250
253
  if (!text || text.length === 0)
251
254
  return false;
255
+ // Count tone marks: a single syllable can have at most one
256
+ const toneCount = (text.match(TONE_MARKS) || []).length;
257
+ if (toneCount > 1)
258
+ return false;
252
259
  const normalized = stripToneMarks(text);
253
260
  return VALID_SYLLABLES.has(normalized);
254
261
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"