A simple utility to divide a string
or string[]
based on given indexes or delimiters.
pnpm install @nyaomaru/divider
import { divider } from '@nyaomaru/divider';
// Divide a string by index positions
const helloArray = divider('hello', 1, 3);
// ['h', 'el', 'lo']
const [hello1, hello2, ...restHello] = divider('hello', 1, 3, 4);
// hello1 = 'h'
// hello2 = 'el'
// restHello = ['l', 'o']
// Divide a string using a character separator
const divideWithString = divider('hello', 'e');
// ['h', 'llo']
const divideWithMultipleString = divider('hello', 'l');
// ['he', 'o']
// Divide an array of strings
const words = ['hello', 'world'];
const dividedWords = divider(words, 2);
// [['he', 'llo'], ['wo', 'rld']]
const dividedWordsWithFlattenOption = divider(words, 2, { flatten: true });
// ['he', 'llo', 'wo', 'rld']
- Supports both
index-based
andstring-based
division - Works with both
strings
andarrays of strings
- Optional
flattening
for array results
Welcome your contributions! If you want to add features or fix issues, feel free to submit a PR!
pnpm install
pnpm test
- If you add new functions, please add corresponding tests in the
tests
directory. - No strict rules—just keep it clean and readable!
- Thank you for your contribution. 😺