replace-moment
v1.0.0
Published
rapid replace or replace-all
Downloads
11
Maintainers
Readme
Replace Moment
Notice: This project is used for researching.
Its speed is 3-5x slower than String.prototype.replaceAll
.
Maybe because the JavaScript parser is too slow. You can try using c++ to rewrite this project.
How to install it:
npm i [email protected] --save
How to use it:
const { replace, replaceAll } = require('replace-moment');
const str = 'pig piggy';
console.log(replace(str, 'pig', 'dog'));
// 'dog piggy'
console.log(replaceAll(str, 'pig', 'dog'));
// 'dog doggy'
Declares:
/**
* @function name: replace
* @Description : replace sub-string in string
* @Author : lihugang
* @param {string} source
* @param {string} pattern
* @param {string | Function} replacement
* @param {number} startSearchPosition
* @return {string}
* @Date : 2022-08-02 14:22:12
* @LastEditors : lihugang
*/
declare function replace(source: string, pattern: string, replacement: string | Function, startSearchPosition? : number): string;
/**
* @function name: replaceAll
* @Description : replace all sub-string in string
* @Author : lihugang
* @param {string} source
* @param {string} pattern
* @param {string | Function} replacement
* @param {number} startSearchPosition
* @return {string}
* @Date : 2022-08-02 14:22:12
* @LastEditors : lihugang
*/
declare function replaceAll(source: string, pattern: string, replacement: string | Function, startSearchPosition?: number): string;