regexp-map

Curried function which takes a map of `RegExp` string keys which when successfully matched given string, resolves to mapped value.

Usage no npm install needed!

<script type="module">
  import regexpMap from 'https://cdn.skypack.dev/regexp-map';
</script>

README

regexp-map

Curried function which takes a map of RegExp string keys which when successfully matched given string, resolves to mapped value.

Build Status Code Climate js-standard-style

npm install regexp-map --save

You can also use Duo, Bower or download the files manually.

npm stats

npm NPM downloads David

API Example

var remap = require('regexp-map')
var makes = remap({
  '^toyota': 'Toyota',
  '^ford': 'Ford',
  '^dodge': 'Dodge'
})

makes('Toyota RAV4')
//=> 'Toyota'

API

remap(map, str)

arguments
  • map (Object.<string, string>) Map of RegExp strings which when matched against string successfully, resolves to mapped value.
  • str (String) String to search.
returns
  • (String) When matched returns corresponding mapped value; otherwise, an empty string.

Contributing

SEE: contributing.md

Licenses

GitHub license