Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
regex-cache
Advanced tools
Readme
Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of the same string and options, resulting in dramatic speed improvements.
Read what this does.
npm i regex-cache --save
When a regex is created using the new RegExp()
constructor and a function is returned, you can wrap the function like this:
var cache = require('regex-cache');
var someRegex = cache(require('some-regex-lib'));
If the code you're wrapping returns a regex (e.g. not a function), wrap it first so it returns a function to achieve the same results. (Note that after wrapping the function with regex-cache a regexp should be returned instead of a function).
DO use this when:
DO NOT use this when:
Performance results for a random regex lib, mentions-regex, with and without regex-cache, and no options passed:
with regex-cache x 11,256,663 ops/sec ±0.59% (97 runs sampled)
without regex-cache x 1,812,916 ops/sec ±1.66% (24 runs sampled)
If you're using new RegExp('foo')
instead of a regex literal, it's probably because you need to dyamically generate a regex based on user options or some other potentially changing factors.
regex-cache is a simple way to cache the results of a previous call to the RegExp constructor to avoid unnecessary runtime compilation when both the string and options being passed have not changed.
Using the RegExp constructor offers a lot of flexibility, but the runtime compilation comes at a price - it's slow. Not specifically because of the call to the RegExp constructor, but because you have to build up the string to create the regex based on various inputs.
Install dev dependencies:
npm i -d && npm test
Install dev dependencies:
npm i -d && npm run benchmarks
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on February 09, 2015.
FAQs
Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of the same string and options, resulting in surprising performance improvements.
We found that regex-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).