UNPKG

node-nlp

Version:

Library for NLU (Natural Language Understanding) done in Node.js

11 lines (8 loc) 320 B
'use strict'; var escapeStringRegexp = require('escape-string-regexp'); module.exports = function (str, target) { if (typeof str !== 'string' || typeof target !== 'string') { throw new TypeError('Expected a string'); } return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target); };