String
Default export StringUtils.
When to use
- UI:
ellipsisStrfor middle‑ellipsis - Naming:
toCamelCasefor snake/kebab → camelCase - Random/color:
createRandomStr/randomHexColor - Basic ops:
reverseString/countOccurrences
Import
ts
import { StringUtils } from 'nex-lib'APIs
ts
StringUtils.randomHexColor() // '#a1b2c3'
StringUtils.toCamelCase('hello_world') // 'helloWorld'
StringUtils.toCamelCase('foo-bar') // 'fooBar'
StringUtils.reverseString('abc') // 'cba'
StringUtils.ellipsisStr('abcdefghijklmn', 6, 4) // 'abcdef...jklmn'
StringUtils.createRandomStr(8) // 随机字符串
StringUtils.countOccurrences('foofoo', 'foo') // 2