1
0
mirror of https://github.com/chylex/objtree.git synced 2025-06-03 00:34:10 +02:00

Add support for being included as an npm module

This commit is contained in:
chylex 2017-07-24 11:46:13 +02:00
parent f1a6f08983
commit ab989f13f1
2 changed files with 197 additions and 176 deletions

View File

@ -1,4 +1,4 @@
`objtree` is a script that generates a text tree representation of an object. The script can be executed in a browser console.
`objtree` is a script that generates a text tree representation of an object. The script can be executed in a browser console or imported as an `npm` module.
# How to Use

View File

@ -1,3 +1,4 @@
(function(){
const OBJTREE_OBJECT = 0;
const OBJTREE_UNKNOWN = 1;
const OBJTREE_COMPLEX_FUNCTION = 2;
@ -178,6 +179,10 @@ var objtree = function(target, {
},
downloadText: function(filename){
if (typeof window === "undefined"){
throw "objtree.downloadText is only supported in a browser";
}
let url = window.URL.createObjectURL(new Blob([obj.asText()], { "type": "octet/stream" }));
let ele = document.createElement("a");
document.body.appendChild(ele);
@ -192,3 +197,19 @@ var objtree = function(target, {
return obj;
};
objtree.TYPE_OBJECT = OBJTREE_OBJECT;
objtree.TYPE_UNKNOWN = OBJTREE_UNKNOWN;
objtree.TYPE_COMPLEX_FUNCTION = OBJTREE_COMPLEX_FUNCTION;
objtree.TYPE_SIMPLE_FUNCTION = OBJTREE_SIMPLE_FUNCTION;
objtree.TYPE_PRIMARRAY = OBJTREE_PRIMARRAY;
objtree.TYPE_VARIABLE = OBJTREE_VARIABLE;
objtree.TYPE_TOODEEP = OBJTREE_TOODEEP;
if (typeof module !== "undefined" && typeof module.exports !== "undefined"){
module.exports = objtree;
}
else{
window.objtree = objtree;
}
})();