{"name":"pinyin","version":"3.0.0-alpha.2","keywords":["拼音","汉语","汉字","中文","Pinyin"],"author":{"name":"闲耘","email":"hotoo.cn@gmail.com"},"license":"MIT","_id":"pinyin@3.0.0-alpha.2","homepage":"https://pinyin.js.org/","bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"bin":{"pinyin":"bin/pinyin"},"dist":{"shasum":"868e8b24961886affdd37456b3945e22f49af886","tarball":"http://registry-npm.ywwl.com/pinyin/download/pinyin-3.0.0-alpha.2.tgz","fileCount":47,"integrity":"sha512-2xJDEUuGTGWTAZUdXr8QvFJwi7TKI9y0rF2jV/+FigTR5Yt0t5dbs0SDn7LKrnDpsAtMLi04YtknjrbDqP3hHg==","signatures":[{"sig":"MEUCIQDaaF2DkwG2jCXHj8tGld4Q00QDiCjXZKrWpqZebMVH4QIgXlxsFHGXhewj5eTxwHx5ZVgFqNxsQQRACvi8fN/C9TQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9171011,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiOT7WACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpQbA/+N132tgqiPBQDjCYlkKIXqJFRPEd7zWm+QOmJXtS4nSnqp36S\r\nBM0z6Cn1k6q0+43ZgDxdmupHFK9Fhj3pGWfx3jfAAk/1SyUgxka881M8j6vJ\r\nyOympB9j0+2+Tqz6s50Ynm94pGnNqJYyU4BLp9hfvz7jV/e84Q4niMqw7JPy\r\nNvRWRjoi7cviQPtmZzWDQQvLVKQ9OudLF4oAQes1N5CnZyCciWw/Os5//4AI\r\nGY/Zu6yx8vbi9S6x9PRYKPDDEoC6Kv6N/64lpetjC+hhkddETR9pwXGRWYHX\r\nXFOf+pu84528zxfBd9ghj/3q+cFvf3bqD4+znCNs91m1k/j0tiALkfVTizUG\r\nD5wvnx0y/IS6DQjq03EVdD9Qk+ur9NE9D14XtaZ5MAx9PUgfTc0rpnHRhd3c\r\nmzEd6T+K6VaSYK1xAYWS1vgLCgPozZFSfPaJBLTpNHy7mzQehx8vEe/vdPNj\r\neLVuomnvHBu4oTr0O4Rb9LRRrfLQ/0NWkDm1hx9hzL/yROe9IMFfYN1k7zGh\r\nAuPuQIXizn1Smm1Y8UZxKGPIR4Z+jjdrQw5XB8rlqgO3DqcE1CxMIk7za/gz\r\n3xy3NUXwSax79aS4Eqc/s+nJ35eyGeIMZIB2VIctZAl1CkXcTwrEQJmRm53w\r\nxk4j0idNvsbzu1aUXTis/Vh0E9QbMi8Hq0g=\r\n=q0u8\r\n-----END PGP SIGNATURE-----\r\n","size":983650,"noattachment":false,"key":"/pinyin/-/pinyin-3.0.0-alpha.2.tgz"},"main":"./lib/pinyin.js","types":"./lib/pinyin.d.ts","module":"./esm/pinyin.js","browser":{"./esm/pinyin.js":"./esm/pinyin-web.js","./lib/pinyin.js":"./lib/pinyin-web.js"},"gitHead":"ee4ae9e1b16e0aca86e0f83cf34c81c22af8c631","scripts":{"lint":"eslint ./src/ ./test/","test":"jest --coverage","build":"tsc --downlevelIteration -p tsconfig-es5.json & tsc --downlevelIteration -p tsconfig.json","debug":"npx ts-node tools/debug.ts","start":"dumi dev","doc:build":"rm -rf ./src/.umi && dumi build","doc:deploy":"npm run doc:build && cp CNAME docs-dist/dist && gh-pages -d docs-dist/dist","prepublishOnly":"npm run build"},"_npmUser":{"name":"hotoo","email":"hotoo.cn@gmail.com"},"registry":"https://registry.npmmirror.com","repository":{"url":"git+https://github.com/hotoo/pinyin.git","type":"git"},"_npmVersion":"8.3.1","description":"汉语拼音转换工具。","directories":{"test":"test","example":"examples"},"_nodeVersion":"16.14.0","dependencies":{"commander":"~1.1.1","nodejieba":"2.5.2","segmentit":"^2.0.3","@node-rs/jieba":"^1.6.0"},"_hasShrinkwrap":false,"readmeFilename":"README.en-US.md","devDependencies":{"npx":"^10.2.2","aurl":"^1.2.0","dumi":"^1.1.30","jest":"^27.2.3","nock":"^13.1.4","eslint":"^8.11.0","aws-sdk":"^2.1011.0","request":"~2.68.0","ts-node":"^10.5.0","gh-pages":"^3.2.3","prettier":"^2.6.0","benchmark":"~1.0.0","typescript":"^4.4.4","@types/jest":"^27.0.2","mock-aws-s3":"^4.0.2","react-json-view":"^1.21.3","@babel/preset-env":"^7.15.6","eslint-config-prettier":"^8.5.0","eslint-plugin-prettier":"^4.0.0","@babel/preset-typescript":"^7.15.0","@typescript-eslint/parser":"^5.14.0","@typescript-eslint/eslint-plugin":"^5.14.0","eslint-import-resolver-typescript":"^2.5.0"},"optionalDependencies":{"nodejieba":"2.5.2","segmentit":"^2.0.3","@node-rs/jieba":"^1.6.0"},"_npmOperationalInternal":{"tmp":"tmp/pinyin_3.0.0-alpha.2_1647918806138_0.4907642862533046","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":1647918806336,"maintainers":[{"name":"hotoo","email":"hotoo.cn@gmail.com"}],"_cnpm_publish_time":1647918806336,"dist-tags":{"alpha":"4.0.0-alpha.3","latest":"4.0.0"}}