string-replace-async
Advanced tools
Comparing version 1.1.0 to 1.2.0
19
index.js
@@ -44,5 +44,4 @@ 'use strict'; | ||
return prev.then(function (ret) { | ||
return assignReplacement(match, replacer).then(function (match) { | ||
ret.push(match); | ||
return ret; | ||
return assignReplacement(match, replacer).then(function (res) { | ||
return ret.concat([res]); | ||
}); | ||
@@ -63,3 +62,3 @@ }); | ||
if (typeof replacer === 'string') { | ||
return Promise.resolve(str.replace(re, replacer)); | ||
return str.replace(re, replacer); | ||
} | ||
@@ -79,10 +78,18 @@ | ||
function fn(str, re, replacer, seq) { | ||
try { | ||
return Promise.resolve(processString(str, re, replacer, seq)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
function stringReplaceAsync(str, re, replacer) { | ||
return processString(str, re, replacer, false); | ||
return fn(str, re, replacer, false); | ||
} | ||
stringReplaceAsync.seq = function (str, re, replacer) { | ||
return processString(str, re, replacer, true); | ||
return fn(str, re, replacer, true); | ||
}; | ||
module.exports = stringReplaceAsync; |
{ | ||
"name": "string-replace-async", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Asynchronous String.prototype.replace()", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
5528
71