JSPM

interpolate-regex

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q46457F
  • License CC0-1.0

Useful for basic templating by interpolating values into placeholders. Takes a left and right delimiter and returns a regex object for matching them and capturing the contents.

Package Exports

  • interpolate-regex

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (interpolate-regex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

interpolate-regex

Useful for basic templating by interpolating values into placeholders. Takes a left and right delimiter and returns a regex object for matching them and capturing the contents.

install

npm install interpolate-regex

example

const Regex = require('interpolate-regex')

const data = {place: 'world'}
'Hello, {{place}}'.replace(Regex('{{', '}}'), (_, contents) => {
  console.log(contents) // -> 'place'
  return data[contents] // -> 'world'
}) // -> 'Hello, world'

API

Regex(left, right, matchEmpty)

  • left: string left delimiter
  • right: string right delimiter
  • matchEmpty: boolean, true match when there is nothing in between delimiters