
@vltpkg/fast-split
This is a very fast alternative to String.split(), which can be used
to quickly parse a small-to-medium sized string by a given delimiter.
It's fast · Usage
How Fast Is It!?
This is about 10% faster for splitting short strings by a short
delimiter. When we have to walk the resulting list for any reason, or
limit the number of items returned, it's an even bigger difference.
2024 M1 macbook pro, using node 20.11.0, v8 version 11.3.244.8-node.17
Counts are operations per ms, splitting the string '1.2.3-asdf+foo' by
the delimiter '.', transforms calling part.toUpperCase(), and limits
at 2 items
split 10385.779
fastSplit 10718.341
splitEmptyCheck 9563.721
fastSplitEmptyCheck 11273.537
splitTransformLoop 5722.724
splitTransformMap 6136.161
fastSplitTransform 6438.606
splitLimit 7076.179
fastSplitLimit 13257.948
Usage
import { fastSplit } from '@vltpkg/fast-split'
const str = getSomeStringSomehow()
const parts = fastSplit(str, '.')
const [first, second, rest] = fastSplit(str, '.', 3)
const nums = fastSplit(str, '.', -1, (part, parts, index) =>
Number(s),
)