{"name":"pinyin","version":"2.3.2","keywords":["拼音","Pinyin"],"author":{"name":"闲耘","email":"hotoo.cn@gmail.com"},"license":"MIT","_id":"pinyin@2.3.2","homepage":"http://pinyin.hotoo.me/","bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"bin":{"pinyin":"./bin/pinyin"},"spm":{"main":"index.js","tests":"tests/*-spec.js","devDependencies":{"expect.js":"0.3.1"}},"dist":{"shasum":"746199ff8d561c7c93795cf365972c6defa96b9d","tarball":"http://registry-npm.ywwl.com/pinyin/download/pinyin-2.3.2.tgz","integrity":"sha512-diZmYTiqJqwW1YpynHCS0nowmHwAxcf4sP9p55zS0Kb2dmzoTkvTMzHKuaxJRqjFb6/c3FbfG//DTal4REO+Iw==","signatures":[{"sig":"MEQCIG6BI7n0loKVSrnpoclPHhGjcnJOHIJhgqaCkO8S4aevAiAdeqTmnc4cTyva2XV2AyUxNr2LtowQTPE/RWlL8uppyw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":4193421,"noattachment":false,"key":"/pinyin/-/pinyin-2.3.2.tgz"},"main":"index.js","_from":".","_shasum":"746199ff8d561c7c93795cf365972c6defa96b9d","gitHead":"6d4319bbbebc047d5d637443641c248c573b5035","scripts":{"test":"make test"},"_npmUser":{"name":"hotoo","email":"hotoo.cn@gmail.com"},"repository":{"url":"https://github.com/hotoo/pinyin.git","type":"git"},"_npmVersion":"1.4.13","description":"汉语拼音转换工具。","directories":{"test":"tests","example":"examples"},"dependencies":{"segment":"0.0.5","commander":"~1.1.1"},"devDependencies":{"iconv":"2.1.0","mocha":"1.17.1","request":"2.33.0","expect.js":"0.3.1"},"readme":"# pīnyīn (v3)\n\npinyin, The convert tool of chinese pinyin.\n\n---\n\n[![NPM version][npm-badge]][npm-url]\n[![Build Status][build-badge]][build-url]\n[![Coverage Status][coveralls-badge]][coveralls-url]\n[![Language Grade: JavaScript][lgtm-badge]][lgtm-url]\n[![NPM downloads][npm-downloads]][npm-url]\n\n\n[npm-badge]: https://img.shields.io/npm/v/pinyin.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/pinyin\n[npm-downloads]: http://img.shields.io/npm/dm/pinyin.svg?style=flat\n[build-badge]: https://github.com/hotoo/pinyin/actions/workflows/node.js.yml/badge.svg\n[build-url]: https://github.com/hotoo/pinyin/actions\n[coveralls-badge]: https://coveralls.io/repos/hotoo/pinyin/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/r/hotoo/pinyin\n[lgtm-badge]: https://img.shields.io/lgtm/grade/javascript/g/hotoo/pinyin.svg?logo=lgtm&logoWidth=18\n[lgtm-url]: https://lgtm.com/projects/g/hotoo/pinyin/context:javascript\n\n\nWeb Site: [简体中文](/) | English | [한국어](/ko-KR/)\n\nREADME: [简体中文](README.md) | English | [한국어](README.ko-KR.md)\n\n\nConvert Han to pinyin. useful for phonetic notation, sorting, and searching.\n\n> Note: This module both support Node and Web browser.\n>\n> Python version see [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin)\n\n---\n\n## Feature\n\n* Segmentation for heteronym words.\n* Support Traditional and Simplified Chinese.\n* Support multiple pinyin style.\n\n## Install\n\nvia npm:\n\n```bash\nnpm install pinyin --save\n```\n\n## Usage\n\nfor developer:\n\n```typescript\nimport pinyin from \"pinyin\";\n\nconsole.log(pinyin(\"中心\"));    // [ [ 'zhōng' ], [ 'xīn' ] ]\n\nconsole.log(pinyin(\"中心\", {\n  heteronym: true                // Enable heteronym mode.\n}));                            // [ [ 'zhōng', 'zhòng' ], [ 'xīn' ] ]\n\nconsole.log(pinyin(\"中心\", {\n  heteronym: true,              // Enable heteronym mode.\n  segment: true                 // Enable Chinese words segmentation, fix most heteronym problem.\n}));                            // [ [ 'zhōng' ], [ 'xīn' ] ]\n\nconsole.log(pinyin(\"我喜欢你\", {\n  segment: true,                // Enable segmentation. Needed for grouping.\n  group: true                   // Group pinyin segments\n}));                            // [ [ 'wǒ' ], [ 'xǐhuān' ], [ 'nǐ' ] ]\n\nconsole.log(pinyin(\"中心\", {\n  style: pinyin.STYLE_INITIALS, // Setting pinyin style.\n  heteronym: true\n}));                            // [ [ 'zh' ], [ 'x' ] ]\n\nconsole.log(pinyin(\"华夫人\", {\n  mode: \"surname\",              // 姓名模式。\n}));                            // [ ['huà'], ['fū'], ['rén'] ]\n```\n\nfor cli:\n\n```bash\n$ pinyin 中心\nzhōng xīn\n$ pinyin -h\n```\n\n## Types\n\n### IPinyinOptions\n\nThe types for the second argument of pinyin method.\n\n```typescript\nexport interface IPinyinOptions {\n  style?: IPinyinStyle; // output style of pinyin.\n  mode?: IPinyinMode, // mode of pinyin.\n  segment?: IPinyinSegment | boolean;\n  heteronym?: boolean;\n  group?: boolean;\n  compact?: boolean;\n}\n```\n\n### IPinyinStyle\n\nThe output style of pinyin.\n\n```typescript\nexport type IPinyinStyle =\n  \"normal\" | \"tone\" | \"tone2\" | \"to3ne\" | \"initials\" | \"first_letter\" | // Suggest.\n  \"NORMAL\" | \"TONE\" | \"TONE2\" | \"TO3NE\" | \"INITIALS\" | \"FIRST_LETTER\" |\n  0        | 1      | 2       | 5       | 3          | 4;               // compatibility.\n```\n\n### IPinyinMode\n\nThe mode of pinyin.\n\n```typescript\n// - NORMAL: Default mode is normal mode.\n// - SURNAME: surname mode, for chinese surname.\nexport type IPinyinMode =\n  \"normal\" | \"surname\" |\n  \"NORMAL\" | \"SURNAME\";\n```\n\n### IPinyinSegment\n\nThe segment method.\n\n- Default is disable segment: `false`，\n- If set `true`, use \"Intl.Segmenter\" module default for segment on Web and Node.\n- Also specify follow string for segment (bug just \"Intl.Segmenter\", \"segmentit\" is support on web):\n\n```typescript\nexport type IPinyinSegment = \"Intl.Segmenter\" | \"nodejieba\" | \"segmentit\" | \"@node-rs/jieba\";\n```\n\n\n## API\n\n### `<Array> pinyin(words[, options])`\n\nConvert Han （汉字） to pinyin.\n\n`options` argument is optional, for sepcify heteronym mode and pinyin styles.\n\nReturn a `Array<Array<String>>`. If one of Han is heteronym word, it would be\nhave multiple pinyin.\n\n### `Number pinyin.compare(a, b)`\n\nDefault compare implementation for pinyin.\n\n\n## Options\n\n#### `<Boolean> options.segment`\n\nEnable Chinese word segmentation. Segmentation is helpful for fix heteronym\nproblem, but performance will be more slow, and need more CPU and memory.\n\nDefault is `false`.\n\n### `<Boolean> options.heteronym`\n\nEnable or disable heteronym mode. default is disabled, `false`.\n\n### `<Boolean> options.group`\n\nGroup pinyin by phrases. for example:\n\n```\n我喜欢你\nwǒ xǐhuān nǐ\n```\n\n### `<Object> options.style`\n\nSpecify pinyin style. please use static properties like `STYLE_*`.\ndefault is `.STYLE_TONE`. see Static Property for more.\n\n### `options.mode`\n\npinyin mode, default is `pinyin.MODE_NORMAL`. If you cleared in surname scene,\nuse `pinyin.MODE_SURNAME` maybe better.\n\n## Static Property\n\n### `.STYLE_NORMAL`\n\nNormal mode.\n\nExample: `pin yin`\n\n### `.STYLE_TONE`\n\nTone style, this is default.\n\nExample: `pīn yīn`\n\n### `.STYLE_TONE2`\n\ntone style by postfix number [0-4].\n\nExample: `pin1 yin1`\n\n### `.STYLE_TO3NE`\n\ntone style by number [0-4] after phonetic notation character.\n\nExample: `pin1 yin1`\n\n### `.STYLE_INITIALS`\n\nInitial consonant (of a Chinese syllable).\n\nExample: pinyin of `中国` is `zh g`\n\nNote: when a Han （汉字） without initial consonant, will convert to empty string.\n\n### `.STYLE_FIRST_LETTER`\n\nFirst letter style.\n\nExample: `p y`\n\n### `pinyin.MODE_NORMAL`\n\nNormal mode. This is the default mode.\n\n### `pinyin.MODE_SURNAME`\n\nSurname mode. If chinese word is surname, The pinyin of surname is prioritized.\n\n## Test\n\n```\nnpm test\n```\n\n## Q&A\n\n### How to sort by pinyin?\n\nThis module provide default compare implementation:\n\n```js\nconst pinyin = require('pinyin');\n\nconst data = '我要排序'.split('');\nconst sortedData = data.sort(pinyin.compare);\n```\n\nBut if you need different implementation, do it like:\n\n```\nconst pinyin = require('pinyin');\n\nconst data = '我要排序'.split('');\n\n// Suggest you to store pinyin result by data persistence.\nconst pinyinData = data.map(han => ({\n  han: han,\n  pinyin: pinyin(han)[0][0], // Choose you options and styles.\n}));\nconst sortedData = pinyinData.sort((a, b) => {\n  return a.pinyin.localeCompare(b.pinyin);\n}).map(d => d.han);\n```\n\n## Donate\n\nIf this module is helpful for you, please Star this repository.\n\nAnd you have chioce donate to me via Aliapy or WeChat:\n\n<img src=\"https://hotoo.github.io/images/donate-hotoo.png\" alt=\"Alipay:hotoo.cn@gmail.com, WeChat:hotoome\" width=\"400\" />\n\n\n## License\n\n[MIT](http://hotoo.mit-license.org/)\n","publish_time":1401774137945,"maintainers":[{"name":"hotoo","email":"hotoo.cn@gmail.com"}],"_cnpm_publish_time":1401774137945,"dist-tags":{"alpha":"4.0.0-alpha.3","latest":"4.0.0"}}