0.0.2 • Published 2 years ago
rollup-string-performance v0.0.2
rollup-string-performance
transfrom startsWith and endsWith to one char compare.
const str = 'hello world'
str.startsWith('he')
str.endssWith('ld')will transfrom:
const str = 'hello world'
(str[0] === 'h' && str[1] === 'e')
(str[str.length - 2] === 'l' && str[str.length - 1] === 'e')Install
npm i rollup-string-performance -DUsage
In rollup.config.js:
import { stringOptimize } from 'rollup-string-performance'
export default {
// ...
plugin: [stringOptimize()],
}Note
String that include '\\' will ignore, like \t, \n.
Only Literal or Identifier arguments node can be regonized, other node will be ignored, like:
const fn = (str: string) => str
const str = 'hello world'
str.startsWith(fn('he')) // will ignoreyou cant rewirte to:
const fn = (str: string) => str
const str = 'hello world'
const perfix = fn('he')
str.startsWith(perfix) // will work