Skip to content

String

Default export StringUtils.

When to use

  • UI: ellipsisStr for middle‑ellipsis
  • Naming: toCamelCase for 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

Released under the ISC License.