@saihu/common 1.2.3 → 1.2.4

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.
@@ -1,2 +1,12 @@
1
+ /**
2
+ * 获取中文字符串的拼音首字母。
3
+ *
4
+ * - 保留 `-` 分隔符(每段独立取首字母后用 `-` 重新拼接)
5
+ * - 非中文字符被忽略
6
+ * - 特殊处理:`调-` → `条-`
7
+ *
8
+ * @example chnInitials('爱国') // 'ag'
9
+ * @example chnInitials('调-味品') // 'tw-wp'
10
+ */
1
11
  export declare function chnInitials(text: string): string;
2
12
  //# sourceMappingURL=chn-initials.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chn-initials.d.ts","sourceRoot":"","sources":["../../src/util/chn-initials.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUhD"}
1
+ {"version":3,"file":"chn-initials.d.ts","sourceRoot":"","sources":["../../src/util/chn-initials.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBhD"}
@@ -2,14 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chnInitials = chnInitials;
4
4
  const pinyin_pro_1 = require("pinyin-pro");
5
+ /**
6
+ * 获取中文字符串的拼音首字母。
7
+ *
8
+ * - 保留 `-` 分隔符(每段独立取首字母后用 `-` 重新拼接)
9
+ * - 非中文字符被忽略
10
+ * - 特殊处理:`调-` → `条-`
11
+ *
12
+ * @example chnInitials('爱国') // 'ag'
13
+ * @example chnInitials('调-味品') // 'tw-wp'
14
+ */
5
15
  function chnInitials(text) {
16
+ if (!text || typeof text !== 'string')
17
+ return '';
18
+ // 特殊处理"调-"到"条-"
19
+ text = text.replace(/调-/g, '条-');
6
20
  return text
7
- .split('')
8
- .map((char) => {
9
- if (/[\u4e00-\u9fa5]/.test(char)) {
10
- return (0, pinyin_pro_1.pinyin)(char, { pattern: 'initial' });
11
- }
12
- return char; // preserve symbols like '-' or spaces
13
- })
14
- .join('');
21
+ .split('-')
22
+ .map((part) => [...part]
23
+ .filter((c) => /[\u4e00-\u9fa5]/.test(c))
24
+ .map((c) => (0, pinyin_pro_1.pinyin)(c, { pattern: 'first' }))
25
+ .join(''))
26
+ .filter((s) => s.length > 0)
27
+ .join('-');
15
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",