Last active
December 15, 2019 13:49
-
-
Save EduApps-CDG/98b4d85f0f3884fd29edadc2178f3e4e to your computer and use it in GitHub Desktop.
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
/** | |
* Copyright 2019 EduApps (Eduardo P. Gomez) | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
var ObjectTools = { | |
help: function() { | |
console.log("ObjectTools.js V1.0.0 by EduApps\n<> - needed variable.\n[] - not needed variable.\n\ncommands:\n help - show this help message()\n" + | |
" Length - returns the number of child Objects inside the Object root(<object>)\n" + | |
" getRAM - return the size (in bytes) occupied by the Object in RAM(<>object)"); | |
}, | |
Length: function(object) { | |
var length = 0; | |
for (var key in object) { | |
if (object.hasOwnProperty(key)) { | |
++length; | |
} | |
} | |
return length; | |
}, | |
getRAM: function(object) { | |
var objectList = []; | |
var stack = [object]; | |
var bytes = 0; | |
while (stack.length) { | |
var value = stack.pop(); | |
if (typeof value === 'boolean') { | |
bytes += 4; | |
} else if (typeof value === 'string') { | |
bytes += value.length * 2; | |
} else if (typeof value === 'number') { | |
bytes += 8; | |
} else if (typeof value === 'object' && objectList.indexOf( value ) === -1) { | |
objectList.push(value); | |
for( var i in value ) { | |
stack.push( value[ i ] ); | |
} | |
} | |
} | |
return bytes; | |
} | |
} |
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
/** | |
* Copyright 2019 EduApps (Eduardo P. Gomez) | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
var ObjectTools={help:function(){console.log("ObjectTools.js V1.0.0 by EduApps\n<> - needed variable.\n[] - not needed variable.\n\ncommands:\n help - show this help message()\n"+" Length - returns the number of child Objects inside the Object root(<object>)\n"+" getRAM - return the size (in bytes) occupied by the Object in RAM(<>object)")},Length:function(object){var length=0;for(var key in object){if(object.hasOwnProperty(key)){++length}}return length},getRAM:function(object){var objectList=[];var stack=[object];var bytes=0;while(stack.length){var value=stack.pop();if(typeof value==='boolean'){bytes+=4}else if(typeof value==='string'){bytes+=value.length*2}else if(typeof value==='number'){bytes+=8}else if(typeof value==='object'&&objectList.indexOf(value)===-1){objectList.push(value);for(var i in value){stack.push(value[i])}}}return bytes}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What it can do:
How to do:
see a list of command by typing (on javascript console):