JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1402
  • Score
    100M100P100Q98938F

A find and replace utility. Modify strings by passing an array of RegExp or string replacement patterns

Package Exports

  • frep

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 (frep) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

frep NPM version

A find and replace utility. Modify strings by passing an array of RegExp or string replacement patterns

Quickstart

npm i frep --save
var frep = require('frep');

frep.replaceStr(String, ArrayOfPatterns));
frep.replaceArray(ArrayOfStrings, ArrayOfPatterns));

Methods

replaceStr

replaceStr(String, Array)

Parameters:

  • String: The string to modify with the given replacement patterns.
  • Array: Array of objects containing the replacement patterns, each including a pattern property (which can be a string or a RegExp), and a replacement property (which can be a string or a function to be called for each match).

Given the following:

var frep = require('frep');

var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
var patterns = [
  {
    pattern: /(A|B|C)/g,
    replacement: '###'
  },
  {
    pattern: /(X|Y|Z)/g,
    replacement: '$$$'
  },
  ...
];

frep.replaceStr(str, patterns));

A new string is returned with some or all matches replaced by the given replacement strings.

#########DEFGHIJKLMNOPQRSTUVW$$$$$$$$$

replaceArray

replaceArray(Array, Array)

Parameters:

  • Array: The string to modify with the given replacement patterns.
  • Array: Same as replacStr, this is an an array of objects containing the replacement patterns, each including a pattern property, which can be a string or a RegExp, and a replacement property, which can be a string or a function to be called for each match.

Given the following:

var frep = require('frep');

var arr = [
  'Jon Schlinkert',
  'Brian Woodward'
];
var patterns = [
  {
    pattern: /(B|S)/g,
    replacement: '###'
  },
  {
    pattern: /(J|W)/g,
    replacement: '$$$'
  },
  ...
];

frep.replaceArray(arr, patterns));

An array of new strings is returned, with some or all matches in each string replaced by the given replacement strings.

["$$$on ###chlinkert", "###rian $$$oodward"]

Author

License

Copyright (c) 2013 Jon Schlinkert Licensed under the MIT license.


Project created by Jon Schlinkert.

This file was generated on Wed Sep 18 2013 00:03:54.