magic-string-rs
100% API compatible (port) MagicString by Rich-Harris implementation for Node and modern browsers, also, for rust, of course.
Installation
Rust
Add it as a dependency in a Cargo project.
# Cargo.toml
[dependency]
magic_string = "x.x.x"
Node
$ npm install @napi-rs/magic-string
Benchmark
Running "toString" suite...
Progress: 100%
MagicString:
226 614 ops/s, ±0.08% | slowest, 42.65% slower
MagicStringRust:
395 166 ops/s, ±1.83% | fastest
Finished 2 cases!
Fastest: MagicStringRust
Slowest: MagicString
Running "generateDecodedMap" suite...
Progress: 100%
MagicString:
173 590 ops/s, ±0.55% | slowest, 18.84% slower
MagicStringRust:
213 893 ops/s, ±0.75% | fastest
Finished 2 cases!
Fastest: MagicStringRust
Slowest: MagicString
Running "generateMap.toString" suite...
Progress: 100%
MagicString:
141 658 ops/s, ±0.53% | slowest, 31.48% slower
MagicStringRust:
206 744 ops/s, ±0.64% | fastest
Finished 2 cases!
Fastest: MagicStringRust
Slowest: MagicString
Supported APIs
- generateMap
- generateDecodedMap
- toString
- prepend
- append
- prependLeft
- prependRight
- appendLeft
- appendRight
- overwrite
- move
- locateOrigin
- locate
- insertLeft
- insertRight
- indent
- addSourcemapLocation
- clone
- remove
- slice
- snip
- trim
- trimStart
- trimEnd
- trimLines
- isEmpty
Credits
The original project magic-string is really awesome, you should check it out and we made this project even furthur for better performance.
License
MIT