npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chinese-character

v1.0.3

Published

operate chinese string function first,sort,count,pin ...

Downloads

16

Readme

chinese-character

操作中文字符串

安装

npm install chinese-character

用法

var chinese = require('chinese-character');

//unicode 编码,类似 \u4e2d\u6587 的相互转换,
var str=chinese.string_to_unicode('中文');
console.log(str);
var str=chinese.unicode_to_string('\u4e2d\u6587');
console.log(str);


//unicode10 编码,类似 中文 的相互转换,
var str=chinese.string_to_unicode10('中文');
console.log(str); 
var str=chinese.unicode10_to_string('中文');
console.log(str); 


//unicode16 编码,类似 中文 的相互转换,
var str=chinese.string_to_unicode16('中文');
console.log(str); 
var str=chinese.unicode16_to_string('中文');
console.log(str); 


//html 编码,类似  '< >"& 的相互转换,
var str=chinese.html_encode('\'< >"&');
console.log(str); 
var str=chinese.html_decode('&apos;&lt;&nbsp;&gt;&quot;&amp;');
console.log(str); 


//字符串首字母
var str=chinese.first('國家对抗');
console.log(str); 
//返回 g


//字符串首字母连接
var str=chinese.firstAll('國家对抗');
console.log(str); 
//返回 gjdk


//字符串首字母数组
var str=chinese.firstAll('國家对抗',join=false);
console.log(str); 
//返回[ 'g', 'j', 'd', 'k' ]


//字符串首字母的拼音
var str=chinese.pin('國家对抗');
console.log(str); 
//返回guo


//字符串首字母的拼音连接
var str=chinese.pinAll('國家对抗');
console.log(str); 
//返回guojiaduikang


//字符串首字母的拼音数组
var str=chinese.pinAll('國家对抗',join=false);
console.log(str); 
//返回[ 'guo', 'jia', 'dui', 'kang' ]


//字符串首字母的声调拼音
var str=chinese.yin('國家对抗');
console.log(str); 
//返回guó


//字符串首字母的声调拼音连接
var str=chinese.yinAll('國家对抗');
console.log(str); 
//返回guójiāduìkàng


//字符串首字母的声调拼音数组
var str=chinese.yinAll('國家对抗',join=false);
console.log(str); 
//返回[ 'guó', 'jiā', 'duì', 'kàng' ]


//字符串首字母的声调
var str=chinese.diao('國家对抗');
console.log(str); 
//返回2


//字符串首字母的声调连接
var str=chinese.diaoAll('國家对抗');
console.log(str); 
//返回2144


//字符串首字母的声调数组
var str=chinese.diaoAll('國家对抗',join=false);
console.log(str); 
//返回[ 2, 1, 4, 4 ]


//字符串内中文字数,默认不含标点符号
var str=chinese.count('國家,对抗');
console.log(str); 
//返回4


//字符串内中文字数,含标点符号
var str=chinese.count('國家,对抗',punc=true);
console.log(str); 
//返回5


//数组内对象的中文属性排序
var str=chinese.firstSort([{'title':'世界'},{'title':'你好'},{'title':'时间'},{'title':'白天'},{'title':'宁静'},{'title':'闪电'}], 'title');
console.log(str); 
/*返回
[ { title: '白天' },
  { title: '你好' },
  { title: '宁静' },
  { title: '世界' },
  { title: '时间' },
  { title: '闪电' } ]
*/


//数组内中文排序
var str=chinese.firstSort(['世界','你好','时间','白天','宁静','闪电']);
console.log(str); 
//返回 [ '白天', '你好', '宁静', '世界', '时间', '闪电' ]


//数组内对象的中文属性排序后分组
var str=chinese.firstGroupSort([{'title':'世界'},{'title':'你好'},{'title':'时间'},{'title':'白天'},{'title':'宁静'},{'title':'闪电'}], 'title');
console.log(str); 
/* 返回
[ { first: 'b', data: [ [Object] ] },
  { first: 'n', data: [ [Object], [Object] ] },
  { first: 's', data: [ [Object], [Object], [Object] ] } ]
*/


//数组内中文排序后分组
var str=chinese.firstGroupSort(['世界','你好','时间','白天','宁静','闪电']);
console.log(str); 
/* 返回
[ { first: 'b', data: [ '白天' ] },
  { first: 'n', data: [ '你好', '宁静' ] },
  { first: 's', data: [ '世界', '时间', '闪电' ] } ]
*/