Files
gun/src/gun.js
2016-05-04 14:39:51 -07:00

48 lines
1.4 KiB
JavaScript

function Gun(o){
var gun = this;
if(!Gun.is(gun)){ return new Gun(o) }
if(Gun.is(o)){ return gun }
return gun.opt(o);
}
Gun.version = 0.3;
Gun._ = { // some reserved key words, these are not the only ones.
meta: '_' // all metadata of the node is stored in the meta property on the node.
,soul: '#' // a soul is a UUID of a node but it always points to the "latest" data known.
,field: '.' // a field is a property on a node which points to a value.
,state: '>' // other than the soul, we store HAM metadata.
,'#':'soul'
,'.':'field'
,'=':'value'
,'>':'state'
}
// check to see if it is a GUN instance.
Gun.is = function(gun){
return (gun instanceof Gun);
}
var root = this || {}; // safe for window, global, root, and 'use strict'.
root.console = root.console || {log: function(s){ return s }}; // safe for old browsers
if(typeof window !== "undefined"){
root = window;
window.Gun = Gun;
}
module.exports = Gun;
Gun.log = function(s){
return (!Gun.log.squelch && root.console.log.apply(root.console, arguments)), s;
}
Gun.log.count = function(s){ return Gun.log.count[s] = Gun.log.count[s] || 0, Gun.log.count[s]++ }
/*
var console = {
log: function(s){return root.console.log.apply(root.console, arguments), s},
Log: Gun.log
};
console.debug = function(i, s){ return (Gun.log.debug && i === Gun.log.debug && Gun.log.debug++) && root.console.log.apply(root.console, arguments), s };
*/