Skip to content

Instantly share code, notes, and snippets.

function unescapeJSString(string) {
var named = {b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", v: "\v"};
return string.replace(/\\(?:([bfnrtv])|u([0-9a-fA-F]{4})|x([0-9a-fA-F]{2})|([0-3][0-7]{0,2}|[0-7]{1,2})|([^]))/g, function(seq, name, hex4, hex2, oct, char) {
var hex;
if (name) { // e.g. \n
return named[name];
} else if (char) { // e.g. \"
return char;
} else if (hex = hex4 || hex2) { // e.g. \u0022 or \x22
return String.fromCharCode(parseInt(hex, 16));
Array.prototype.forSome = function(callback, thisValue) {
if (typeof thisValue !== 'object') {
thisValue = null;
}
try {
for (var i = 0; i < this.length; i++) {
if (this.hasOwnProperty(i)) {
var returnValue = callback.call(thisValue, this[i], i, this);
if (typeof returnValue !== 'undefined') {
return returnValue;