UNPKG

baidu-translate-service

Version:
2 lines 8.41 kB
/*! For license information please see baiduTranslateService.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.baiduTranslateService=e():t.baiduTranslateService=e()}(this,(()=>(()=>{var t={487:t=>{var e={utf8:{stringToBytes:function(t){return e.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(e.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e},bytesToString:function(t){for(var e=[],r=0;r<t.length;r++)e.push(String.fromCharCode(t[r]));return e.join("")}}};t.exports=e},12:t=>{var e,r;e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=r.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],r=0,n=0;r<t.length;r++,n+=8)e[n>>>5]|=t[r]<<24-n%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r<t.length;r++)e.push((t[r]>>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;r<t.length;r+=2)e.push(parseInt(t.substr(r,2),16));return e},bytesToBase64:function(t){for(var r=[],n=0;n<t.length;n+=3)for(var o=t[n]<<16|t[n+1]<<8|t[n+2],i=0;i<4;i++)8*n+6*i<=8*t.length?r.push(e.charAt(o>>>6*(3-i)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var r=[],n=0,o=0;n<t.length;o=++n%4)0!=o&&r.push((e.indexOf(t.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|e.indexOf(t.charAt(n))>>>6-2*o);return r}},t.exports=r},738:t=>{function e(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}t.exports=function(t){return null!=t&&(e(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&e(t.slice(0,0))}(t)||!!t._isBuffer)}},568:(t,e,r)=>{var n,o,i,u,s;n=r(12),o=r(487).utf8,i=r(738),u=r(487).bin,(s=function(t,e){t.constructor==String?t=e&&"binary"===e.encoding?u.stringToBytes(t):o.stringToBytes(t):i(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||t.constructor===Uint8Array||(t=t.toString());for(var r=n.bytesToWords(t),a=8*t.length,c=1732584193,f=-271733879,p=-1732584194,l=271733878,d=0;d<r.length;d++)r[d]=16711935&(r[d]<<8|r[d]>>>24)|4278255360&(r[d]<<24|r[d]>>>8);r[a>>>5]|=128<<a%32,r[14+(a+64>>>9<<4)]=a;var h=s._ff,y=s._gg,g=s._hh,v=s._ii;for(d=0;d<r.length;d+=16){var b=c,m=f,x=p,w=l;c=h(c,f,p,l,r[d+0],7,-680876936),l=h(l,c,f,p,r[d+1],12,-389564586),p=h(p,l,c,f,r[d+2],17,606105819),f=h(f,p,l,c,r[d+3],22,-1044525330),c=h(c,f,p,l,r[d+4],7,-176418897),l=h(l,c,f,p,r[d+5],12,1200080426),p=h(p,l,c,f,r[d+6],17,-1473231341),f=h(f,p,l,c,r[d+7],22,-45705983),c=h(c,f,p,l,r[d+8],7,1770035416),l=h(l,c,f,p,r[d+9],12,-1958414417),p=h(p,l,c,f,r[d+10],17,-42063),f=h(f,p,l,c,r[d+11],22,-1990404162),c=h(c,f,p,l,r[d+12],7,1804603682),l=h(l,c,f,p,r[d+13],12,-40341101),p=h(p,l,c,f,r[d+14],17,-1502002290),c=y(c,f=h(f,p,l,c,r[d+15],22,1236535329),p,l,r[d+1],5,-165796510),l=y(l,c,f,p,r[d+6],9,-1069501632),p=y(p,l,c,f,r[d+11],14,643717713),f=y(f,p,l,c,r[d+0],20,-373897302),c=y(c,f,p,l,r[d+5],5,-701558691),l=y(l,c,f,p,r[d+10],9,38016083),p=y(p,l,c,f,r[d+15],14,-660478335),f=y(f,p,l,c,r[d+4],20,-405537848),c=y(c,f,p,l,r[d+9],5,568446438),l=y(l,c,f,p,r[d+14],9,-1019803690),p=y(p,l,c,f,r[d+3],14,-187363961),f=y(f,p,l,c,r[d+8],20,1163531501),c=y(c,f,p,l,r[d+13],5,-1444681467),l=y(l,c,f,p,r[d+2],9,-51403784),p=y(p,l,c,f,r[d+7],14,1735328473),c=g(c,f=y(f,p,l,c,r[d+12],20,-1926607734),p,l,r[d+5],4,-378558),l=g(l,c,f,p,r[d+8],11,-2022574463),p=g(p,l,c,f,r[d+11],16,1839030562),f=g(f,p,l,c,r[d+14],23,-35309556),c=g(c,f,p,l,r[d+1],4,-1530992060),l=g(l,c,f,p,r[d+4],11,1272893353),p=g(p,l,c,f,r[d+7],16,-155497632),f=g(f,p,l,c,r[d+10],23,-1094730640),c=g(c,f,p,l,r[d+13],4,681279174),l=g(l,c,f,p,r[d+0],11,-358537222),p=g(p,l,c,f,r[d+3],16,-722521979),f=g(f,p,l,c,r[d+6],23,76029189),c=g(c,f,p,l,r[d+9],4,-640364487),l=g(l,c,f,p,r[d+12],11,-421815835),p=g(p,l,c,f,r[d+15],16,530742520),c=v(c,f=g(f,p,l,c,r[d+2],23,-995338651),p,l,r[d+0],6,-198630844),l=v(l,c,f,p,r[d+7],10,1126891415),p=v(p,l,c,f,r[d+14],15,-1416354905),f=v(f,p,l,c,r[d+5],21,-57434055),c=v(c,f,p,l,r[d+12],6,1700485571),l=v(l,c,f,p,r[d+3],10,-1894986606),p=v(p,l,c,f,r[d+10],15,-1051523),f=v(f,p,l,c,r[d+1],21,-2054922799),c=v(c,f,p,l,r[d+8],6,1873313359),l=v(l,c,f,p,r[d+15],10,-30611744),p=v(p,l,c,f,r[d+6],15,-1560198380),f=v(f,p,l,c,r[d+13],21,1309151649),c=v(c,f,p,l,r[d+4],6,-145523070),l=v(l,c,f,p,r[d+11],10,-1120210379),p=v(p,l,c,f,r[d+2],15,718787259),f=v(f,p,l,c,r[d+9],21,-343485551),c=c+b>>>0,f=f+m>>>0,p=p+x>>>0,l=l+w>>>0}return n.endian([c,f,p,l])})._ff=function(t,e,r,n,o,i,u){var s=t+(e&r|~e&n)+(o>>>0)+u;return(s<<i|s>>>32-i)+e},s._gg=function(t,e,r,n,o,i,u){var s=t+(e&n|r&~n)+(o>>>0)+u;return(s<<i|s>>>32-i)+e},s._hh=function(t,e,r,n,o,i,u){var s=t+(e^r^n)+(o>>>0)+u;return(s<<i|s>>>32-i)+e},s._ii=function(t,e,r,n,o,i,u){var s=t+(r^(e|~n))+(o>>>0)+u;return(s<<i|s>>>32-i)+e},s._blocksize=16,s._digestsize=16,t.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);var r=n.wordsToBytes(s(t,e));return e&&e.asBytes?r:e&&e.asString?u.bytesToString(r):n.bytesToHex(r)}},300:(t,e,r)=>{"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r.g)return r.g;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,n.fetch&&(e.default=n.fetch.bind(n)),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},587:t=>{"use strict";function e(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,r,n,o){r=r||"&",n=n||"=";var i={};if("string"!=typeof t||0===t.length)return i;var u=/\+/g;t=t.split(r);var s=1e3;o&&"number"==typeof o.maxKeys&&(s=o.maxKeys);var a=t.length;s>0&&a>s&&(a=s);for(var c=0;c<a;++c){var f,p,l,d,h=t[c].replace(u,"%20"),y=h.indexOf(n);y>=0?(f=h.substr(0,y),p=h.substr(y+1)):(f=h,p=""),l=decodeURIComponent(f),d=decodeURIComponent(p),e(i,l)?Array.isArray(i[l])?i[l].push(d):i[l]=[i[l],d]:i[l]=d}return i}},361:t=>{"use strict";var e=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,r,n,o){return r=r||"&",n=n||"=",null===t&&(t=void 0),"object"==typeof t?Object.keys(t).map((function(o){var i=encodeURIComponent(e(o))+n;return Array.isArray(t[o])?t[o].map((function(t){return i+encodeURIComponent(e(t))})).join(r):i+encodeURIComponent(e(t[o]))})).filter(Boolean).join(r):o?encodeURIComponent(e(o))+n+encodeURIComponent(e(t)):""}},673:(t,e,r)=>{"use strict";e.decode=e.parse=r(587),e.encode=e.stringify=r(361)},607:function(t,e,r){"use strict";var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var i=o(r(300)),u=o(r(673)),s=o(r(568)),a={appid:"",key:"",to:"",q:"",from:"auto",tts:1,dict:1,action:0};e.default=function(t){var e="".concat(Date.now()).concat(Math.random()),r=(0,s.default)("".concat(t.appid).concat(t.q).concat(e).concat(t.key));return new Promise((function(o,s){(0,i.default)("http://api.fanyi.baidu.com/api/trans/vip/translate",{headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",body:u.default.stringify(n(n(n({},a),t),{salt:e,sign:r}))}).then((function(t){return t.json()})).then(o).catch(s)}))}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}();var n=r(607);return n.default})()));