super-split

🔪 split string by delimiter array - delimiters retained

Usage no npm install needed!

<script type="module">
  import superSplit from 'https://cdn.skypack.dev/super-split';
</script>

README

Super-Split

🔪 split string by delimiter array - delimiters retained

Build Status Coverage Status NPM Version XO code style

Install

$ yarn add super-split

Usage

Split a string

const superSplit = require('super-split')

const str = 'A+B-C'
const delimiters = ['+', '-']
const result = superSplit(str, delimiters)

Result:

['A', '+', 'B', '-', 'C']

Split with ANSI

const str = 'I like to \u001b[34mmove it\u001b[39m, move it.'

const delimiters = ['\u001b[34m', '\u001b[39m']

const result = superSplit(str, delimiters)

Result:

['I like to ', '\u001b[34m', 'move it', '\u001b[39m', ', move it.']

Split Array

const ary = [':-)', 'o_O']

const delimiters = ['-', '_']

const result = superSplit(ary, delimiters)

Result:

[':', '-', ')', 'o', '_', 'O']