{"_id":"@dwscdv3/pinyin","name":"@dwscdv3/pinyin","dist-tags":{"latest":"3.0.0-alpha.6"},"versions":{"3.0.0-alpha.6":{"name":"@dwscdv3/pinyin","version":"3.0.0-alpha.6","description":"汉语拼音转换工具。","main":"./lib/pinyin.js","module":"./esm/pinyin.js","browser":{"./lib/pinyin.js":"./lib/pinyin-web.js","./esm/pinyin.js":"./esm/pinyin-web.js"},"bin":{"pinyin":"bin/pinyin"},"homepage":"https://pinyin.js.org/","author":{"name":"神楽坂静瑶","email":"dwscdv3@hotmail.com"},"repository":{"type":"git","url":"git+https://github.com/hotoo/pinyin.git"},"bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"scripts":{"start":"dumi dev","prepublishOnly":"npm run build","build":"tsc --downlevelIteration -p tsconfig-es5.json & tsc --downlevelIteration -p tsconfig.json","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","lint":"eslint ./src/ ./test/","test":"jest --coverage","debug":"npx ts-node tools/debug.ts"},"dependencies":{"commander":"~1.1.1","@node-rs/jieba":"^1.6.0","segmentit":"^2.0.3"},"optionalDependencies":{"segmentit":"^2.0.3"},"devDependencies":{"@babel/preset-env":"^7.15.6","@babel/preset-typescript":"^7.15.0","@types/jest":"^27.0.2","@typescript-eslint/eslint-plugin":"^5.14.0","@typescript-eslint/parser":"^5.14.0","aurl":"^1.2.0","aws-sdk":"^2.1011.0","benchmark":"~1.0.0","dumi":"^1.1.30","eslint":"^8.11.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"^2.5.0","eslint-plugin-prettier":"^4.0.0","gh-pages":"^3.2.3","jest":"^27.2.3","mock-aws-s3":"^4.0.2","nock":"^13.1.4","npx":"^10.2.2","prettier":"^2.6.0","react-json-view":"^1.21.3","request":"~2.68.0","ts-node":"^10.5.0","typescript":"^4.4.4"},"registry":"https://registry.npmmirror.com","publishConfig":{"registry":"https://registry.npmjs.org/"},"keywords":["拼音","汉语","汉字","中文","Pinyin"],"directories":{"example":"examples","test":"test"},"license":"MIT","gitHead":"1265a25582905222c185d08f9904ad0b49cc32d0","_id":"@dwscdv3/pinyin@3.0.0-alpha.6","_nodeVersion":"14.21.1","_npmVersion":"6.14.17","dist":{"integrity":"sha512-Lbh6JiMv46kkOt2DTMVPXmCK98817yVSs7Mb25HT2O1tqCr93EdcXBEK1bp2lWCuMyDiRJO/GnoXlgBin7yQcw==","shasum":"33582b6711ee76e88c4deab4037ac85c96901fad","tarball":"https://registry.npmjs.org/@dwscdv3/pinyin/-/pinyin-3.0.0-alpha.6.tgz","fileCount":91,"unpackedSize":18497763,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+SmZKSXIWsbTePYYzbdN3YRslwi8gPoFaDY5AAj4FQQIhAKa5gyikXHYVViLiOQfB2n788xcGgksDz20z2Nt8fDDk"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjkVEHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrKVA/5AeIrgQEEpwgciHn0SWReb7qnQMPH6WL5RQFklclSWLD84Abk\r\nhX5Dekt1xFWejDT+uplGU1sxeGOxpPLmoMJsdo+hRSCjFdappxUiu2XJ4WWv\r\nZjHAsOKnJO9EA3SO3dzYD0ABuuGllN300h++Jx81OWTaWDKhYDDY430vEGyd\r\n+wmq1UNwh3yWPsptOZWY8K3id1BFcjhEOdHmt9zJVb0em2SMwmeT7aFkyQi4\r\nlkZvKPtYmmRdFMn/XVTCeDcsoOwZVP80OlfHfhgEFGRN2MZYmCYvzPSEXr+E\r\nSvjZgT3tdrNlJpNv7RCEE/d9Mg0Fr5t1mgH0oLNpQioDTJSAHcnVcquEPYQ4\r\nFSiqp3+pgf+YBHLdJFbQUV6UAErAaO8FYt7OopYc7kIIQfXmdDRojBXbeVlA\r\nBbTcYRQ96imfe8LZIBkjbYXRY3we0aJJqUaZ7636BPfVQW/c0RxCidu44vrR\r\ngDX07IehM8dfRVALi08p9gyFV8Gsi1Q+wcgcqRdie7/1olQ/mHnnQ1ja+d2E\r\ng/MHItBRq1y2RLg3Gzu8/tGwfDy5kU81dG02QKq5WLZZTTkDAZjnBuMDFdNA\r\nqgcs3Y2iwDeCczckzC3991rZUDj1y0OAeJ5So5H3pKPdHX6R6utCnxpk8ZN9\r\nddm0OVUuQKl9KIIqcE1Icxx7RD3SkfGFeLw=\r\n=YNyX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"dwscdv3","email":"dwscdv3@hotmail.com"},"maintainers":[{"name":"dwscdv3","email":"dwscdv3@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pinyin_3.0.0-alpha.6_1670467847553_0.5939535175974593"},"_hasShrinkwrap":false}},"time":{"created":"2022-12-08T02:50:47.485Z","3.0.0-alpha.6":"2022-12-08T02:50:47.802Z","modified":"2022-12-08T02:50:47.972Z"},"maintainers":[{"name":"dwscdv3","email":"dwscdv3@hotmail.com"}],"description":"汉语拼音转换工具。","homepage":"https://pinyin.js.org/","keywords":["拼音","汉语","汉字","中文","Pinyin"],"repository":{"type":"git","url":"git+https://github.com/hotoo/pinyin.git"},"author":{"name":"神楽坂静瑶","email":"dwscdv3@hotmail.com"},"bugs":{"url":"https://github.com/hotoo/pinyin/issues"},"license":"MIT","readme":"# pīnyīn (v3)\r\n\r\npinyin, The convert tool of chinese pinyin.\r\n\r\n---\r\n\r\n[![NPM version][npm-badge]][npm-url]\r\n[![Build Status][build-badge]][build-url]\r\n[![Coverage Status][coveralls-badge]][coveralls-url]\r\n[![Language Grade: JavaScript][lgtm-badge]][lgtm-url]\r\n[![NPM downloads][npm-downloads]][npm-url]\r\n\r\n\r\n[npm-badge]: https://img.shields.io/npm/v/pinyin.svg?style=flat\r\n[npm-url]: https://www.npmjs.com/package/pinyin\r\n[npm-downloads]: http://img.shields.io/npm/dm/pinyin.svg?style=flat\r\n[build-badge]: https://github.com/hotoo/pinyin/actions/workflows/node.js.yml/badge.svg\r\n[build-url]: https://github.com/hotoo/pinyin/actions\r\n[coveralls-badge]: https://coveralls.io/repos/hotoo/pinyin/badge.svg?branch=master\r\n[coveralls-url]: https://coveralls.io/r/hotoo/pinyin\r\n[lgtm-badge]: https://img.shields.io/lgtm/grade/javascript/g/hotoo/pinyin.svg?logo=lgtm&logoWidth=18\r\n[lgtm-url]: https://lgtm.com/projects/g/hotoo/pinyin/context:javascript\r\n\r\n\r\nWeb Site: [简体中文](/) | English\r\n\r\nREADME: [简体中文](README.md) | English\r\n\r\n\r\nConvert Han to pinyin. useful for phonetic notation, sorting, and searching.\r\n\r\n> Note: This module both support Node and Web browser.\r\n>\r\n> Python version see [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin)\r\n\r\n---\r\n\r\n## Feature\r\n\r\n* Segmentation for heteronym words.\r\n* Support Traditional and Simplified Chinese.\r\n* Support multiple pinyin style.\r\n\r\n## Install\r\n\r\nvia npm:\r\n\r\n```bash\r\nnpm install pinyin@alpha --save\r\n```\r\n\r\n## Usage\r\n\r\nfor developer:\r\n\r\n```typescript\r\nimport pinyin from \"pinyin\";\r\n\r\nconsole.log(pinyin(\"中心\"));    // [ [ 'zhōng' ], [ 'xīn' ] ]\r\n\r\nconsole.log(pinyin(\"中心\", {\r\n  heteronym: true                // Enable heteronym mode.\r\n}));                            // [ [ 'zhōng', 'zhòng' ], [ 'xīn' ] ]\r\n\r\nconsole.log(pinyin(\"中心\", {\r\n  heteronym: true,              // Enable heteronym mode.\r\n  segment: true                 // Enable Chinese words segmentation, fix most heteronym problem.\r\n}));                            // [ [ 'zhōng' ], [ 'xīn' ] ]\r\n\r\nconsole.log(pinyin(\"我喜欢你\", {\r\n  segment: true,                // Enable segmentation. Needed for grouping.\r\n  group: true                   // Group pinyin segments\r\n}));                            // [ [ 'wǒ' ], [ 'xǐhuān' ], [ 'nǐ' ] ]\r\n\r\nconsole.log(pinyin(\"中心\", {\r\n  style: pinyin.STYLE_INITIALS, // Setting pinyin style.\r\n  heteronym: true\r\n}));                            // [ [ 'zh' ], [ 'x' ] ]\r\n\r\nconsole.log(pinyin(\"华夫人\", {\r\n  mode: \"surname\",              // 姓名模式。\r\n}));                            // [ ['huà'], ['fū'], ['rén'] ]\r\n```\r\n\r\nfor cli:\r\n\r\n```bash\r\n$ pinyin 中心\r\nzhōng xīn\r\n$ pinyin -h\r\n```\r\n\r\n## Types\r\n\r\n### IPinyinOptions\r\n\r\nThe types for the second argument of pinyin method.\r\n\r\n```typescript\r\nexport interface IPinyinOptions {\r\n  style?: IPinyinStyle; // output style of pinyin.\r\n  mode?: IPinyinMode, // mode of pinyin.\r\n  segment?: IPinyinSegment | boolean;\r\n  heteronym?: boolean;\r\n  group?: boolean;\r\n  compact?: boolean;\r\n}\r\n```\r\n\r\n### IPinyinStyle\r\n\r\nThe output style of pinyin.\r\n\r\n```typescript\r\nexport type IPinyinStyle =\r\n  \"normal\" | \"tone\" | \"tone2\" | \"to3ne\" | \"initials\" | \"first_letter\" | // Suggest.\r\n  \"NORMAL\" | \"TONE\" | \"TONE2\" | \"TO3NE\" | \"INITIALS\" | \"FIRST_LETTER\" |\r\n  0        | 1      | 2       | 5       | 3          | 4;               // compatibility.\r\n```\r\n\r\n### IPinyinMode\r\n\r\nThe mode of pinyin.\r\n\r\n```typescript\r\n// - NORMAL: Default mode is normal mode.\r\n// - SURNAME: surname mode, for chinese surname.\r\nexport type IPinyinMode =\r\n  \"normal\" | \"surname\" |\r\n  \"NORMAL\" | \"SURNAME\";\r\n```\r\n\r\n### IPinyinSegment\r\n\r\nThe segment method.\r\n\r\n- Default is disable segment: `false`，\r\n- If set `true`, use \"segmentit\" module for segment in Web, use \"@node-rs/jieba\" for segment in Node.\r\n- Also specify follow string for segment (bug just \"segmentit\" in web):\r\n\r\n```typescript\r\nexport type IPinyinSegment = \"segmentit\" | \"@node-rs/jieba\";\r\n```\r\n\r\n\r\n## API\r\n\r\n### `<Array> pinyin(words[, options])`\r\n\r\nConvert Han （汉字） to pinyin.\r\n\r\n`options` argument is optional, for sepcify heteronym mode and pinyin styles.\r\n\r\nReturn a `Array<Array<String>>`. If one of Han is heteronym word, it would be\r\nhave multiple pinyin.\r\n\r\n### `Number pinyin.compare(a, b)`\r\n\r\nDefault compare implementation for pinyin.\r\n\r\n\r\n## Options\r\n\r\n#### `<Boolean> options.segment`\r\n\r\nEnable Chinese word segmentation. Segmentation is helpful for fix heteronym\r\nproblem, but performance will be more slow, and need more CPU and memory.\r\n\r\nDefault is `false`.\r\n\r\n### `<Boolean> options.heteronym`\r\n\r\nEnable or disable heteronym mode. default is disabled, `false`.\r\n\r\n### `<Boolean> options.group`\r\n\r\nGroup pinyin by phrases. for example:\r\n\r\n```\r\n我喜欢你\r\nwǒ xǐhuān nǐ\r\n```\r\n\r\n### `<Object> options.style`\r\n\r\nSpecify pinyin style. please use static properties like `STYLE_*`.\r\ndefault is `.STYLE_TONE`. see Static Property for more.\r\n\r\n### `options.mode`\r\n\r\npinyin mode, default is `pinyin.MODE_NORMAL`. If you cleared in surname scene,\r\nuse `pinyin.MODE_SURNAME` maybe better.\r\n\r\n## Static Property\r\n\r\n### `.STYLE_NORMAL`\r\n\r\nNormal mode.\r\n\r\nExample: `pin yin`\r\n\r\n### `.STYLE_TONE`\r\n\r\nTone style, this is default.\r\n\r\nExample: `pīn yīn`\r\n\r\n### `.STYLE_TONE2`\r\n\r\ntone style by postfix number [0-4].\r\n\r\nExample: `pin1 yin1`\r\n\r\n### `.STYLE_TO3NE`\r\n\r\ntone style by number [0-4] after phonetic notation character.\r\n\r\nExample: `pin1 yin1`\r\n\r\n### `.STYLE_INITIALS`\r\n\r\nInitial consonant (of a Chinese syllable).\r\n\r\nExample: pinyin of `中国` is `zh g`\r\n\r\nNote: when a Han （汉字） without initial consonant, will convert to empty string.\r\n\r\n### `.STYLE_FIRST_LETTER`\r\n\r\nFirst letter style.\r\n\r\nExample: `p y`\r\n\r\n### `pinyin.MODE_NORMAL`\r\n\r\nNormal mode. This is the default mode.\r\n\r\n### `pinyin.MODE_SURNAME`\r\n\r\nSurname mode. If chinese word is surname, The pinyin of surname is prioritized.\r\n\r\n## Test\r\n\r\n```\r\nnpm test\r\n```\r\n\r\n## Q&A\r\n\r\n### What's the different Node version and Web version?\r\n\r\n`pinyin` support Node and Web browser now, the API and usage is complete same.\r\n\r\nBut the Web version is simple than Node version. Just frequently-used dict,\r\nwithout segmentation, and the dict is compress for web.\r\n\r\nBecause of Traditional and Segmentation, the convert result will be not complete same.\r\nand the test case have some different too.\r\n\r\n| Feature      | Web version                     | Node version                     |\r\n|--------------|---------------------------------|----------------------------------|\r\n| Dict         | Frequently-used Dict, Compress. | Complete Dict, without Compress. |\r\n| Segmentation | NO                              | Segmentation options.            |\r\n| Traditional  | NO                              | Full Traditional support.        |\r\n\r\n\r\n### How to sort by pinyin?\r\n\r\nThis module provide default compare implementation:\r\n\r\n```js\r\nconst pinyin = require('pinyin');\r\n\r\nconst data = '我要排序'.split('');\r\nconst sortedData = data.sort(pinyin.compare);\r\n```\r\n\r\nBut if you need different implementation, do it like:\r\n\r\n```\r\nconst pinyin = require('pinyin');\r\n\r\nconst data = '我要排序'.split('');\r\n\r\n// Suggest you to store pinyin result by data persistence.\r\nconst pinyinData = data.map(han => ({\r\n  han: han,\r\n  pinyin: pinyin(han)[0][0], // Choose you options and styles.\r\n}));\r\nconst sortedData = pinyinData.sort((a, b) => {\r\n  return a.pinyin.localeCompare(b.pinyin);\r\n}).map(d => d.han);\r\n```\r\n\r\n## Donate\r\n\r\nIf this module is helpful for you, please Star this repository.\r\n\r\nAnd you have chioce donate to me via Aliapy or WeChat:\r\n\r\n<img src=\"https://hotoo.github.io/images/donate-hotoo.png\" alt=\"Alipay:hotoo.cn@gmail.com, WeChat:hotoome\" width=\"400\" />\r\n\r\n\r\n## License\r\n\r\n[MIT](http://hotoo.mit-license.org/)\r\n","readmeFilename":"README.en-US.md"}