Skip to content

字符串工具 (String)

@pt/utils/modules/string 提供了字符串处理相关的工具函数。

truncate

截断字符串。

typescript
import { truncate } from '@pt/utils/modules/string';

truncate('这是一段很长的文本', 6); // '这是一...'
truncate('Hello World', 8, '***'); // 'Hello***'

toCamelCase

转换为驼峰命名。

typescript
import { toCamelCase } from '@pt/utils/modules/string';

toCamelCase('hello-world'); // 'helloWorld'
toCamelCase('hello_world'); // 'helloWorld'

toPascalCase

转换为帕斯卡命名。

typescript
import { toPascalCase } from '@pt/utils/modules/string';

toPascalCase('hello-world'); // 'HelloWorld'
toPascalCase('hello_world'); // 'HelloWorld'

Released under the MIT License.