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/strrpos.js | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 node_modules/locutus/php/strings/strrpos.js (limited to 'node_modules/locutus/php/strings/strrpos.js') diff --git a/node_modules/locutus/php/strings/strrpos.js b/node_modules/locutus/php/strings/strrpos.js new file mode 100644 index 0000000..ccabd92 --- /dev/null +++ b/node_modules/locutus/php/strings/strrpos.js @@ -0,0 +1,30 @@ +'use strict'; + +module.exports = function strrpos(haystack, needle, offset) { + // discuss at: http://locutus.io/php/strrpos/ + // original by: Kevin van Zonneveld (http://kvz.io) + // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) + // bugfixed by: Brett Zamir (http://brett-zamir.me) + // input by: saulius + // example 1: strrpos('Kevin van Zonneveld', 'e') + // returns 1: 16 + // example 2: strrpos('somepage.com', '.', false) + // returns 2: 8 + // example 3: strrpos('baa', 'a', 3) + // returns 3: false + // example 4: strrpos('baa', 'a', 2) + // returns 4: 2 + + var i = -1; + if (offset) { + i = (haystack + '').slice(offset).lastIndexOf(needle); // strrpos' offset indicates starting point of range till end, + // while lastIndexOf's optional 2nd argument indicates ending point of range from the beginning + if (i !== -1) { + i += offset; + } + } else { + i = (haystack + '').lastIndexOf(needle); + } + return i >= 0 ? i : false; +}; +//# sourceMappingURL=strrpos.js.map \ No newline at end of file -- cgit v1.2.3