{"name":"pinyin","version":"2.10.0","keywords":["拼音","汉语","汉字","中文","Pinyin"],"author":{"name":"闲耘","email":"hotoo.cn@gmail.com"},"license":"MIT","_id":"pinyin@2.10.0","homepage":"http://pinyin.hotoo.me/","bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"bin":{"pinyin":"bin/pinyin"},"dist":{"shasum":"832c61d73019c5cb67e4ea0b7c2462dec8c3a992","tarball":"http://registry-npm.ywwl.com/pinyin/download/pinyin-2.10.0.tgz","fileCount":14,"integrity":"sha512-6psdK9BCkhr19jsSD3p+77+DjuJHMNTUccclEoBqIIka16IN1T2nIgdrFy1IJneR28AkSD2TnJlnP8r6pzjZYw==","signatures":[{"sig":"MEYCIQDbJwn28XScmx5lF3ZqES5Rj+LOVCUgTkpHx2/Kqp+PZQIhAM/wjX6yYC0caKXLMYmm/AyCFN38YNivijn42SbT2eCd","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3821029,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgcuaXCRA9TVsSAnZWagAAF9oQAIhiddy3M9+UWPmLI/4P\nVkXjZDs94I5puPqNP7K9n7LdA1nE7Y5vV+f8OOuuGSnvqqWLVzOJY4FyHSEH\nB9V93Lq78FuvJDkF3m2rAVG5PvP8S0QmBfm4Pmx4DGdBD3LT03dWyAM5c9Vw\nFSqcnZu8QT8HxwrtILUEhhZV5GSMafNcdAIR2a/kzpV+OAJFDEiDRShzEx+c\nDtUsPCyjd3cB/HoDiSL4mYsvLTKAhomHhZD+9fhtAO/Rf0cD61W/IRRSQ2xV\nzgmapxbnCzVTaUmfFhoNuchN4GucB2AOdFug4yWVh36sD0C2bxja+Q22IMdT\neany/XjLhGF8Mn01Er+gFyMVrgFMaMWHOPiyRTWRg227OgWVfMjqf2xkCBvK\n79xkFXlCNZrmZyAByli6f7Hp9tzSH9KZgy0roIV7JSY84LBqXoWYC/AvBjIX\n4CU3YEcbV1NnfcpfWlELWpJlwF+hI6jnlHqL1j8bKPgdQvHUjlS6Mc/AS6lv\npg4oJu54tQT3PJ+WGe/U03LFd0ofeJPsJfCU8oBAR58kDDSsWbfw9+8bOhGc\n6QHoLr8QMzdpfkHbP0BN2TelbKxWO3oG01BvtXIhFaUeGxvZ3gFrBc11PuBs\nmfZ/8Vfeook4U/vF5/aAg1XnbNiWHX/OkqfYgWyQBTTtupRvxqJ33eeMhkhs\nMYPa\r\n=KXwC\r\n-----END PGP SIGNATURE-----\r\n","size":1081918,"noattachment":false,"key":"/pinyin/-/pinyin-2.10.0.tgz"},"main":"lib/index.js","browser":"lib/web-pinyin.js","gitHead":"b0f12dfc6f4cfb0bd997a51ca1fd0782a7c8c98f","scripts":{"lint":"eslint ./lib/ ./bin/ ./tests/","test":"npm run lint && npm run test-cli && npm run test-npm && npm run benchmark","test-cli":"mocha -R spec --timeout 5000 tests/cli.test.js","test-npm":"istanbul cover _mocha -- --harmony --reporter spec --timeout 2000 --inline-diffs ./tests/test.js","benchmark":"node tests/benchmark.test.js"},"_npmUser":{"name":"hotoo","email":"hotoo.cn@gmail.com"},"repository":{"url":"git+https://github.com/hotoo/pinyin.git","type":"git"},"_npmVersion":"6.14.4","description":"汉语拼音转换工具。","directories":{"test":"tests","example":"examples"},"_nodeVersion":"12.18.0","dependencies":{"commander":"~1.1.1","nodejieba":"^2.2.1","object-assign":"^4.0.1"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^8.3.2","eslint":"~0.24.0","request":"~2.68.0","istanbul":"~0.3.17","benchmark":"~1.0.0","expect.js":"~0.3.1"},"optionalDependencies":{"nodejieba":"^2.2.1"},"_npmOperationalInternal":{"tmp":"tmp/pinyin_2.10.0_1618142870736_0.4996968180648853","host":"s3://npm-registry-packages"},"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":1618142870927,"maintainers":[{"name":"hotoo","email":"hotoo.cn@gmail.com"}],"_cnpm_publish_time":1618142870927,"dist-tags":{"alpha":"4.0.0-alpha.3","latest":"4.0.0"}}