Last active
August 3, 2021 15:11
-
-
Save plugn/8f1d328b2a0712ac2a66bf50977c4b10 to your computer and use it in GitHub Desktop.
php.func.es6.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* php.es6 | |
* @description PHP functions implemented in JavaScript/ES6 | |
* @author Max L Dolgov <bananafishbone@gmail.com> | |
*/ | |
function count(value) { return value.length } | |
function chr(num) { return String.fromCharCode(num) } | |
function ord(str) { return String(str).charCodeAt(0) } | |
function trim(str) { return String(str).trim() } | |
function substr(str, start, length) { return String(str).substr(start, length) } | |
function strtok(str, token='') { | |
function reOR(str) { return new RegExp(`[${str}]`) } | |
return token ? str.split(reOR(token))[0] : false | |
} | |
function str_replace(search, replace, str, count) { | |
function re(str) { | |
return new RegExp(Array.isArray(str) ? str.join('|') : str, 'gm') | |
} | |
return str.replace(re(search), replace) | |
} | |
function strpos(haystack, needle, offset) { | |
const index = String(haystack).indexOf(needle, offset) | |
return Boolean(~index) ? index : false | |
} | |
function explode(delimiter, str, limit) { return String(str).split(delimiter, limit) } | |
function implode(delimiter = '', arr) { return arr.join(delimiter) } | |
function array_shift(arr, ...items) { return arr.shift(...items) } | |
function array_unshift(arr, ...items) { return arr.unshift(...items) } | |
function array_pop(arr) { return arr.pop() } | |
function array_push(arr, ...items) { return arr.push(...items) } | |
function array_splice(arr, start, length, insertion) { | |
return [].splice.apply(arr, [start, length || arr.length].concat(insertion || [])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment