rollup-string-performance
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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 -D

Usage

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 ignore

you cant rewirte to:

const fn = (str: string) => str

const str = 'hello world'

const perfix = fn('he')
str.startsWith(perfix) // will work

Package Sidebar

Install

npm i rollup-string-performance

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

6.31 kB

Total Files

5

Last publish

Collaborators

  • plumbiu