From 824a2d9f587ca017fc71b84d835e72f54f9c87c4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 7 Nov 2018 18:02:36 +0100 Subject: Began rewrite --- node_modules/locutus/php/strings/substr_replace.js | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 node_modules/locutus/php/strings/substr_replace.js (limited to 'node_modules/locutus/php/strings/substr_replace.js') diff --git a/node_modules/locutus/php/strings/substr_replace.js b/node_modules/locutus/php/strings/substr_replace.js new file mode 100644 index 0000000..9778789 --- /dev/null +++ b/node_modules/locutus/php/strings/substr_replace.js @@ -0,0 +1,32 @@ +'use strict'; + +module.exports = function substr_replace(str, replace, start, length) { + // eslint-disable-line camelcase + // discuss at: http://locutus.io/php/substr_replace/ + // original by: Brett Zamir (http://brett-zamir.me) + // example 1: substr_replace('ABCDEFGH:/MNRPQR/', 'bob', 0) + // returns 1: 'bob' + // example 2: var $var = 'ABCDEFGH:/MNRPQR/' + // example 2: substr_replace($var, 'bob', 0, $var.length) + // returns 2: 'bob' + // example 3: substr_replace('ABCDEFGH:/MNRPQR/', 'bob', 0, 0) + // returns 3: 'bobABCDEFGH:/MNRPQR/' + // example 4: substr_replace('ABCDEFGH:/MNRPQR/', 'bob', 10, -1) + // returns 4: 'ABCDEFGH:/bob/' + // example 5: substr_replace('ABCDEFGH:/MNRPQR/', 'bob', -7, -1) + // returns 5: 'ABCDEFGH:/bob/' + // example 6: substr_replace('ABCDEFGH:/MNRPQR/', '', 10, -1) + // returns 6: 'ABCDEFGH://' + + if (start < 0) { + // start position in str + start = start + str.length; + } + length = length !== undefined ? length : str.length; + if (length < 0) { + length = length + str.length - start; + } + + return [str.slice(0, start), replace.substr(0, length), replace.slice(length), str.slice(start + length)].join(''); +}; +//# sourceMappingURL=substr_replace.js.map \ No newline at end of file -- cgit v1.2.3