1.0.6 • Published 7 years ago

perls v1.0.6

Weekly downloads
3
License
X11
Repository
-
Last release
7 years ago

perl s(ubstitution)

A s///-alike search-and-replace/substitution tagged-template-string for JS.

Makes Search-and-replace regex, or substitutions, available in JS. Use handy perls`find this/replace with/g` to do text substiution.

var perls= require("perls")
var lukesDad= perls`vader/anakin/`("vader") //=> "anakin"
var threeCheers= perls`(:<cheer>(huzzah|cheers))/*$+{cheer}* *$+{cheer}* *$+{cheer}*/`("huzzah") //=> "*huzzah* *huzzah* *huzzah*"

Background

In JavaScript, RegExp.prototype.exec is used to get results out of regexp groups. If just trying to do some text substitution, that means writing a fairly gnarly string to concattenate together some output literal, from that exec output. This library exists to bring a more convenient means of doing text substitution to JavaScript.

In other non-JS environments, there's a s/find this/replace with this/ substitution one can run-

languageexample
perl$myFav =~ s/replace this/with this/
vim:s/replace this/with this/g 10000

Usage

  • Find and replace
perls`change this text/now a replacement/`("it's a good start. change this text.") //=> "it's a good stat. now a replacement"
  • Use a capture group
perls`find (\w+)/$1 once, $2 twice/`("find this") //=> "this once, this twice"
  • Use a named capture grou
perls`more (:<noun>)/$+{noun}! $+{noun}! $+{noun}`("more obama") //=> "obama! obama! obama!"

Run the substitution ./.examples or their ./.tests to see usage.

Install

Perls is distributed on npm.

Package

From inside the project you want to add perls to:

npm install --save perls

Dependencies

Shout to to these fabulous libraries for their assistance:

named-js-regexp to power named group matching.

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago