New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

perls

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perls

A normative substitution tagged-template function (s// replacement for js).

latest
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

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.

Keywords

regexp

FAQs

Package last updated on 22 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts