@glennsl/bs-revamp

0.2.0 • Public • Published

bs-re:vamp

An experimental safe and functional API for JavaScript regexes

npm Travis Coveralls Dependencies Issues Last Commit Size

Example

/*
 * Dasherize camelCased identifiers inside string literals
 */

let code = {|
  let borderLeftColor = "borderLeftColor";
  let borderRightColor = "borderRightColor";
|};

code |> Revamp.replace({|"([^"]+)"|},                /* Matches the content of string literals */
          Revamp.replace("[A-Z]", letter =>          /* Matches uppercase letters */
            "-" ++ letter |> Js.String.toLowerCase)) /* Convert to lower case and prefix with a dash */
     |> Js.log;

/* Outputs:

  let borderLeftColor = "border-left-color";
  let borderRightColor = "border-right-color";
*/

Installation

npm install --save @glennsl/bs-revamp

Then add @glennsl/bs-revamp to bs-dependencies in your bsconfig.json:

{
  ...
  "bs-dependencies": ["@glennsl/bs-revamp"]
}

Goals

  • A sane, safe API
  • Low performance overhead (secondary)

Non-goals

  • Full feature parity

Documentation

For the moment, please see the interface file, Revamp.rei.

Changes

0.2.0

  • [BREAKING] Removed Match.matches, deprecated in 0.1.0, due to being unsound

0.1.0

  • Changed type of captures from Sequence.t(array(string)) to Sequence.t(list(option(string))) because the former was unsound.
  • Added Match.match and Match.captures
  • Deprecated Match.matches due to being unsound

Package Sidebar

Install

npm i @glennsl/bs-revamp

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • glennsl