示例#1
0
  function encodeValue_(encoded) {
    // BYTES
    if (is.defined(encoded.blobValue)) {
      encoded.stringValue = encoded.blobValue.toString('base64');
      delete encoded.blobValue;
    }

    // INT64, Infinity, -Infinity, NaN types are encoded as strings
    if (is.defined(encoded.numberValue)) {
      var value = encoded.numberValue;

      if (is.infinite(value) || Number.isNaN(value) || value % 1 === 0) {
        encoded.stringValue = value.toString();
        delete encoded.numberValue;
      }
    }

    // ARRAY
    if (is.defined(encoded.listValue)) {
      encoded.listValue.values = encoded.listValue.values.map(encodeValue_);
    }

    return encoded;
  }
示例#2
0
}function int64add4(dst,a,b,c,d){var w0=(65535&a.l)+(65535&b.l)+(65535&c.l)+(65535&d.l),w1=(a.l>>>16)+(b.l>>>16)+(c.l>>>16)+(d.l>>>16)+(w0>>>16),w2=(65535&a.h)+(65535&b.h)+(65535&c.h)+(65535&d.h)+(w1>>>16),w3=(a.h>>>16)+(b.h>>>16)+(c.h>>>16)+(d.h>>>16)+(w2>>>16);dst.l=65535&w0|w1<<16,dst.h=65535&w2|w3<<16}function int64add5(dst,a,b,c,d,e){var w0=(65535&a.l)+(65535&b.l)+(65535&c.l)+(65535&d.l)+(65535&e.l),w1=(a.l>>>16)+(b.l>>>16)+(c.l>>>16)+(d.l>>>16)+(e.l>>>16)+(w0>>>16),w2=(65535&a.h)+(65535&b.h)+(65535&c.h)+(65535&d.h)+(65535&e.h)+(w1>>>16),w3=(a.h>>>16)+(b.h>>>16)+(c.h>>>16)+(d.h>>>16)+(e.h>>>16)+(w2>>>16);dst.l=65535&w0|w1<<16,dst.h=65535&w2|w3<<16}var sha512_k,hexcase=options&&"boolean"==typeof options.uppercase?options.uppercase:!1,b64pad=options&&"string"==typeof options.pad?options.pda:"=",utf8=options&&"boolean"==typeof options.utf8?options.utf8:!0;this.hex=function(s){return rstr2hex(rstr(s))},this.b64=function(s){return rstr2b64(rstr(s),b64pad)},this.any=function(s,e){return rstr2any(rstr(s),e)},this.hex_hmac=function(k,d){return rstr2hex(rstr_hmac(k,d))},this.b64_hmac=function(k,d){return rstr2b64(rstr_hmac(k,d),b64pad)},this.any_hmac=function(k,d,e){return rstr2any(rstr_hmac(k,d),e)},this.vm_test=function(){return"900150983cd24fb0d6963f7d28e17f72"===hex("abc").toLowerCase()},this.setUpperCase=function(a){return"boolean"==typeof a&&(hexcase=a),this},this.setPad=function(a){return b64pad=a||b64pad,this},this.setUTF8=function(a){return"boolean"==typeof a&&(utf8=a),this}},RMD160:function(options){function rstr(s){return s=utf8?utf8Encode(s):s,binl2rstr(binl(rstr2binl(s),8*s.length))}function rstr_hmac(key,data){key=utf8?utf8Encode(key):key,data=utf8?utf8Encode(data):data;var i,hash,bkey=rstr2binl(key),ipad=Array(16),opad=Array(16);for(bkey.length>16&&(bkey=binl(bkey,8*key.length)),i=0;16>i;i+=1)ipad[i]=909522486^bkey[i],opad[i]=1549556828^bkey[i];return hash=binl(ipad.concat(rstr2binl(data)),512+8*data.length),binl2rstr(binl(opad.concat(hash),672))}function binl2rstr(input){var i,output="",l=32*input.length;for(i=0;l>i;i+=8)output+=String.fromCharCode(255&input[i>>5]>>>i%32);return output}function binl(x,len){var T,j,i,l,A1,B1,C1,D1,E1,A2,B2,C2,D2,E2,h0=1732584193,h1=4023233417,h2=2562383102,h3=271733878,h4=3285377520;for(x[len>>5]|=128<<len%32,x[(len+64>>>9<<4)+14]=len,l=x.length,i=0;l>i;i+=16){for(A1=A2=h0,B1=B2=h1,C1=C2=h2,D1=D2=h3,E1=E2=h4,j=0;79>=j;j+=1)T=safe_add(A1,rmd160_f(j,B1,C1,D1)),T=safe_add(T,x[i+rmd160_r1[j]]),T=safe_add(T,rmd160_K1(j)),T=safe_add(bit_rol(T,rmd160_s1[j]),E1),A1=E1,E1=D1,D1=bit_rol(C1,10),C1=B1,B1=T,T=safe_add(A2,rmd160_f(79-j,B2,C2,D2)),T=safe_add(T,x[i+rmd160_r2[j]]),T=safe_add(T,rmd160_K2(j)),T=safe_add(bit_rol(T,rmd160_s2[j]),E2),A2=E2,E2=D2,D2=bit_rol(C2,10),C2=B2,B2=T;T=safe_add(h1,safe_add(C1,D2)),h1=safe_add(h2,safe_add(D1,E2)),h2=safe_add(h3,safe_add(E1,A2)),h3=safe_add(h4,safe_add(A1,B2)),h4=safe_add(h0,safe_add(B1,C2)),h0=T}return[h0,h1,h2,h3,h4]}function rmd160_f(j,x,y,z){return j>=0&&15>=j?x^y^z:j>=16&&31>=j?x&y|~x&z:j>=32&&47>=j?(x|~y)^z:j>=48&&63>=j?x&z|y&~z:j>=64&&79>=j?x^(y|~z):"rmd160_f: j out of range"}function rmd160_K1(j){return j>=0&&15>=j?0:j>=16&&31>=j?1518500249:j>=32&&47>=j?1859775393:j>=48&&63>=j?2400959708:j>=64&&79>=j?2840853838:"rmd160_K1: j out of range"}function rmd160_K2(j){return j>=0&&15>=j?1352829926:j>=16&&31>=j?1548603684:j>=32&&47>=j?1836072691:j>=48&&63>=j?2053994217:j>=64&&79>=j?0:"rmd160_K2: j out of range"}var hexcase=options&&"boolean"==typeof options.uppercase?options.uppercase:!1,b64pad=options&&"string"==typeof options.pad?options.pda:"=",utf8=options&&"boolean"==typeof options.utf8?options.utf8:!0,rmd160_r1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],rmd160_r2=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],rmd160_s1=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],rmd160_s2=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];this.hex=function(s){return rstr2hex(rstr(s,utf8))},this.b64=function(s){return rstr2b64(rstr(s,utf8),b64pad)},this.any=function(s,e){return rstr2any(rstr(s,utf8),e)},this.hex_hmac=function(k,d){return rstr2hex(rstr_hmac(k,d))},this.b64_hmac=function(k,d){return rstr2b64(rstr_hmac(k,d),b64pad)},this.any_hmac=function(k,d,e){return rstr2any(rstr_hmac(k,d),e)},this.vm_test=function(){return"900150983cd24fb0d6963f7d28e17f72"===hex("abc").toLowerCase()},this.setUpperCase=function(a){return"boolean"==typeof a&&(hexcase=a),this},this.setPad=function(a){return a!==void 0&&(b64pad=a),this},this.setUTF8=function(a){return"boolean"==typeof a&&(utf8=a),this}}},function(window){var freeExports=!1;"object"==typeof exports&&(freeExports=exports,exports&&"object"==typeof global&&global&&global===global.global&&(window=global)),"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return Hashes}):freeExports?"object"==typeof module&&module&&module.exports===freeExports?module.exports=Hashes:freeExports.Hashes=Hashes:window.Hashes=Hashes}(this)})()})(window)},{}],2:[function(require,module){"use strict";var hashes=require("jshashes"),xtend=require("xtend"),sha1=new hashes.SHA1,ohauth={};ohauth.qsString=function(obj){return Object.keys(obj).sort().map(function(key){return ohauth.percentEncode(key)+"="+ohauth.percentEncode(obj[key])}).join("&")},ohauth.stringQs=function(str){return str.split("&").reduce(function(obj,pair){var parts=pair.split("=");return obj[decodeURIComponent(parts[0])]=null===parts[1]?"":decodeURIComponent(parts[1]),obj},{})},ohauth.rawxhr=function(method,url,data,headers,callback){var xhr=new XMLHttpRequest,twoHundred=/^20\d$/;xhr.onreadystatechange=function(){if(4==xhr.readyState&&0!==xhr.status){if(!twoHundred.test(xhr.status))return callback(xhr,null);callback(null,xhr)}},xhr.onerror=function(e){return callback(e,null)},xhr.open(method,url,!0);for(var h in headers)xhr.setRequestHeader(h,headers[h]);xhr.send(data)},ohauth.xhr=function(method,url,auth,data,options,callback){var headers=options&&options.header||{"Content-Type":"application/x-www-form-urlencoded"};headers.Authorization="OAuth "+ohauth.authHeader(auth),ohauth.rawxhr(method,url,data,headers,callback)},ohauth.nonce=function(){for(var o="";6>o.length;)o+="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"[Math.floor(61*Math.random())];return o},ohauth.authHeader=function(obj){return Object.keys(obj).sort().map(function(key){return encodeURIComponent(key)+'="'+encodeURIComponent(obj[key])+'"'}).join(", ")},ohauth.timestamp=function(){return~~(+new Date/1e3)},ohauth.percentEncode=function(s){return encodeURIComponent(s).replace(/\!/g,"%21").replace(/\'/g,"%27").replace(/\*/g,"%2A").replace(/\(/g,"%28").replace(/\)/g,"%29")},ohauth.baseString=function(method,url,params){return params.oauth_signature&&delete params.oauth_signature,[method,ohauth.percentEncode(url),ohauth.percentEncode(ohauth.qsString(params))].join("&")},ohauth.signature=function(oauth_secret,token_secret,baseString){return sha1.b64_hmac(ohauth.percentEncode(oauth_secret)+"&"+ohauth.percentEncode(token_secret),baseString)},ohauth.headerGenerator=function(options){options=options||{};var consumer_key=options.consumer_key||"",consumer_secret=options.consumer_secret||"",signature_method=options.signature_method||"HMAC-SHA1",version=options.version||"1.0",token=options.token||"";return function(method,uri,extra_params){method=method.toUpperCase(),"string"==typeof extra_params&&extra_params.length>0&&(extra_params=ohauth.stringQs(extra_params));var uri_parts=uri.split("?",2),base_uri=uri_parts[0],query_params=2===uri_parts.length?ohauth.stringQs(uri_parts[1]):{},oauth_params={oauth_consumer_key:consumer_key,oauth_signature_method:signature_method,oauth_version:version,oauth_timestamp:ohauth.timestamp(),oauth_nonce:ohauth.nonce()};token&&(oauth_params.oauth_token=token);var all_params=xtend({},oauth_params,query_params,extra_params),base_str=ohauth.baseString(method,base_uri,all_params);return oauth_params.oauth_signature=ohauth.signature(consumer_secret,token,base_str),"OAuth "+ohauth.authHeader(oauth_params)}},module.exports=ohauth},{jshashes:7,xtend:3}],6:[function(require,module){module.exports=Object.keys||require("./shim")},{"./shim":8}],8:[function(require,module){(function(){"use strict";var keysShim,has=Object.prototype.hasOwnProperty,is=require("is"),forEach=require("foreach"),hasDontEnumBug=!{toString:null}.propertyIsEnumerable("toString"),dontEnums=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];keysShim=function(object){if(!is.object(object)&&!is.array(object))throw new TypeError("Object.keys called on a non-object");var name,theKeys=[];for(name in object)has.call(object,name)&&theKeys.push(name);return hasDontEnumBug&&forEach(dontEnums,function(dontEnum){has.call(object,dontEnum)&&theKeys.push(dontEnum)}),theKeys},module.exports=keysShim})()},{is:9,foreach:10}],9:[function(require,module){var objProto=Object.prototype,owns=objProto.hasOwnProperty,toString=objProto.toString,isActualNaN=function(value){return value!==value},NON_HOST_TYPES={"boolean":1,number:1,string:1,undefined:1},is=module.exports={};is.a=is.type=function(value,type){return typeof value===type},is.defined=function(value){return void 0!==value},is.empty=function(value){var key,type=toString.call(value);if("[object Array]"===type||"[object Arguments]"===type)return 0===value.length;if("[object Object]"===type){for(key in value)if(owns.call(value,key))return!1;return!0}return"[object String]"===type?""===value:!1},is.equal=function(value,other){var key,type=toString.call(value);if(type!==toString.call(other))return!1;if("[object Object]"===type){for(key in value)if(!is.equal(value[key],other[key]))return!1;return!0}if("[object Array]"===type){if(key=value.length,key!==other.length)return!1;for(;--key;)if(!is.equal(value[key],other[key]))return!1;return!0}return"[object Function]"===type?value.prototype===other.prototype:"[object Date]"===type?value.getTime()===other.getTime():value===other},is.hosted=function(value,host){var type=typeof host[value];return"object"===type?!!host[value]:!NON_HOST_TYPES[type]},is.instance=is["instanceof"]=function(value,constructor){return value instanceof constructor},is["null"]=function(value){return null===value},is.undefined=function(value){return void 0===value},is.arguments=function(value){var isStandardArguments="[object Arguments]"===toString.call(value),isOldArguments=!is.array(value)&&is.arraylike(value)&&is.object(value)&&is.fn(value.callee);return isStandardArguments||isOldArguments},is.array=function(value){return"[object Array]"===toString.call(value)},is.arguments.empty=function(value){return is.arguments(value)&&0===value.length},is.array.empty=function(value){return is.array(value)&&0===value.length},is.arraylike=function(value){return!!value&&!is.boolean(value)&&owns.call(value,"length")&&isFinite(value.length)&&is.number(value.length)&&value.length>=0},is.boolean=function(value){return"[object Boolean]"===toString.call(value)},is["false"]=function(value){return is.boolean(value)&&(value===!1||value.valueOf()===!1)},is["true"]=function(value){return is.boolean(value)&&(value===!0||value.valueOf()===!0)},is.date=function(value){return"[object Date]"===toString.call(value)},is.element=function(value){return void 0!==value&&"undefined"!=typeof HTMLElement&&value instanceof HTMLElement&&1===value.nodeType},is.error=function(value){return"[object Error]"===toString.call(value)},is.fn=is["function"]=function(value){var isAlert="undefined"!=typeof window&&value===window.alert;return isAlert||"[object Function]"===toString.call(value)},is.number=function(value){return"[object Number]"===toString.call(value)},is.infinite=function(value){return 1/0===value||value===-1/0},is.decimal=function(value){return is.number(value)&&!isActualNaN(value)&&0!==value%1},is.divisibleBy=function(value,n){var isDividendInfinite=is.infinite(value),isDivisorInfinite=is.infinite(n),isNonZeroNumber=is.number(value)&&!isActualNaN(value)&&is.number(n)&&!isActualNaN(n)&&0!==n;return isDividendInfinite||isDivisorInfinite||isNonZeroNumber&&0===value%n},is.int=function(value){return is.number(value)&&!isActualNaN(value)&&0===value%1},is.maximum=function(value,others){if(isActualNaN(value))throw new TypeError("NaN is not a valid value");if(!is.arraylike(others))throw new TypeError("second argument must be array-like");for(var len=others.length;--len>=0;)if(others[len]>value)return!1;return!0},is.minimum=function(value,others){if(isActualNaN(value))throw new TypeError("NaN is not a valid value");if(!is.arraylike(others))throw new TypeError("second argument must be array-like");for(var len=others.length;--len>=0;)if(value>others[len])return!1;return!0},is.nan=function(value){return!is.number(value)||value!==value},is.even=function(value){return is.infinite(value)||is.number(value)&&value===value&&0===value%2},is.odd=function(value){return is.infinite(value)||is.number(value)&&value===value&&0!==value%2},is.ge=function(value,other){if(isActualNaN(value)||isActualNaN(other))throw new TypeError("NaN is not a valid value");return!is.infinite(value)&&!is.infinite(other)&&value>=other},is.gt=function(value,other){if(isActualNaN(value)||isActualNaN(other))throw new TypeError("NaN is not a valid value");return!is.infinite(value)&&!is.infinite(other)&&value>other},is.le=function(value,other){if(isActualNaN(value)||isActualNaN(other))throw new TypeError("NaN is not a valid value");return!is.infinite(value)&&!is.infinite(other)&&other>=value},is.lt=function(value,other){if(isActualNaN(value)||isActualNaN(other))throw new TypeError("NaN is not a valid value");return!is.infinite(value)&&!is.infinite(other)&&other>value},is.within=function(value,start,finish){if(isActualNaN(value)||isActualNaN(start)||isActualNaN(finish))throw new TypeError("NaN is not a valid value");if(!is.number(value)||!is.number(start)||!is.number(finish))throw new TypeError("all arguments must be numbers");var isAnyInfinite=is.infinite(value)||is.infinite(start)||is.infinite(finish);return isAnyInfinite||value>=start&&finish>=value},is.object=function(value){return value&&"[object Object]"===toString.call(value)},is.hash=function(value){return is.object(value)&&value.constructor===Object&&!value.nodeType&&!value.setInterval},is.regexp=function(value){return"[object RegExp]"===toString.call(value)},is.string=function(value){return"[object String]"===toString.call(value)}},{}],10:[function(require,module){var hasOwn=Object.prototype.hasOwnProperty,toString=Object.prototype.toString;module.exports=function(obj,fn,ctx){if("[object Function]"!==toString.call(fn))throw new TypeError("iterator must be a function");var l=obj.length;if(l===+l)for(var i=0;l>i;i++)fn.call(ctx,obj[i],i,obj);else for(var k in obj)hasOwn.call(obj,k)&&fn.call(ctx,obj[k],k,obj)}},{}]},{},[1])(1)});
is.lt = function (value, other) {
  if (isActualNaN(value) || isActualNaN(other)) {
    throw new TypeError('NaN is not a valid value');
  }
  return !is.infinite(value) && !is.infinite(other) && value < other;
};
is.odd = function (value) {
  return is.infinite(value) || (is.number(value) && value === value && value % 2 !== 0);
};
is.divisibleBy = function (value, n) {
  var isDividendInfinite = is.infinite(value);
  var isDivisorInfinite = is.infinite(n);
  var isNonZeroNumber = is.number(value) && !isActualNaN(value) && is.number(n) && !isActualNaN(n) && n !== 0;
  return isDividendInfinite || isDivisorInfinite || (isNonZeroNumber && value % n === 0);
};
is.decimal = function (value) {
  return is.number(value) && !isActualNaN(value) && !is.infinite(value) && value % 1 !== 0;
};