@caiyb7923/cn-name-stroke-counter 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +28 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +26 -0
- package/package.json +29 -4
- package/README.md +0 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cnchar = require('cnchar');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取中文姓名的笔画数
|
|
7
|
+
* @param cnName {string}
|
|
8
|
+
*/
|
|
9
|
+
function countNameStroke(cnName) {
|
|
10
|
+
if (!cnName) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
// 存在非中文字符
|
|
14
|
+
if (!cnchar.isCnChar(cnName)) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
// 输入过短或过长,都认为不是标准的中文名字
|
|
18
|
+
if (cnName.length < 2 || cnName.length > 4) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const totalStrokes = cnchar.stroke(cnName, 'count');
|
|
22
|
+
if (typeof totalStrokes !== 'number') {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
return totalStrokes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.countNameStroke = countNameStroke;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsBtD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import cnchar from 'cnchar';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 获取中文姓名的笔画数
|
|
5
|
+
* @param cnName {string}
|
|
6
|
+
*/
|
|
7
|
+
function countNameStroke(cnName) {
|
|
8
|
+
if (!cnName) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
// 存在非中文字符
|
|
12
|
+
if (!cnchar.isCnChar(cnName)) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
// 输入过短或过长,都认为不是标准的中文名字
|
|
16
|
+
if (cnName.length < 2 || cnName.length > 4) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
const totalStrokes = cnchar.stroke(cnName, 'count');
|
|
20
|
+
if (typeof totalStrokes !== 'number') {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return totalStrokes;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { countNameStroke };
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caiyb7923/cn-name-stroke-counter",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "根据中文姓名计算笔画数的工具库",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rollup -c"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cn",
|
|
16
|
+
"chinese",
|
|
17
|
+
"name",
|
|
18
|
+
"stroke count"
|
|
19
|
+
],
|
|
20
|
+
"author": "Cai Yongbo",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rollup/plugin-typescript": "^12.3.1",
|
|
24
|
+
"rollup": "^4.68.9",
|
|
25
|
+
"tslib": "^2.9.1",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"cnchar": "^3.2.6"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/README.md
DELETED