2017-02-03 20:50:45 +00:00
|
|
|
function isval(x/*:?any*/)/*:boolean*/ { return x !== undefined && x !== null; }
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function keys(o/*:any*/)/*:Array<any>*/ { return Object.keys(o); }
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function evert_key(obj/*:any*/, key/*:string*/)/*:EvertType*/ {
|
|
|
|
var o = ([]/*:any*/), K = keys(obj);
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i !== K.length; ++i) o[obj[K[i]][key]] = K[i];
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function evert(obj/*:any*/)/*:EvertType*/ {
|
|
|
|
var o = ([]/*:any*/), K = keys(obj);
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i !== K.length; ++i) o[obj[K[i]]] = K[i];
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function evert_num(obj/*:any*/)/*:EvertNumType*/ {
|
|
|
|
var o = ([]/*:any*/), K = keys(obj);
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i !== K.length; ++i) o[obj[K[i]]] = parseInt(K[i],10);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function evert_arr(obj/*:any*/)/*:EvertArrType*/ {
|
|
|
|
var o/*:EvertArrType*/ = ([]/*:any*/), K = keys(obj);
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i !== K.length; ++i) {
|
|
|
|
if(o[obj[K[i]]] == null) o[obj[K[i]]] = [];
|
|
|
|
o[obj[K[i]]].push(K[i]);
|
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
return o;
|
|
|
|
}
|
2014-05-22 12:16:51 +00:00
|
|
|
|
|
|
|
/* TODO: date1904 logic */
|
2017-02-10 19:23:01 +00:00
|
|
|
function datenum(v/*:number*/, date1904/*:?boolean*/)/*:number*/ {
|
2014-05-22 12:16:51 +00:00
|
|
|
if(date1904) v+=1462;
|
|
|
|
var epoch = Date.parse(v);
|
2014-06-29 18:29:45 +00:00
|
|
|
return (epoch + 2209161600000) / (24 * 60 * 60 * 1000);
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:50:45 +00:00
|
|
|
function cc2str(arr/*:Array<number>*/)/*:string*/ {
|
2014-06-29 18:29:45 +00:00
|
|
|
var o = "";
|
|
|
|
for(var i = 0; i != arr.length; ++i) o += String.fromCharCode(arr[i]);
|
|
|
|
return o;
|
2014-05-22 12:16:51 +00:00
|
|
|
}
|
2014-07-28 13:22:32 +00:00
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
function dup(o/*:any*/)/*:any*/ {
|
|
|
|
if(typeof JSON != 'undefined') return JSON.parse(JSON.stringify(o));
|
|
|
|
if(typeof o != 'object' || !o) return o;
|
|
|
|
var out = {};
|
|
|
|
for(var k in o) if(o.hasOwnProperty(k)) out[k] = dup(o[k]);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length < l) o+=c; return o; }
|