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

string-replace-enhanced

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-replace-enhanced

A package to go further with string replace

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

📝✏️string-replace-enhanced

A package to go further with string replace

MIT licenses snyk NPM version NPM dependencies Travis codecov Codacy bundlephobia semantic-release PRs Welcome

string-replace-enhanced allow you to go futher with the command replace for string in javascript. You have two options, use the object and implement his settings or use the functions in a standalone way.

Installation

Using npm:

npm install -S string-replace-enhanced

... and then:

import stringReplaceEnhanced from 'string-replace-enhanced'
//  or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
//  or
const {default: stringReplaceEnhanced} = require('string-replace-enhanced')

In NodeJS:

const {default : stringReplaceEnhanced} = require('string-replace-enhanced')
//  or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'

In a browser:

<script src="https://unpkg.com/string-replace-enhanced@latest/lib/sre.min.js"></script>
<script>
  /* stringReplaceEnhanced is available here */
  /* in object style */

  new StringReplaceEnhanced.default(options) //constructor

  /* standalone functions */

  StringReplaceEnhanced.replace(...args) //function
</script>

Usage

There is two possibilities, use the object ou the separated functions.

Object

With the object it will be possible to reuse a preset configuration or use the default one.

import stringReplaceEnhanced from 'string-replace-enhanced'

// If an option is missing, it will be given a default value
const options =  {
  after: ['«'],
  around: [],
  before: ['!', '?', ':', ';', '»'],
  regex: [],
  replacer: '&nbsp;',
  toReplace: ' ',
};

// Create a new stringReplaceEnhanced object
const sre = new stringReplaceEnhanced(options);

// Use its methods simply giving the string to work on
console.log(sre.replaceBefore('Hello world !'));
// Hello world&nbsp;!

Functions

For the standalone functions you will need to specify every arguments

import { replaceBefore } from 'string-replace-enhanced'

console.log(replaceBefore('Hello world !', ' ', '&nbsp;'))
// Hello world&nbsp;!

Options

Check the links below to have the up to date version:

  • All options are documented in here

  • The default object implementation's settings is here

nametypedefaultdescription
afterReadonlyArray or string['«']Array of char in need of potential need of replacement after itself
aroundReadonlyArray or string[]Array of char in need of potential need of replacement around itself
beforeReadonlyArray or string['!', '?', ':', ';', '»']Array of char in need of potential need of replacement before itself
regexReadonlyArray or RegExp[]Array of regex, replace match by the replacer
replacerstring'&nbsp;'Replacer of matching toReplace
toReplacestring' 'String to replace, in the function replace toReplace can be an array of string

Properties and methods

To see more about the methods and properties you can access to the documentation here

Documentation

To see more about the functions or the configuration you can access it in the latest documentation here or one in the forked project:

npm i && npm run build:doc

The documentation will be available in the docs file.

Keywords

nbsp

FAQs

Package last updated on 08 Apr 2019

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