cut-string

v1.0.3
Cut a string if too long. Support CJK(漢字) and emoji❤️.
string truncate ellipsis

cut-string

Cut a string if too long. Support CJK and emoji❤️.

Install

$ npm install cut-string

Usage

const cutString = require('cut-string')

cutString('ABCDEFG', 4)
//=> 'ABCD'

cutString('我在东北玩泥巴', 4)
//=> '我在'

cutString('👨‍👩‍👧😀❣️😸', 6)
//=> '👨‍👩‍👧😀❣️'

cutString('我在东北玩泥巴', 6, { ellipsis: true })
//=> '我在...'

cutString('👨‍👩‍👧😀❣️😸', 6, { emojiWidth: 3 })
//=> '👨‍👩‍👧😀'
npm i cut-string

Metadata

  • MIT
  • Whatever
  • starkwang
  • released 8/23/2018

Downloads

Maintainers