Created
February 10, 2015 13:56
-
-
Save svaponi/f99db513c6693ae4598a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/suvaro
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
/* JSON formatting (syntaxHighlight) */ | |
pre { | |
border: 1px dotted #ddd; | |
background-color: #f8f8f8; | |
border-radius: 5px; | |
} | |
.string { | |
color: green; | |
} | |
.number { | |
color: darkorange; | |
} | |
.boolean { | |
color: blue; | |
} | |
.null { | |
color: magenta; | |
} | |
.key { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<input id="displayData" type="button" value="Click then check the ORIGINAL data object" /> | |
<input id="deleteData" type="button" value="Click then check the data after props have been DELETED" /> | |
<input id="filterData" type="button" value="Click then check the data after props have been FILTERED" /> | |
<div id="result"></div> | |
<script id="jsbin-javascript"> | |
var data = { | |
"kind": "drive#file", | |
"id": "0B5wcaiDxogdvdhTzIwOWJZX0U", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/MTQyMzUTE5MjY6Mg\"", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWTTzIwOWJZX0U", | |
"webContentLink": "https://docs.google.com/a/email.com/uc?id=0B5wcaiDxoBHWT6dhTzIwOWJZX0U&export=download", | |
"alternateLink": "https://docs.google.com/a/email.com/file/d/0B5wcaiDxWT6dhTzIwOWJZX0U/edit?usp=drivesdk", | |
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png", | |
"title": "cryptsetup", | |
"mimeType": "application/octet-stream", | |
"labels": { | |
"starred": false, | |
"hidden": false, | |
"trashed": false, | |
"restricted": false, | |
"viewed": true | |
}, | |
"createdDate": "3015-03-10T11:56:13.860Z", | |
"modifiedDate": "3015-03-10T11:56:13.673Z", | |
"modifiedByMeDate": "3015-03-10T11:56:13.673Z", | |
"lastViewedByMeDate": "3015-03-10T11:56:13.673Z", | |
"markedViewedByMeDate": "1970-01-01T00:00:00.000Z", | |
"version": "1735", | |
"parents": [{ | |
"kind": "drive#parentReference", | |
"id": "0AJwcaiDxoBHWUk9PVA", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhTzIwOW0U/parents/0AJwcaiDxoBHWUk9PVA", | |
"parentLink": "https://www.googleapis.com/drive/v3/files/0AJwcaiDxoBHk9PVA", | |
"isRoot": true | |
}], | |
"downloadUrl": "https://doc-04-3c-docs.googleusercontent.com/docs/securesc/kd3phd0hf6o5d84lkag86llkamhrp/o9cmuiafc65hds0r1klt5nitnotqii/1436300/15695367667335169/15695369335169/0B5wcaiDxoBHWT6dhTzIwOWJZX0U?h=14664165789095643886&e=download&gd=true", | |
"userPermission": { | |
"kind": "drive#permission", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/BfaTXif3DDFVbiuUFkCkA-xM\"", | |
"id": "me", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhwOWJZX0U/permissions/me", | |
"role": "owner", | |
"type": "user" | |
}, | |
"originalFilename": "cryptsetup", | |
"fileExtension": "", | |
"md5Checksum": "3d86504a5871b4cad4e64417cf0359", | |
"fileSize": "47040", | |
"quotaBytesUsed": "47040", | |
"ownerNames": [ | |
"name surname"], | |
"owners": [{ | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permissionId": "156953676659335169", | |
"emailAddress": "[email protected]" | |
}], | |
"lastModifyingUserName": "name surname", | |
"lastModifygUser": { | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permiionId": "15695367659335169", | |
"emailAddress": "[email protected]" | |
}, | |
"editable": true, | |
"copyable": true, | |
"writersCanShare": true, | |
"shared": false, | |
"appDataContents": false, | |
"headRevisionId": "0B5wcaiDxoBHWT0trT3VwbHl5ajlrUTZ6RTlOZG5PNGRjPQ" | |
}; | |
// campi di interesse | |
var props = ['owners', 'displayName', 'emailAddress', 'id', 'originalFilename', 'fileExtension', 'iconLink', 'ownerNames', 'selfLink', 'alternateLink', 'webContentLink', 'downloadUrl']; | |
var f = { | |
'deleteRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (data.hasOwnProperty(property)) { | |
for (var i in attrs) { | |
if (property == attrs[i]) { | |
delete obj[attrs[i]]; | |
} else { | |
if (typeof obj[property] === "object") { | |
this.deleteRecursive(obj[property], attrs); | |
} | |
} | |
} | |
} | |
} | |
}, | |
'filterRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (obj.hasOwnProperty(property)) { | |
var found = false; | |
for (var i in attrs) { | |
if (!isNaN(property) || property == attrs[i] ) { | |
// se la proprietà è presente in attr --> continuo o scendo di livello | |
if (typeof obj[property] === "object") this.filterRecursive(obj[property], attrs); | |
found = true; | |
break; | |
} | |
} | |
if (!found) delete obj[property]; | |
} | |
} | |
}, | |
'appendOutput': function (obj) { | |
var pre = document.createElement('pre'); | |
pre.innerHTML = '<h5>' + new Date().getTime() + '</h5>' + this.syntaxHighlight(obj); | |
var cnt = document.getElementById('result'); | |
if (cnt.firstChild) cnt.insertBefore(document.createElement('hr'), cnt.firstChild); | |
cnt.insertBefore(pre, cnt.firstChild); | |
}, | |
'syntaxHighlight': function (obj) { | |
var json = obj; // JSON.stringify(data, undefined, 4); | |
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | |
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { | |
var cls = 'number'; | |
if (/^"/.test(match)) { | |
if (/:$/.test(match)) { | |
cls = 'key'; | |
} else { | |
cls = 'string'; | |
} | |
} else if (/true|false/.test(match)) { | |
cls = 'bodataolean'; | |
} else if (/null/.test(match)) { | |
cls = 'null'; | |
} | |
return '<span class="' + cls + '">' + match + '</span>'; | |
}); | |
} | |
}; | |
jQuery(document).ready(function () { | |
jQuery("#displayData").click(function () { | |
f.appendOutput(JSON.stringify(data, null, 4)); | |
}); | |
jQuery("#deleteData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.deleteRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
jQuery("#filterData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.filterRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//code.jquery.com/jquery-2.1.1.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input id="displayData" type="button" value="Click then check the ORIGINAL data object" /> | |
<input id="deleteData" type="button" value="Click then check the data after props have been DELETED" /> | |
<input id="filterData" type="button" value="Click then check the data after props have been FILTERED" /> | |
<div id="result"></div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-css" type="text/css"> /* JSON formatting (syntaxHighlight) */ | |
pre { | |
border: 1px dotted #ddd; | |
background-color: #f8f8f8; | |
border-radius: 5px; | |
} | |
.string { | |
color: green; | |
} | |
.number { | |
color: darkorange; | |
} | |
.boolean { | |
color: blue; | |
} | |
.null { | |
color: magenta; | |
} | |
.key { | |
color: red; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var data = { | |
"kind": "drive#file", | |
"id": "0B5wcaiDxogdvdhTzIwOWJZX0U", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/MTQyMzUTE5MjY6Mg\"", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWTTzIwOWJZX0U", | |
"webContentLink": "https://docs.google.com/a/email.com/uc?id=0B5wcaiDxoBHWT6dhTzIwOWJZX0U&export=download", | |
"alternateLink": "https://docs.google.com/a/email.com/file/d/0B5wcaiDxWT6dhTzIwOWJZX0U/edit?usp=drivesdk", | |
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png", | |
"title": "cryptsetup", | |
"mimeType": "application/octet-stream", | |
"labels": { | |
"starred": false, | |
"hidden": false, | |
"trashed": false, | |
"restricted": false, | |
"viewed": true | |
}, | |
"createdDate": "3015-03-10T11:56:13.860Z", | |
"modifiedDate": "3015-03-10T11:56:13.673Z", | |
"modifiedByMeDate": "3015-03-10T11:56:13.673Z", | |
"lastViewedByMeDate": "3015-03-10T11:56:13.673Z", | |
"markedViewedByMeDate": "1970-01-01T00:00:00.000Z", | |
"version": "1735", | |
"parents": [{ | |
"kind": "drive#parentReference", | |
"id": "0AJwcaiDxoBHWUk9PVA", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhTzIwOW0U/parents/0AJwcaiDxoBHWUk9PVA", | |
"parentLink": "https://www.googleapis.com/drive/v3/files/0AJwcaiDxoBHk9PVA", | |
"isRoot": true | |
}], | |
"downloadUrl": "https://doc-04-3c-docs.googleusercontent.com/docs/securesc/kd3phd0hf6o5d84lkag86llkamhrp/o9cmuiafc65hds0r1klt5nitnotqii/1436300/15695367667335169/15695369335169/0B5wcaiDxoBHWT6dhTzIwOWJZX0U?h=14664165789095643886&e=download&gd=true", | |
"userPermission": { | |
"kind": "drive#permission", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/BfaTXif3DDFVbiuUFkCkA-xM\"", | |
"id": "me", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhwOWJZX0U/permissions/me", | |
"role": "owner", | |
"type": "user" | |
}, | |
"originalFilename": "cryptsetup", | |
"fileExtension": "", | |
"md5Checksum": "3d86504a5871b4cad4e64417cf0359", | |
"fileSize": "47040", | |
"quotaBytesUsed": "47040", | |
"ownerNames": [ | |
"name surname"], | |
"owners": [{ | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permissionId": "156953676659335169", | |
"emailAddress": "[email protected]" | |
}], | |
"lastModifyingUserName": "name surname", | |
"lastModifygUser": { | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permiionId": "15695367659335169", | |
"emailAddress": "[email protected]" | |
}, | |
"editable": true, | |
"copyable": true, | |
"writersCanShare": true, | |
"shared": false, | |
"appDataContents": false, | |
"headRevisionId": "0B5wcaiDxoBHWT0trT3VwbHl5ajlrUTZ6RTlOZG5PNGRjPQ" | |
}; | |
// campi di interesse | |
var props = ['owners', 'displayName', 'emailAddress', 'id', 'originalFilename', 'fileExtension', 'iconLink', 'ownerNames', 'selfLink', 'alternateLink', 'webContentLink', 'downloadUrl']; | |
var f = { | |
'deleteRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (data.hasOwnProperty(property)) { | |
for (var i in attrs) { | |
if (property == attrs[i]) { | |
delete obj[attrs[i]]; | |
} else { | |
if (typeof obj[property] === "object") { | |
this.deleteRecursive(obj[property], attrs); | |
} | |
} | |
} | |
} | |
} | |
}, | |
'filterRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (obj.hasOwnProperty(property)) { | |
var found = false; | |
for (var i in attrs) { | |
if (!isNaN(property) || property == attrs[i] ) { | |
// se la proprietà è presente in attr --> continuo o scendo di livello | |
if (typeof obj[property] === "object") this.filterRecursive(obj[property], attrs); | |
found = true; | |
break; | |
} | |
} | |
if (!found) delete obj[property]; | |
} | |
} | |
}, | |
'appendOutput': function (obj) { | |
var pre = document.createElement('pre'); | |
pre.innerHTML = '<h5>' + new Date().getTime() + '</h5>' + this.syntaxHighlight(obj); | |
var cnt = document.getElementById('result'); | |
if (cnt.firstChild) cnt.insertBefore(document.createElement('hr'), cnt.firstChild); | |
cnt.insertBefore(pre, cnt.firstChild); | |
}, | |
'syntaxHighlight': function (obj) { | |
var json = obj; // JSON.stringify(data, undefined, 4); | |
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | |
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { | |
var cls = 'number'; | |
if (/^"/.test(match)) { | |
if (/:$/.test(match)) { | |
cls = 'key'; | |
} else { | |
cls = 'string'; | |
} | |
} else if (/true|false/.test(match)) { | |
cls = 'bodataolean'; | |
} else if (/null/.test(match)) { | |
cls = 'null'; | |
} | |
return '<span class="' + cls + '">' + match + '</span>'; | |
}); | |
} | |
}; | |
jQuery(document).ready(function () { | |
jQuery("#displayData").click(function () { | |
f.appendOutput(JSON.stringify(data, null, 4)); | |
}); | |
jQuery("#deleteData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.deleteRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
jQuery("#filterData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.filterRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
});</script></body> | |
</html> |
This file contains hidden or 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
/* JSON formatting (syntaxHighlight) */ | |
pre { | |
border: 1px dotted #ddd; | |
background-color: #f8f8f8; | |
border-radius: 5px; | |
} | |
.string { | |
color: green; | |
} | |
.number { | |
color: darkorange; | |
} | |
.boolean { | |
color: blue; | |
} | |
.null { | |
color: magenta; | |
} | |
.key { | |
color: red; | |
} |
This file contains hidden or 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
var data = { | |
"kind": "drive#file", | |
"id": "0B5wcaiDxogdvdhTzIwOWJZX0U", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/MTQyMzUTE5MjY6Mg\"", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWTTzIwOWJZX0U", | |
"webContentLink": "https://docs.google.com/a/email.com/uc?id=0B5wcaiDxoBHWT6dhTzIwOWJZX0U&export=download", | |
"alternateLink": "https://docs.google.com/a/email.com/file/d/0B5wcaiDxWT6dhTzIwOWJZX0U/edit?usp=drivesdk", | |
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png", | |
"title": "cryptsetup", | |
"mimeType": "application/octet-stream", | |
"labels": { | |
"starred": false, | |
"hidden": false, | |
"trashed": false, | |
"restricted": false, | |
"viewed": true | |
}, | |
"createdDate": "3015-03-10T11:56:13.860Z", | |
"modifiedDate": "3015-03-10T11:56:13.673Z", | |
"modifiedByMeDate": "3015-03-10T11:56:13.673Z", | |
"lastViewedByMeDate": "3015-03-10T11:56:13.673Z", | |
"markedViewedByMeDate": "1970-01-01T00:00:00.000Z", | |
"version": "1735", | |
"parents": [{ | |
"kind": "drive#parentReference", | |
"id": "0AJwcaiDxoBHWUk9PVA", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhTzIwOW0U/parents/0AJwcaiDxoBHWUk9PVA", | |
"parentLink": "https://www.googleapis.com/drive/v3/files/0AJwcaiDxoBHk9PVA", | |
"isRoot": true | |
}], | |
"downloadUrl": "https://doc-04-3c-docs.googleusercontent.com/docs/securesc/kd3phd0hf6o5d84lkag86llkamhrp/o9cmuiafc65hds0r1klt5nitnotqii/1436300/15695367667335169/15695369335169/0B5wcaiDxoBHWT6dhTzIwOWJZX0U?h=14664165789095643886&e=download&gd=true", | |
"userPermission": { | |
"kind": "drive#permission", | |
"etag": "\"uEj7LMQAiqGTU6UveaT9PYa-HUQ/BfaTXif3DDFVbiuUFkCkA-xM\"", | |
"id": "me", | |
"selfLink": "https://www.googleapis.com/drive/v3/files/0B5wcaiDxoBHWT6dhwOWJZX0U/permissions/me", | |
"role": "owner", | |
"type": "user" | |
}, | |
"originalFilename": "cryptsetup", | |
"fileExtension": "", | |
"md5Checksum": "3d86504a5871b4cad4e64417cf0359", | |
"fileSize": "47040", | |
"quotaBytesUsed": "47040", | |
"ownerNames": [ | |
"name surname"], | |
"owners": [{ | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permissionId": "156953676659335169", | |
"emailAddress": "[email protected]" | |
}], | |
"lastModifyingUserName": "name surname", | |
"lastModifygUser": { | |
"kind": "drive#user", | |
"displayName": "name surname", | |
"isAuthenticatedUser": true, | |
"permiionId": "15695367659335169", | |
"emailAddress": "[email protected]" | |
}, | |
"editable": true, | |
"copyable": true, | |
"writersCanShare": true, | |
"shared": false, | |
"appDataContents": false, | |
"headRevisionId": "0B5wcaiDxoBHWT0trT3VwbHl5ajlrUTZ6RTlOZG5PNGRjPQ" | |
}; | |
// campi di interesse | |
var props = ['owners', 'displayName', 'emailAddress', 'id', 'originalFilename', 'fileExtension', 'iconLink', 'ownerNames', 'selfLink', 'alternateLink', 'webContentLink', 'downloadUrl']; | |
var f = { | |
'deleteRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (data.hasOwnProperty(property)) { | |
for (var i in attrs) { | |
if (property == attrs[i]) { | |
delete obj[attrs[i]]; | |
} else { | |
if (typeof obj[property] === "object") { | |
this.deleteRecursive(obj[property], attrs); | |
} | |
} | |
} | |
} | |
} | |
}, | |
'filterRecursive': function (obj, attrs) { | |
for (var property in obj) { | |
if (obj.hasOwnProperty(property)) { | |
var found = false; | |
for (var i in attrs) { | |
if (!isNaN(property) || property == attrs[i] ) { | |
// se la proprietà è presente in attr --> continuo o scendo di livello | |
if (typeof obj[property] === "object") this.filterRecursive(obj[property], attrs); | |
found = true; | |
break; | |
} | |
} | |
if (!found) delete obj[property]; | |
} | |
} | |
}, | |
'appendOutput': function (obj) { | |
var pre = document.createElement('pre'); | |
pre.innerHTML = '<h5>' + new Date().getTime() + '</h5>' + this.syntaxHighlight(obj); | |
var cnt = document.getElementById('result'); | |
if (cnt.firstChild) cnt.insertBefore(document.createElement('hr'), cnt.firstChild); | |
cnt.insertBefore(pre, cnt.firstChild); | |
}, | |
'syntaxHighlight': function (obj) { | |
var json = obj; // JSON.stringify(data, undefined, 4); | |
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | |
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { | |
var cls = 'number'; | |
if (/^"/.test(match)) { | |
if (/:$/.test(match)) { | |
cls = 'key'; | |
} else { | |
cls = 'string'; | |
} | |
} else if (/true|false/.test(match)) { | |
cls = 'bodataolean'; | |
} else if (/null/.test(match)) { | |
cls = 'null'; | |
} | |
return '<span class="' + cls + '">' + match + '</span>'; | |
}); | |
} | |
}; | |
jQuery(document).ready(function () { | |
jQuery("#displayData").click(function () { | |
f.appendOutput(JSON.stringify(data, null, 4)); | |
}); | |
jQuery("#deleteData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.deleteRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
jQuery("#filterData").click(function () { | |
var tmp = JSON.parse( JSON.stringify( data ) ); | |
f.filterRecursive(tmp, props); | |
f.appendOutput(JSON.stringify(tmp, null, 4)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment