1.0.0 • Published 2 years ago

replace-moment v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 replace-moment@1.0.0 --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;

LICENSE: MIT

Join to this project: replace-moment