Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artentica/string-replace-enhanced
A package to go further with string replace
https://github.com/artentica/string-replace-enhanced
javascript npm-package regex standalone string string-manipulation utility
Last synced: 4 days ago
JSON representation
A package to go further with string replace
- Host: GitHub
- URL: https://github.com/artentica/string-replace-enhanced
- Owner: artentica
- License: mit
- Created: 2018-12-08T12:11:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-24T23:24:54.000Z (over 1 year ago)
- Last Synced: 2024-10-06T21:35:43.823Z (about 1 month ago)
- Topics: javascript, npm-package, regex, standalone, string, string-manipulation, utility
- Language: TypeScript
- Homepage: https://artentica.github.io/string-replace-enhanced
- Size: 1.32 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
📝✏️string-replace-enhanced
A package to go further with string replace
**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:
```javascript
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:
```javascript
const {default : stringReplaceEnhanced} = require('string-replace-enhanced')
// or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
```In a browser:
```html
/* stringReplaceEnhanced is available here */
/* in object style */new StringReplaceEnhanced.default(options) //constructor
/* standalone functions */
StringReplaceEnhanced.replace(...args) //function
```
## 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.
```javascript
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: 'Â ',
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 !
```### Functions
For the standalone functions you will need to specify every arguments
```javascript
import { replaceBefore } from 'string-replace-enhanced'console.log(replaceBefore('Hello world !', ' ', 'Â '))
// Hello world !
```## Options
Check the links below to have the up to date version:
- All options are documented in [here](https://artentica.github.io/string-replace-enhanced/interfaces/_interfaces_.isettings.html)
- The default object implementation's settings is [here](https://artentica.github.io/string-replace-enhanced/modules/_defaultsetttings_.html)
| name | type | default | description |
| --------- | ------------------------------- | --------------------------- | ------------------------------------------------------------------------------------ |
| after | ReadonlyArray or string | `['«']` | Array of char in need of potential need of replacement after itself |
| around | ReadonlyArray or string | `[]` | Array of char in need of potential need of replacement around itself |
| before | ReadonlyArray or string | `['!', '?', ':', ';', '»']` | Array of char in need of potential need of replacement before itself |
| regex | ReadonlyArray or RegExp | `[]` | Array of regex, replace match by the replacer |
| replacer | string | `'Â '` | Replacer of matching `toReplace` |
| toReplace | string | `' '` | 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](https://artentica.github.io/string-replace-enhanced/modules/_core_.html)
## Documentation
To see more about the functions or the configuration you can access it in the latest documentation [here](https://artentica.github.io/string-replace-enhanced/) or one in the forked project:
npm i && npm run build:doc
The documentation will be available in the `docs` file.