{"name":"pinyin","version":"2.10.2","keywords":["拼音","汉语","汉字","中文","Pinyin"],"author":{"name":"闲耘","email":"hotoo.cn@gmail.com"},"license":"MIT","_id":"pinyin@2.10.2","homepage":"http://pinyin.hotoo.me/","bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"bin":{"pinyin":"bin/pinyin"},"dist":{"shasum":"93e3b3cb4430009925163bad10c741778c85b013","tarball":"http://registry-npm.ywwl.com/pinyin/download/pinyin-2.10.2.tgz","fileCount":14,"integrity":"sha512-qAcp7+2vnjm6sAd0B9pp5JpyvHbYoQO1v9zCeJQMEgyw2VeRi02l0gR22ZBgfjjvZ1c2EGoVjJHJ1h0rwr34Ug==","signatures":[{"sig":"MEUCIQDAJ8X2yFF5Ce7IxkrSZCeoQKmvhRgqyY921SytbyhPlQIgdMx7UDgKUTV+s+I26QgH+guN3MbmmtohZduhEYKhwZM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3821340,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgcxIDCRA9TVsSAnZWagAACbMP/2Hjg6dgiiDmZRNU6oD6\nN2khw0BrMn90LkW4ez9oFvdO3xncHZKN8b2/q4tQa4SqwBPw4wIHcoBPyGuI\n1XAL4bHE6ar92f5VmVLTFZ/1WPO7RUi9xGXvEcVEDeXoVH5T+jMiINIS1oRM\neRTeMe7PV+iuLW/ndhLBW5iDbhRSmWtFeSycjGL49z1zAntQFlEoz5f2dvap\nxBH2Rl3o2UuB0DutJqNFlA1Dlsv+d9UP3ex1lQJZFYv7658ORwgFRsxeku21\naWcoArsNgGqq4dsxSZSYE8n/cqacZOcSKEFU1340MvZyTIuodxO333oRFZ9/\nxsKrxNisheFJS1pejuf/kGP3Q6NT9YksaaB8ovHFUSJa8ZK36VIJgYRYQiMv\nuHiWt9PI2HpRx+vcKBsR9aMolikJnuCcLhd0ywbxJ9eZ1h7vupPtykjA2+Fc\nud8s8wq85+6c2im7G2Sm3icG+qo7D3KDq9kMyt68BBv8cnEro5Q8jlLX6zvC\n5p8FHOiqLQ8Gzl5YmckLFgWsSvoCGx8qrX2wjJVpJenu/7xooYCaSFbyqSGq\nyuQlZFFPg7a8Ra4RpOPtW8Kb/7gTR6qnQwDVwoFHk9iE7Ohg4kuzYShsHIjW\noCCjJAfXavR282lktfup8oCjKtdkpBXc8Uklb+TtJnJHa062tBrbNWUdhb9v\n2Qd8\r\n=oGNe\r\n-----END PGP SIGNATURE-----\r\n","size":1082054,"noattachment":false,"key":"/pinyin/-/pinyin-2.10.2.tgz"},"main":"lib/index.js","browser":"lib/web-pinyin.js","gitHead":"320e4a79d6e9db998d6d4b2196dd6e5ec2f4faa5","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.2_1618153986457_0.8935150353305916","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":1618153986807,"maintainers":[{"name":"hotoo","email":"hotoo.cn@gmail.com"}],"_cnpm_publish_time":1618153986807,"dist-tags":{"alpha":"4.0.0-alpha.3","latest":"4.0.0"}}