{"id":19030497,"url":"https://github.com/sofish/han","last_synced_at":"2025-04-07T14:12:07.762Z","repository":{"id":4919465,"uuid":"6075884","full_name":"sofish/han","owner":"sofish","description":"a module for tanslating Chinese(汉字) into /\\w+/ or pinyin","archived":false,"fork":false,"pushed_at":"2018-04-21T11:24:30.000Z","size":431,"stargazers_count":200,"open_issues_count":3,"forks_count":34,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-31T13:16:14.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mllrsohn/gulp-protractor","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sofish.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-04T13:43:39.000Z","updated_at":"2023-05-11T12:27:30.000Z","dependencies_parsed_at":"2022-08-25T05:01:58.477Z","dependency_job_id":null,"html_url":"https://github.com/sofish/han","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofish%2Fhan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofish%2Fhan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofish%2Fhan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofish%2Fhan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sofish","download_url":"https://codeload.github.com/sofish/han/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666014,"owners_count":20975788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T21:18:13.590Z","updated_at":"2025-04-07T14:12:07.736Z","avatar_url":"https://github.com/sofish.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Han(汉)\n\n[![Build Status](https://travis-ci.org/sofish/han.png)](https://travis-ci.org/sofish/han)\n[![Coverage Status](https://coveralls.io/repos/sofish/han/badge.png)](https://coveralls.io/r/sofish/han)\n\na module for tanslating Chinese(汉字) into pinyin.\n\n## Installation\n\n```bash\n$ npm install han\n```\n\n## Usage\n\n### 1. han.letter()\n\n```js\nhan.letter(chinese ,[separator ,[callback(err, data)])\n```\nUse the `letter` method to translate Chinese in to english letter:\n\n```js\nvar han = require('han');\n\nhan.letter('中文') // zhongwen\nhan.letter('中文', '-') // zhong-wen\nhan.letter('中文', function(err, result){\n  console.log(result) // zhongwen\n})\n```\n\nThe `letter` method has 3 params by default, they can all be _**optional**_, it depends on you(^^). follow the message below, you can also find it at [lib/translate.js](https://github.com/sofish/han/blob/master/lib/translate.js):\n\n```js\n/* @param `chinese` {String} Chinese word\n * @param [optional] `separator` {String} separator for the letters\n * @param [optional] `callback(err, result)` {Function} if a callback is specified,\n *   the program will use an async way to do the translation \n */\n```\n\n### 2. han.pinyin(chinese)\n\nUser the `pinyin` method to translate Chinese into Pinyin(letters with notation):\n\n```js\nhan.pinyin('中文') // [ [ 'zhōng', 'zhòng' ], [ 'wén', 'wèn' ] ]\n\n// mixin are allowed, like:\nhan.pinyin('My Chinese name is 小鱼(sofish)');\n// [ 'My Chinese name is ', [ 'xǐao' ], [ 'yú' ], '(sofish)' ]\n\n// also running with messy code, see the testcase below\n```\n\n#### __WHY__ the return value is an array?\n\nBeause that a Chinese word always having more than one pronunciation. You may want to allow users to correct your output that is generated by your program in an automatic way(like google?! yep!).\n\n## Testcase\n\n```sh\n$ npm install han\n# or git clone git://github.com/sofish/han.git\n\n$ cd node_modules/han \u0026\u0026 make test\n```\n\n## Translating Messy Code\n\nMessy code? orginal file is here [testcase.js](https://github.com/sofish/han/blob/master/testcase.js):\n```js\nvar han = require('han');\n\nconsole.log('orginal：要实现 Speaker Deck 那种中文转拼音的')\nconsole.log(han.letter('要实现 Speaker Deck 那种中文转拼音的', '-'), '\\n')\n// orginal：要实现 Speaker Deck 那种中文转拼音的\n// yao-shi-xian-speaker-deck-na-zhong-zhong-wen-zhuan-pin-yin-de\n\nhan.letter('中aaaaa中¢∞§¶•誩aa文喳aa', function(err, result){\n  if(err) throw err;\n  console.log('orginal：中aaaaa中¢∞§¶•誩aa文喳aa')\n  console.log('callback：' + result, '\\n')\n  // orginal：中aaaaa中¢∞§¶•誩aa文喳aa\n  // callback：zhong aaaaa 4e2da2 221ea7b6 2022 jing aa wen zha aa\n});\n\nhan.letter('中EnglishWords¢∞§¶•ªº文', '-', function(err, result){\n  console.log('orginal：中EnglishWords¢∞§¶•ªº文')\n  console.log('callback：' + result)\n  // original：中EnglishWords¢∞§¶•ªº文\n  // callback：zhong-englishwords-221ea7b6-2022aaba-wen\n});\n\n\nconsole.log('original: My Chinese name is 小鱼(sofish)')\nconsole.log(han.pinyin('My Chinese name is 小鱼(sofish)'))\n// original: My Chinese name is 小鱼(sofish)\n// [ 'My Chinese name is ', [ 'xǐao' ], [ 'yú' ], '(sofish)' ]\n\nconsole.log('original: #$%^\u0026*中23¢∞§¶•ª52849文@#$%^\u0026*(意思，还有英文：english')\nconsole.log(han.pinyin('#$%^\u0026*中23¢∞§¶•ª52849文@#$%^\u0026*(意思，还有英文：english'))\n// original: #$%^\u0026*中23¢∞§¶•ª52849文@#$%^\u0026*(意思，还有英文：english\n// [ '#$%^\u0026*', [ 'zhōng', 'zhòng' ], '23¢∞§¶•ª52849', [ 'wén', 'wèn' ],\n//  '@#$%^\u0026*(', [ 'yì' ], [ 'sī', 'sì', 'sāi' ], '，', [ 'húan', 'hái', 'xúan' ],\n//  [ 'yǒu', 'yòu' ], [ 'yīng', 'yāng' ], [ 'wén', 'wèn' ], '：english' ]\n```\n\n## License\n\nLicensed under [MIT](https://github.com/sofish/han/blob/master/LICENSE).\n\n\n## Contributers:\n\nSpecail thank to [fayland](https://github.com/fayland/perl-lingua-han/tree/master/Lingua-Han-PinYin/lib/Lingua/Han/PinYin) for providing the unicode table of Chinese.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsofish%2Fhan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsofish%2Fhan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsofish%2Fhan/lists"}