deprecation warnings

This commit is contained in:
Mark Nadal 2021-08-19 05:27:10 -07:00
parent 252e42de17
commit 7d34a29460

View File

@ -1,24 +1,27 @@
;(function(){
var u;
if(''+u == typeof Gun){ return }
var DEP = function(n){ console.log("Warning! Deprecated internal utility will break in next version:", n) }
// Generic javascript utilities.
var Type = Gun;
//Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
Type.fn = {is: function(fn){ return (!!fn && 'function' == typeof fn) }}
Type.bi = {is: function(b){ return (b instanceof Boolean || typeof b == 'boolean') }}
Type.num = {is: function(n){ return !list_is(n) && ((n - parseFloat(n) + 1) >= 0 || Infinity === n || -Infinity === n) }}
Type.text = {is: function(t){ return (typeof t == 'string') }}
Type.text.ify = function(t){
Type.fn = Type.fn || {is: function(fn){ DEP('fn'); return (!!fn && 'function' == typeof fn) }}
Type.bi = Type.bi || {is: function(b){ DEP('bi');return (b instanceof Boolean || typeof b == 'boolean') }}
Type.num = Type.num || {is: function(n){ DEP('num'); return !list_is(n) && ((n - parseFloat(n) + 1) >= 0 || Infinity === n || -Infinity === n) }}
Type.text = Type.text || {is: function(t){ DEP('text'); return (typeof t == 'string') }}
Type.text.ify = Type.text.ify || function(t){ DEP('text.ify');
if(Type.text.is(t)){ return t }
if(typeof JSON !== "undefined"){ return JSON.stringify(t) }
return (t && t.toString)? t.toString() : t;
}
Type.text.random = function(l, c){
Type.text.random = Type.text.random || function(l, c){ DEP('text.random');
var s = '';
l = l || 24; // you are not going to make a 0 length random number, so no need to check type
c = c || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz';
while(l > 0){ s += c.charAt(Math.floor(Math.random() * c.length)); l-- }
return s;
}
Type.text.match = function(t, o){ var tmp, u;
Type.text.match = Type.text.match || function(t, o){ var tmp, u; DEP('text.match');
if('string' !== typeof t){ return false }
if('string' == typeof o){ o = {'=': o} }
o = o || {};
@ -35,7 +38,8 @@
if(u !== o['<'] && t <= o['<']){ return true }
return false;
}
Type.text.hash = function(s, c){ // via SO
Type.text.hash = Type.text.hash || function(s, c){ // via SO
DEP('text.hash');
if(typeof s !== 'string'){ return }
c = c || 0;
if(!s.length){ return c }
@ -46,28 +50,29 @@
}
return c;
}
Type.list = {is: function(l){ return (l instanceof Array) }}
Type.list.slit = Array.prototype.slice;
Type.list.sort = function(k){ // creates a new sort function based off some key
Type.list = Type.list || {is: function(l){ DEP('list'); return (l instanceof Array) }}
Type.list.slit = Type.list.slit || Array.prototype.slice;
Type.list.sort = Type.list.sort || function(k){ // creates a new sort function based off some key
DEP('list.sort');
return function(A,B){
if(!A || !B){ return 0 } A = A[k]; B = B[k];
if(A < B){ return -1 }else if(A > B){ return 1 }
else { return 0 }
}
}
Type.list.map = function(l, c, _){ return obj_map(l, c, _) }
Type.list.map = Type.list.map || function(l, c, _){ DEP('list.map'); return obj_map(l, c, _) }
Type.list.index = 1; // change this to 0 if you want non-logical, non-mathematical, non-matrix, non-convenient array notation
Type.obj = {is: function(o){ return o? (o instanceof Object && o.constructor === Object) || Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] === 'Object' : false }}
Type.obj.put = function(o, k, v){ return (o||{})[k] = v, o }
Type.obj.has = function(o, k){ return o && Object.prototype.hasOwnProperty.call(o, k) }
Type.obj.del = function(o, k){
Type.obj = Type.boj || {is: function(o){ DEP('obj'); return o? (o instanceof Object && o.constructor === Object) || Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] === 'Object' : false }}
Type.obj.put = Type.obj.put || function(o, k, v){ DEP('obj.put'); return (o||{})[k] = v, o }
Type.obj.has = Type.obj.has || function(o, k){ DEP('obj.has'); return o && Object.prototype.hasOwnProperty.call(o, k) }
Type.obj.del = Type.obj.del || function(o, k){ DEP('obj.del');
if(!o){ return }
o[k] = null;
delete o[k];
return o;
}
Type.obj.as = function(o, k, v, u){ return o[k] = o[k] || (u === v? {} : v) }
Type.obj.ify = function(o){
Type.obj.as = Type.obj.as || function(o, k, v, u){ DEP('obj.as'); return o[k] = o[k] || (u === v? {} : v) }
Type.obj.ify = Type.obj.ify || function(o){ DEP('obj.ify');
if(obj_is(o)){ return o }
try{o = JSON.parse(o);
}catch(e){o={}};
@ -78,13 +83,13 @@
if(obj_has(this,k) && u !== this[k]){ return }
this[k] = v;
}
Type.obj.to = function(from, to){
Type.obj.to = Type.obj.to || function(from, to){ DEP('obj.to');
to = to || {};
obj_map(from, map, to);
return to;
}
}());
Type.obj.copy = function(o){ // because http://web.archive.org/web/20140328224025/http://jsperf.com/cloning-an-object/2
Type.obj.copy = Type.obj.copy || function(o){ DEP('obj.copy'); // because http://web.archive.org/web/20140328224025/http://jsperf.com/cloning-an-object/2
return !o? o : JSON.parse(JSON.stringify(o)); // is shockingly faster than anything else, and our data has to be a subset of JSON anyways!
}
;(function(){
@ -92,7 +97,7 @@
if(n && (i === n || (obj_is(n) && obj_has(n, i)))){ return }
if(u !== i){ return true }
}
Type.obj.empty = function(o, n){
Type.obj.empty = Type.obj.empty || function(o, n){ DEP('obj.empty');
if(!o){ return true }
return obj_map(o,empty,{n:n})? false : true;
}
@ -108,7 +113,7 @@
};
var keys = Object.keys, map, u;
Object.keys = Object.keys || function(o){ return map(o, function(v,k,t){t(k)}) }
Type.obj.map = map = function(l, c, _){
Type.obj.map = map = Type.obj.map || function(l, c, _){ DEP('obj.map');
var u, i = 0, x, r, ll, lle, f = 'function' == typeof c;
t.r = u;
if(keys && obj_is(l)){
@ -143,15 +148,15 @@
return f? t.r : Type.list.index? 0 : -1;
}
}());
Type.time = {};
Type.time.is = function(t){ return t? t instanceof Date : (+new Date().getTime()) }
Type.time = Type.time || {};
Type.time.is = Type.time.is || function(t){ DEP('time'); return t? t instanceof Date : (+new Date().getTime()) }
var fn_is = Type.fn.is;
var list_is = Type.list.is;
var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map;
var Val = {};
Val.is = function(v){ // Valid values are a subset of JSON: null, binary, number (!Infinity), text, or a soul relation. Arrays need special algorithms to handle concurrency, so they are not supported directly. Use an extension that supports them if needed but research their problems first.
Val.is = function(v){ DEP('val.is'); // Valid values are a subset of JSON: null, binary, number (!Infinity), text, or a soul relation. Arrays need special algorithms to handle concurrency, so they are not supported directly. Use an extension that supports them if needed but research their problems first.
if(v === u){ return false }
if(v === null){ return true } // "deletes", nulling out keys.
if(v === Infinity){ return false } // we want this to be, but JSON does not support it, sad face.
@ -164,7 +169,7 @@
}
Val.link = Val.rel = {_: '#'};
;(function(){
Val.link.is = function(v){ // this defines whether an object is a soul relation or not, they look like this: {'#': 'UUID'}
Val.link.is = function(v){ DEP('val.link.is'); // this defines whether an object is a soul relation or not, they look like this: {'#': 'UUID'}
if(v && v[rel_] && !v._ && obj_is(v)){ // must be an object.
var o = {};
obj_map(v, map, o);
@ -183,7 +188,7 @@
}
}
}());
Val.link.ify = function(t){ return obj_put({}, rel_, t) } // convert a soul into a relation and return it.
Val.link.ify = function(t){ DEP('val.link.ify'); return obj_put({}, rel_, t) } // convert a soul into a relation and return it.
Type.obj.has._ = '.';
var rel_ = Val.link._, u;
var bi_is = Type.bi.is;
@ -191,11 +196,11 @@
var text_is = Type.text.is;
var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
Type.val = Val;
Type.val = Type.val || Val;
var Node = {_: '_'};
Node.soul = function(n, o){ return (n && n._ && n._[o || soul_]) } // convenience function to check to see if there is a soul on a node and return it.
Node.soul.ify = function(n, o){ // put a soul on an object.
Node.soul = function(n, o){ DEP('node.soul'); return (n && n._ && n._[o || soul_]) } // convenience function to check to see if there is a soul on a node and return it.
Node.soul.ify = function(n, o){ DEP('node.soul.ify'); // put a soul on an object.
o = (typeof o === 'string')? {soul: o} : o || {};
n = n || {}; // make sure it exists.
n._ = n._ || {}; // make sure meta exists.
@ -204,7 +209,7 @@
}
Node.soul._ = Val.link._;
;(function(){
Node.is = function(n, cb, as){ var s; // checks to see if an object is a valid node.
Node.is = function(n, cb, as){ DEP('node.is'); var s; // checks to see if an object is a valid node.
if(!obj_is(n)){ return false } // must be an object.
if(s = Node.soul(n)){ // must have a soul on it.
return !obj_map(n, map, {as:as,cb:cb,s:s,n:n});
@ -218,7 +223,7 @@
}
}());
;(function(){
Node.ify = function(obj, o, as){ // returns a node from a shallow object.
Node.ify = function(obj, o, as){ DEP('node.ify'); // returns a node from a shallow object.
if(!o){ o = {} }
else if(typeof o === 'string'){ o = {soul: o} }
else if('function' == typeof o){ o = {map: o} }
@ -246,11 +251,11 @@
var text = Type.text, text_random = text.random;
var soul_ = Node.soul._;
var u;
Type.node = Node;
Type.node = Type.node || Node;
var State = Type.state;
State.lex = function(){ return State().toString(36).replace('.','') }
State.to = function(from, k, to){
State.lex = function(){ DEP('state.lex'); return State().toString(36).replace('.','') }
State.to = function(from, k, to){ DEP('state.to');
var val = (from||{})[k];
if(obj_is(val)){
val = obj_copy(val);
@ -258,7 +263,7 @@
return State.ify(to, k, State.is(from, k), val, Node.soul(from));
}
;(function(){
State.map = function(cb, s, as){ var u; // for use with Node.ify
State.map = function(cb, s, as){ DEP('state.map'); var u; // for use with Node.ify
var o = obj_is(o = cb || s)? o : null;
cb = fn_is(cb = cb || s)? cb : null;
if(o && !cb){
@ -291,7 +296,7 @@
var Graph = {};
;(function(){
Graph.is = function(g, cb, fn, as){ // checks to see if an object is a valid graph.
Graph.is = function(g, cb, fn, as){ DEP('graph.is'); // checks to see if an object is a valid graph.
if(!g || !obj_is(g) || obj_empty(g)){ return false } // must be an object.
return !obj_map(g, map, {cb:cb,fn:fn,as:as}); // makes sure it wasn't an empty object.
}
@ -306,7 +311,7 @@
}
}());
;(function(){
Graph.ify = function(obj, env, as){
Graph.ify = function(obj, env, as){ DEP('graph.ify');
var at = {path: [], obj: obj};
if(!env){
env = {};
@ -407,13 +412,13 @@
arr.push(at);
}
}());
Graph.node = function(node){
Graph.node = function(node){ DEP('graph.node');
var soul = Node.soul(node);
if(!soul){ return }
return obj_put({}, soul, node);
}
;(function(){
Graph.to = function(graph, root, opt){
Graph.to = function(graph, root, opt){ DEP('graph.to');
if(!graph){ return }
var obj = {};
opt = opt || {seen: {}};
@ -442,5 +447,5 @@
var fn_is = Type.fn.is;
var obj = Type.obj, obj_is = obj.is, obj_del = obj.del, obj_has = obj.has, obj_empty = obj.empty, obj_put = obj.put, obj_map = obj.map, obj_copy = obj.copy;
var u;
Type.graph = Graph;
Type.graph = Type.graph || Graph;
}());