get-safe-reg

get safe regular-expression

Usage no npm install needed!

<script type="module">
  import getSafeReg from 'https://cdn.skypack.dev/get-safe-reg';
</script>

README

Get safe regular-expression

!!Important!! Wrose case on compress code with cache currying

  • Bad (Do not use it in compresss code)
import getSafeReg, {cacheReg} from 'get-safe-reg';

const cache={};

const getRegString = name => '(?:^|\\s+)'+ getSafeReg(name)+ '(?:\\s+|$)';

export default name => cacheReg(cache)(getRegString)(name);
  • Good
import getSafeReg, {cacheReg} from 'get-safe-reg';

const getRegString = name => '(?:^|\\s+)'+ getSafeReg(name)+ '(?:\\s+|$)';

const cache = cacheReg({})(getRegString)

export default name => cache(name);