How to use the pinyin.STYLE_TONE2 function in pinyin

To help you get started, we’ve selected a few pinyin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lovell / limax / lib / limax.js View on Github external
// Should we remove the separator before a digit where previous word does not end in a digit?
  let mergeDigitSuffixes = false;

  // Language-specific behaviour
  const lang = options.lang || '';
  if (lang.toLowerCase().startsWith('ja') || hepburn.containsKana(text)) {
    // Convert from Japanese Kana using Hepburn romanisation
    text = hepburn.fromKana(text);
    // Remove any remaining non-Kana, e.g. Kanji
    text = text.replace(/([^A-Za-z0-9\- ]+)/g, '');
  } else if (lang.toLowerCase().startsWith('zh') || /[\u4e00-\u9fa5]+/.test(text)) {
    // Should we use tone numbers? (default is true)
    const tone = (typeof options.tone === 'boolean') ? options.tone : true;
    mergeDigitSuffixes = tone;
    text = pinyin(text, {
      style: tone ? pinyin.STYLE_TONE2 : pinyin.STYLE_NORMAL
    }).join(' ');
    // Remove punctuation symbols
    const customNonPunctuation = customCharsAsArray(options.custom).map(function (c) { return `\\${c}`; }).join('');
    const nonPunctuationMatcher = new RegExp(`([^0-9A-Za-z ${customNonPunctuation}]+)`, 'g');
    text = text.replace(nonPunctuationMatcher, '');
    // Remove space around single character words, caused by non-Mandarin symbols in otherwise Mandarin text
    text = text.replace(/([^1-4]) ([A-Za-z]) /g, '$1$2');
  }
  // Convert to slug using speakingurl
  const separator = options.replacement || options.separator;
  const slug = speakingurl(text, {
    lang: lang || 'en',
    separator: typeof separator === 'string' ? separator : '-',
    maintainCase: options.maintainCase || false,
    custom: options.custom || {}
  });
github echarts-maps / echarts-mapmaker / src / maker.js View on Github external
function getPinyin(Chinese_words){
    const py = pinyin(Chinese_words, {
	    style: pinyin.STYLE_TONE2
	});
    return py.join('_');
}

pinyin

汉语拼音转换工具。

MIT
Latest version published 4 months ago

Package Health Score

70 / 100
Full package analysis