字符串工具 API
默认导出为 StringUtils。
使用指引(做什么、何时用)
- UI 显示:
ellipsisStr在长串中间省略,适合订单号/地址/密钥显示 - 命名转换:
toCamelCase将snake-case/kebab-case转为 camelCase - 随机/颜色:
createRandomStr/randomHexColor用于占位/测试/主题预览 - 基本处理:
reverseString/countOccurrences用于简单文本操作
导入
ts
import { StringUtils } from 'nex-lib';randomHexColor(): string
ts
StringUtils.randomHexColor(); // '#a1b2c3'toCamelCase(str: string): string
ts
StringUtils.toCamelCase('hello_world'); // 'helloWorld'
StringUtils.toCamelCase('foo-bar'); // 'fooBar'reverseString(str: string): string
ts
StringUtils.reverseString('abc'); // 'cba'ellipsisStr(str: string, start = 6, end = 4): string
ts
StringUtils.ellipsisStr('abcdefghijklmn', 6, 4); // 'abcdef...jklmn'createRandomStr(len = 6): string
ts
StringUtils.createRandomStr(8); // 随机字符串countOccurrences(str: string, word: string): number
ts
StringUtils.countOccurrences('foofoo', 'foo'); // 2