Socket
Socket
Sign inDemoInstall

@ray-js/wechat-helper

Package Overview
Dependencies
0
Maintainers
1
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2-beta-1 to 0.1.2-beta-2

2

index.esm.js

@@ -1,1 +0,1 @@

function e(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function c(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}s((r=r.apply(e,t||[])).next())}))}function t(e,t){return(e&Math.pow(2,t))>>t==1}function n(e){if(e.length>6)throw new Error("The number of bytes exceeds 6");const t=new DataView(e.buffer);switch(e.length){case 1:return t.getInt8(0);case 2:return t.getInt16(0);case 4:return t.getInt32(0);default:{let t=r(e);const n=Math.pow(2,8*e.length)/2;return t>=n&&(t%=n,t=-1*(n-t)),t}}}function r(e){const t=new DataView(e.buffer);switch(e.length){case 0:throw new Error("data of Uint8Array is empty");case 1:return t.getUint8(0);case 2:return t.getUint16(0);case 3:return e.reduce(((e,t)=>e<<8|t),0);case 4:return t.getUint32(0);default:return parseInt(a(e),16)}}function o(e){return e.reduceRight(((e,t)=>{const n=t.toString(2).padStart(8,"0").split("").map((e=>Number(e))).reverse();return e.concat(n)}),[])}function a(e){return e.length?e.length<=4?r(e).toString(16).padStart(2*e.length,"0").toUpperCase():e.reduce(((e,t)=>(e.push(t.toString(16).padStart(2,"0")),e)),[]).join("").toUpperCase():""}function i(e){return e.length%2!=0?(console.error("Illegal Format UTF16 Code!"),""):e.reduce(((e,t)=>(e.push(String.fromCharCode(t)),e)),[]).join("")}function c(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];r<128?(t.push(String.fromCharCode(r)),n++):r>191&&r<224?(t.push(String.fromCharCode((31&r)<<6|63&e[n+1])),n+=2):(t.push(String.fromCharCode((15&r)<<12|(63&e[n+1])<<6|63&e[n+2])),n+=3)}return t.join("")}function s(e){const t=[],n=e.length;for(let r=0;r<n;r++){const n=e.charCodeAt(r);n>=65536&&n<=1114111?(t.push(n>>18&7|240),t.push(n>>12&63|128),t.push(n>>6&63|128),t.push(63&n|128)):n>=2048&&n<=65535?(t.push(n>>12&15|224),t.push(n>>6&63|128),t.push(63&n|128)):n>=128&&n<=2047?(t.push(n>>6&31|192),t.push(63&n|128)):t.push(255&n)}return new Uint8Array(t)}const u=e=>{const t=new Uint8Array(e);for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t},l=e=>{const t=[];do{let n=e%128;(e=parseInt(""+e/128))>0&&(n|=128),t.push(n)}while(e>0);return new Uint8Array(t)},f=(e,t=0)=>{let n=0,r=t;for(;r<4&&r<e.length;r++){const o=e[r];if(n|=(127&o)<<7*(r-t),0==(o>>7&1))break}return{num:n,end:r-t<4?r+1:r}},h=(e,t)=>{const n=new Uint32Array([e]),r=new Uint8Array(n.buffer);return r.reverse(),t?r.slice(4-t):r},g=(e,t)=>{const n=new Int32Array([e]),r=new Int8Array(n.buffer);return r.reverse(),t?new Uint8Array(r.slice(4-t)):new Uint8Array(r)},p=e=>{if(e.length%2!=0)throw new Error("hex length error");const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=parseInt(e.slice(2*r,2*r+2),16);return n},d="undefined"!=typeof wx?wx:"undefined"!=typeof my?my:"undefined"!=typeof ty?ty:{},v="undefined"!=typeof wx,y="undefined"!=typeof my;function C(e,t){return d[e]||t&&d[t]||(()=>{console.warn(`The Api ${e} is not found`)})}function S(e,t,n){"function"==typeof t&&(n=t,t="");const r=d[e]||t&&d[t];return r?e=>new Promise(((t,o)=>{const{success:a,fail:i}=e||{};r(Object.assign(Object.assign({},e),{success:e=>{n&&(e=n(e)),a&&a(e),t(e)},fail:e=>{i&&i(e),"undefined"!=typeof my&&e.error&&(e.errCode=e.error,e.errMsg=e.errorMessage),o(e)}}))})):()=>(console.warn(`The Api ${e} is not found`),Promise.resolve())}const B=C("getFileSystemManager"),w=S("downloadFile"),A=S("getFileInfo"),b=C("getSystemInfoSync"),m=C("getAccountInfoSync"),D=C("getAppAuthorizeSetting"),L=S("authorizeForMiniProgram"),E=S("authorize"),I=S("getBLEDeviceServices",(e=>y?{services:e.services.map((e=>({uuid:e.serviceId.toUpperCase(),isPrimary:e.isPrimary})))}:e)),U=S("getBLEDeviceCharacteristics",(e=>y?{characteristics:e.characteristics.map((e=>Object.assign(Object.assign({},e),{uuid:e.characteristicId.toUpperCase()})))}:e)),j=S("createBLEConnection","connectBLEDevice"),M=S("closeBLEConnection","disconnectBLEDevice"),O=S("startBluetoothDevicesDiscovery"),T=S("stopBluetoothDevicesDiscovery"),P=S("getBLEDeviceRSSI"),V=S("getConnectedBluetoothDevices"),F=C("onBLEConnectionStateChange","onBLEConnectionStateChanged"),_=C("offBLEConnectionStateChange","offBLEConnectionStateChanged"),k=C("onBluetoothAdapterStateChange"),x=S("notifyBLECharacteristicValueChange"),W=S("readBLECharacteristicValue"),z=S("getBLEMTU"),$=S("setBLEMTU"),H=S("getBluetoothAdapterState"),R=new Map,q=S("getBluetoothDevices",(e=>y?{devices:e.devices.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:p(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=p(e.serviceData[n]),t)),{})})))}:e)),G=S("writeBLECharacteristicValue"),K=S("createBLEPeripheralServer"),N=S("openBluetoothAdapter"),J=S("closeBluetoothAdapter"),Q=C("connectSocket"),X=S("login"),Y=S("getUserInfo"),Z=C("createUDPSocket"),ee=S("scanCode"),te=S("getSetting"),ne=S("getLocalIPAddress"),re=S("startWifi"),oe=S("stopWifi"),ae=S("getConnectedWifi"),ie=S("request"),ce=C("onAppHide"),se=C("offAppHide"),ue=C("onAppShow"),le=C("offAppShow"),fe=S("navigateToMiniProgram"),he=S("navigateTo"),ge=S("redirectTo"),pe=S("navigateBack"),de=S("reLaunch"),ve=C("setStorageSync"),ye=C("getStorageSync"),Ce=C("removeStorageSync"),Se=C("showToast"),Be=d.env||{};var we=Object.freeze({__proto__:null,isWechat:v,isAlipay:y,hasBaseApi:e=>!!d[e]||!1,getFileSystemManager:B,downloadFile:w,getFileInfo:A,getSystemInfoSync:b,getAccountInfoSync:m,getAppAuthorizeSetting:D,authorizeForMiniProgram:L,authorize:E,getBLEDeviceServices:I,getBLEDeviceCharacteristics:U,createBLEConnection:j,closeBLEConnection:M,startBluetoothDevicesDiscovery:O,stopBluetoothDevicesDiscovery:T,getBLEDeviceRSSI:P,getConnectedBluetoothDevices:V,onBLEConnectionStateChange:F,offBLEConnectionStateChange:_,onBluetoothAdapterStateChange:k,notifyBLECharacteristicValueChange:x,readBLECharacteristicValue:W,getBLEMTU:z,setBLEMTU:$,getBluetoothAdapterState:H,onBluetoothDeviceFound:e=>{if(y){const t=({devices:t})=>{const n=t.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:p(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=p(e.serviceData[n]),t)),{})})));e({devices:n})};return R.set(e,t),void d.onBluetoothDeviceFound(t)}d.onBluetoothDeviceFound(e)},offBluetoothDeviceFound:e=>{y&&R.has(e)?d.offBluetoothDeviceFound(R.get(e)):d.offBluetoothDeviceFound(e)},getBluetoothDevices:q,onBLECharacteristicValueChange:e=>{if(y){const t=t=>{e(Object.assign(Object.assign({},t),{value:p(t.value)}))};return R.set(e,t),void d.onBLECharacteristicValueChange(t)}d.onBLECharacteristicValueChange(e)},offBLECharacteristicValueChange:e=>{y&&R.has(e)?d.offBLECharacteristicValueChange(R.get(e)):d.offBLECharacteristicValueChange(e)},writeBLECharacteristicValue:G,createBLEPeripheralServer:K,openBluetoothAdapter:N,closeBluetoothAdapter:J,connectSocket:Q,login:X,getUserInfo:Y,createUDPSocket:Z,scanCode:ee,getSetting:te,getLocalIPAddress:ne,startWifi:re,stopWifi:oe,getConnectedWifi:ae,request:ie,onAppHide:ce,offAppHide:se,onAppShow:ue,offAppShow:le,navigateToMiniProgram:fe,navigateTo:he,redirectTo:ge,navigateBack:pe,reLaunch:de,setStorageSync:ve,getStorageSync:ye,removeStorageSync:Ce,showToast:Se,env:Be});const Ae=b()||{};function be(e,t=2){let n=e;return"string"==typeof e&&(n=parseInt(e)),n.toString(16).padStart(t,"0")}function me(e){const t=[];return Array.prototype.map.call(new Uint8Array(e),(function(e){t.push(be(e))})),t}function De(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2){const r=parseInt(e.slice(n,n+2),16);t.push(String.fromCharCode(r))}else for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);t.push(String.fromCharCode(r))}return t.join("")}function Le(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2)t.push(parseInt(e.slice(n,n+2),16));else if("string"==typeof e[0])for(let n=0;n<e.length;n++)t.push(parseInt(e[n],16));return new Uint8Array(t)}const Ee=(e,t=!1)=>{if(!e)return"";return Object.keys(e).reduce(((n,r)=>{const o=e[r];return void 0!==o&&n.push(`${r}=${t?encodeURIComponent(o):o}`),n}),[]).join("&")},Ie=e=>Ue(e,Ae.SDKVersion),Ue=(e,t,n=!0)=>{const r=e.split("."),o=t.split("."),a=Math.max(o.length,r.length);for(;o.length<a;)o.splice(0,0,"0");for(;r.length<a;)r.splice(0,0,"0");for(let e=0;e<a;e++){const t=parseInt(r[e]),n=parseInt(o[e]);if(t>n)return!0;if(t===n)break;return!1}return n},je=e=>e.replace(/^\S/,(function(e){return e.toUpperCase()})),Me=e=>{if(0!==e.indexOf("http")){return`https://images.tuyacn.com${/^\/[\w\W]+/.test(e)?"":"/"}${e}`}return e};function Oe(e){return"object"!=typeof e?e:Array.isArray(e)?e.map((e=>Oe(e))):Object.keys(e).reduce(((t,n)=>{const r=n.split("_").map(((e,t)=>t>0?je(e):e)).join("");let o=e[n];return Array.isArray(o)?o=o.map((e=>Oe(e))):"object"==typeof o&&(o=Oe(o)),t[r]=o,t}),{})}const Te="ios"===Ae.platform,Pe="ios"===Ae.platform,Ve=(t,n)=>e(void 0,void 0,void 0,(function*(){return new Promise((e=>{if(n){const r=t/10;let o=0;const a=setInterval((()=>{o+=r,o>=t&&(clearInterval(a),e(!0)),n()&&(clearInterval(a),e(!0))}),r)}setTimeout((()=>{e(!0)}),t)}))})),Fe=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=1&t?t>>>1^3988292384:t>>>1;Fe[e]=t}function _e(e){let t=-1;for(let n=0,r=e.length;n<r;n++)t=t>>>8^Fe[255&(t^e[n])];return-1^t}function ke(e){let t=65535;let n,r;for(n=0;n<e.length;n++)for(t^=255&e[n],r=0;r<8;r++)0!=(1&t)?(t>>=1,t^=40961):t>>=1;return t}const xe={initial_value:0,table:function(e){const t=[];for(let n=0;n<256;++n){let r=n;for(let t=0;t<8;++t)r=0!=(128&r)?(r<<1^e)%256:(r<<1)%256;t[n]=r}return t}(7)},We=e=>{let t=xe.initial_value;for(let n=0;n<e.length;n++)t=xe.table[(t^e[n])%256];return t},ze=e=>{const t=new DataView(e.buffer),n=[];for(let r=0;r<e.length;r+=4)n.push(t.getInt32(r));return n},$e=e=>{const t=new Uint8Array(4*e.length),n=new DataView(t.buffer);for(let t=0;t<e.length;t++)n.setInt32(4*t,e[t]);return t};const He={encrypt:function(e,t){const n=ze(e),r=ze(t),o=n.length-1;let a,i,c=n[o],s=n[0],u=Math.floor(6+52/(o+1)),l=0;for(;u-- >0;){l=l+2654435769&4294967295,i=l>>>2&3;let e=0;for(;e<o;e++)s=n[e+1],a=(c>>>5^s<<2)+(s>>>3^c<<4)^(l^s)+(r[3&e^i]^c),c=n[e]=n[e]+a&4294967295;s=n[0],a=(c>>>5^s<<2)+(s>>>3^c<<4)^(l^s)+(r[3&e^i]^c),c=n[o]=n[o]+a&4294967295}return $e(n)},decrypt:function(e,t){const n=ze(e),r=ze(t),o=n.length-1;let a=n[o-1],i=n[0];const c=2654435769;let s,u,l=Math.floor(6+52/(o+1))*c&4294967295;for(;0!==l;){u=l>>>2&3;let e=o;for(;e>0;e--)a=n[e-1],s=(a>>>5^i<<2)+(i>>>3^a<<4)^(l^i)+(r[3&e^u]^a),i=n[e]=n[e]-s&4294967295;a=n[o],s=(a>>>5^i<<2)+(i>>>3^a<<4)^(l^i)+(r[3&e^u]^a),i=n[0]=n[0]-s&4294967295,l=l-c&4294967295}return $e(n)}},Re=()=>{if("undefined"!=typeof globalThis)try{return globalThis.__tyGlobal={},globalThis}catch(e){}return void 0===Object.prototype.__globalData&&Object.defineProperty(Object.prototype,"__globalData",{value:{},configurable:!1,enumerable:!1}),Object.prototype.__globalData};function qe(e,t){const n=Re();return n[e]?n[e][t]:null}function Ge(e){const t=Re();return t[e]?t[e]:null}function Ke(e,t,n){const r=Re();r[e]||(r[e]={}),r[e][t]=n}function Ne(e){const t=Re();t[e]&&(t[e]={})}export{we as BaseApi,ke as CRC16,_e as CRC32,We as CRC8,me as ab2hex,t as bitToBoolean,o as bytesToBits,i as bytesToCharts,a as bytesToHex,n as bytesToInt,f as bytesToIntBy128,c as bytesToString,r as bytesToUint,Ue as checkVersion,Ie as checkWxVersion,Ne as clearCache,be as dec2hex,je as firstUpperCase,Ee as formatQuery,qe as getCache,Ge as getCacheSpace,Re as getGlobal,Me as getImageUrl,Le as hex2ab,De as hex2string,p as hexToBytes,g as intToBytes,Pe as isAndroid,Te as isIOS,Oe as keyToHump,u as randomBytes,Ke as setCache,Ve as sleep,s as stringToBytes,h as uintToBytes,l as uintToBytesBy128,He as xxtea};
function e(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function c(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}s((r=r.apply(e,t||[])).next())}))}function t(e,t){return(e&Math.pow(2,t))>>t==1}function n(e){if(e.length>6)throw new Error("The number of bytes exceeds 6");const t=new DataView(e.buffer);switch(e.length){case 1:return t.getInt8(0);case 2:return t.getInt16(0);case 4:return t.getInt32(0);default:{let t=r(e);const n=Math.pow(2,8*e.length)/2;return t>=n&&(t%=n,t=-1*(n-t)),t}}}function r(e){const t=new DataView(e.buffer);switch(e.length){case 0:throw new Error("data of Uint8Array is empty");case 1:return t.getUint8(0);case 2:return t.getUint16(0);case 3:return e.reduce(((e,t)=>e<<8|t),0);case 4:return t.getUint32(0);default:return parseInt(a(e),16)}}function o(e){return e.reduceRight(((e,t)=>{const n=t.toString(2).padStart(8,"0").split("").map((e=>Number(e))).reverse();return e.concat(n)}),[])}function a(e){return e.length?e.length<=4?r(e).toString(16).padStart(2*e.length,"0").toUpperCase():e.reduce(((e,t)=>(e.push(t.toString(16).padStart(2,"0")),e)),[]).join("").toUpperCase():""}function i(e){return e.length%2!=0?(console.error("Illegal Format UTF16 Code!"),""):e.reduce(((e,t)=>(e.push(String.fromCharCode(t)),e)),[]).join("")}function c(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];r<128?(t.push(String.fromCharCode(r)),n++):r>191&&r<224?(t.push(String.fromCharCode((31&r)<<6|63&e[n+1])),n+=2):(t.push(String.fromCharCode((15&r)<<12|(63&e[n+1])<<6|63&e[n+2])),n+=3)}return t.join("")}function s(e){const t=[],n=e.length;for(let r=0;r<n;r++){const n=e.charCodeAt(r);n>=65536&&n<=1114111?(t.push(n>>18&7|240),t.push(n>>12&63|128),t.push(n>>6&63|128),t.push(63&n|128)):n>=2048&&n<=65535?(t.push(n>>12&15|224),t.push(n>>6&63|128),t.push(63&n|128)):n>=128&&n<=2047?(t.push(n>>6&31|192),t.push(63&n|128)):t.push(255&n)}return new Uint8Array(t)}const u=e=>{const t=new Uint8Array(e);for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t},l=e=>{const t=[];do{let n=e%128;(e=parseInt(""+e/128))>0&&(n|=128),t.push(n)}while(e>0);return new Uint8Array(t)},f=(e,t=0)=>{let n=0,r=t;for(;r<4&&r<e.length;r++){const o=e[r];if(n|=(127&o)<<7*(r-t),0==(o>>7&1))break}return{num:n,end:r-t<4?r+1:r}},h=(e,t)=>{const n=new Uint32Array([e]),r=new Uint8Array(n.buffer);return r.reverse(),t?r.slice(4-t):r},g=(e,t)=>{const n=new Int32Array([e]),r=new Int8Array(n.buffer);return r.reverse(),t?new Uint8Array(r.slice(4-t)):new Uint8Array(r)},p=e=>{if(e.length%2!=0)throw new Error("hex length error");const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=parseInt(e.slice(2*r,2*r+2),16);return n},d="undefined"!=typeof wx?wx:"undefined"!=typeof my?my:"undefined"!=typeof ty?ty:{},v="undefined"!=typeof wx,y="undefined"!=typeof my;function C(e,t){return d[e]||t&&d[t]||(()=>{console.warn(`The Api ${e} is not found`)})}function S(e,t,n){"function"==typeof t&&(n=t,t="");const r=d[e]||t&&d[t];return r?e=>new Promise(((t,o)=>{const{success:a,fail:i}=e||{};r(Object.assign(Object.assign({},e),{success:e=>{n&&(e=n(e)),a&&a(e),t(e)},fail:e=>{i&&i(e),"undefined"!=typeof my&&e.error&&(e.errCode=e.error,e.errMsg=e.errorMessage),o(e)}}))})):()=>(console.warn(`The Api ${e} is not found`),Promise.resolve())}const B=C("getFileSystemManager"),w=S("downloadFile"),A=S("getFileInfo"),b=C("getSystemInfoSync"),m=C("getAccountInfoSync"),D=C("getAppAuthorizeSetting"),L=S("authorizeForMiniProgram"),E=S("authorize"),I=S("getBLEDeviceServices",(e=>y?{services:e.services.map((e=>({uuid:e.serviceId.toUpperCase(),isPrimary:e.isPrimary})))}:e)),U=S("getBLEDeviceCharacteristics",(e=>y?{characteristics:e.characteristics.map((e=>Object.assign(Object.assign({},e),{uuid:e.characteristicId.toUpperCase()})))}:e)),j=S("createBLEConnection","connectBLEDevice"),T=S("closeBLEConnection","disconnectBLEDevice"),M=S("startBluetoothDevicesDiscovery"),O=S("stopBluetoothDevicesDiscovery"),P=S("getBLEDeviceRSSI"),V=S("getConnectedBluetoothDevices"),F=C("onBLEConnectionStateChange","onBLEConnectionStateChanged"),_=C("offBLEConnectionStateChange","offBLEConnectionStateChanged"),k=C("onBluetoothAdapterStateChange"),x=S("notifyBLECharacteristicValueChange"),W=S("readBLECharacteristicValue"),z=S("getBLEMTU"),$=S("setBLEMTU"),H=S("getBluetoothAdapterState"),R=new Map,q=S("getBluetoothDevices",(e=>y?{devices:e.devices.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:p(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=p(e.serviceData[n]),t)),{})})))}:e)),G=S("writeBLECharacteristicValue"),K=S("createBLEPeripheralServer"),N=S("openBluetoothAdapter"),J=S("closeBluetoothAdapter"),Q=C("connectSocket"),X=S("login"),Y=S("getUserInfo"),Z=C("createUDPSocket"),ee=C("createTCPSocket"),te=S("scanCode"),ne=S("getSetting"),re=S("getLocalIPAddress"),oe=S("startWifi"),ae=S("stopWifi"),ie=S("getConnectedWifi"),ce=S("request"),se=C("onAppHide"),ue=C("offAppHide"),le=C("onAppShow"),fe=C("offAppShow"),he=S("navigateToMiniProgram"),ge=S("navigateTo"),pe=S("redirectTo"),de=S("navigateBack"),ve=S("reLaunch"),ye=C("setStorageSync"),Ce=C("getStorageSync"),Se=C("removeStorageSync"),Be=C("showToast"),we=d.env||{};var Ae=Object.freeze({__proto__:null,isWechat:v,isAlipay:y,hasBaseApi:e=>!!d[e]||!1,getFileSystemManager:B,downloadFile:w,getFileInfo:A,getSystemInfoSync:b,getAccountInfoSync:m,getAppAuthorizeSetting:D,authorizeForMiniProgram:L,authorize:E,getBLEDeviceServices:I,getBLEDeviceCharacteristics:U,createBLEConnection:j,closeBLEConnection:T,startBluetoothDevicesDiscovery:M,stopBluetoothDevicesDiscovery:O,getBLEDeviceRSSI:P,getConnectedBluetoothDevices:V,onBLEConnectionStateChange:F,offBLEConnectionStateChange:_,onBluetoothAdapterStateChange:k,notifyBLECharacteristicValueChange:x,readBLECharacteristicValue:W,getBLEMTU:z,setBLEMTU:$,getBluetoothAdapterState:H,onBluetoothDeviceFound:e=>{if(y){const t=({devices:t})=>{const n=t.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:p(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=p(e.serviceData[n]),t)),{})})));e({devices:n})};return R.set(e,t),void d.onBluetoothDeviceFound(t)}d.onBluetoothDeviceFound(e)},offBluetoothDeviceFound:e=>{y&&R.has(e)?d.offBluetoothDeviceFound(R.get(e)):d.offBluetoothDeviceFound(e)},getBluetoothDevices:q,onBLECharacteristicValueChange:e=>{if(y){const t=t=>{e(Object.assign(Object.assign({},t),{value:p(t.value)}))};return R.set(e,t),void d.onBLECharacteristicValueChange(t)}d.onBLECharacteristicValueChange(e)},offBLECharacteristicValueChange:e=>{y&&R.has(e)?d.offBLECharacteristicValueChange(R.get(e)):d.offBLECharacteristicValueChange(e)},writeBLECharacteristicValue:G,createBLEPeripheralServer:K,openBluetoothAdapter:N,closeBluetoothAdapter:J,connectSocket:Q,login:X,getUserInfo:Y,createUDPSocket:Z,createTCPSocket:ee,scanCode:te,getSetting:ne,getLocalIPAddress:re,startWifi:oe,stopWifi:ae,getConnectedWifi:ie,request:ce,onAppHide:se,offAppHide:ue,onAppShow:le,offAppShow:fe,navigateToMiniProgram:he,navigateTo:ge,redirectTo:pe,navigateBack:de,reLaunch:ve,setStorageSync:ye,getStorageSync:Ce,removeStorageSync:Se,showToast:Be,env:we});const be=b()||{};function me(e,t=2){let n=e;return"string"==typeof e&&(n=parseInt(e)),n.toString(16).padStart(t,"0")}function De(e){const t=[];return Array.prototype.map.call(new Uint8Array(e),(function(e){t.push(me(e))})),t}function Le(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2){const r=parseInt(e.slice(n,n+2),16);t.push(String.fromCharCode(r))}else for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);t.push(String.fromCharCode(r))}return t.join("")}function Ee(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2)t.push(parseInt(e.slice(n,n+2),16));else if("string"==typeof e[0])for(let n=0;n<e.length;n++)t.push(parseInt(e[n],16));return new Uint8Array(t)}const Ie=(e,t=!1)=>{if(!e)return"";return Object.keys(e).reduce(((n,r)=>{const o=e[r];return void 0!==o&&n.push(`${r}=${t?encodeURIComponent(o):o}`),n}),[]).join("&")},Ue=e=>je(e,be.SDKVersion),je=(e,t,n=!0)=>{const r=e.split("."),o=t.split("."),a=Math.max(o.length,r.length);for(;o.length<a;)o.splice(0,0,"0");for(;r.length<a;)r.splice(0,0,"0");for(let e=0;e<a;e++){const t=parseInt(r[e]),n=parseInt(o[e]);if(t>n)return!0;if(t===n)break;return!1}return n},Te=e=>e.replace(/^\S/,(function(e){return e.toUpperCase()})),Me=e=>{if(0!==e.indexOf("http")){return`https://images.tuyacn.com${/^\/[\w\W]+/.test(e)?"":"/"}${e}`}return e};function Oe(e){return"object"!=typeof e?e:Array.isArray(e)?e.map((e=>Oe(e))):Object.keys(e).reduce(((t,n)=>{const r=n.split("_").map(((e,t)=>t>0?Te(e):e)).join("");let o=e[n];return Array.isArray(o)?o=o.map((e=>Oe(e))):"object"==typeof o&&(o=Oe(o)),t[r]=o,t}),{})}const Pe="ios"===be.platform,Ve="ios"===be.platform,Fe=(t,n)=>e(void 0,void 0,void 0,(function*(){return new Promise((e=>{if(n){const r=t/10;let o=0;const a=setInterval((()=>{o+=r,o>=t&&(clearInterval(a),e(!0)),n()&&(clearInterval(a),e(!0))}),r)}setTimeout((()=>{e(!0)}),t)}))})),_e=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=1&t?t>>>1^3988292384:t>>>1;_e[e]=t}function ke(e){let t=-1;for(let n=0,r=e.length;n<r;n++)t=t>>>8^_e[255&(t^e[n])];return-1^t}function xe(e){let t=65535;let n,r;for(n=0;n<e.length;n++)for(t^=255&e[n],r=0;r<8;r++)0!=(1&t)?(t>>=1,t^=40961):t>>=1;return t}const We={initial_value:0,table:function(e){const t=[];for(let n=0;n<256;++n){let r=n;for(let t=0;t<8;++t)r=0!=(128&r)?(r<<1^e)%256:(r<<1)%256;t[n]=r}return t}(7)},ze=e=>{let t=We.initial_value;for(let n=0;n<e.length;n++)t=We.table[(t^e[n])%256];return t},$e=e=>{const t=new DataView(e.buffer),n=[];for(let r=0;r<e.length;r+=4)n.push(t.getInt32(r));return n},He=e=>{const t=new Uint8Array(4*e.length),n=new DataView(t.buffer);for(let t=0;t<e.length;t++)n.setInt32(4*t,e[t]);return t};const Re={encrypt:function(e,t){const n=$e(e),r=$e(t),o=n.length-1;let a,i,c=n[o],s=n[0],u=Math.floor(6+52/(o+1)),l=0;for(;u-- >0;){l=l+2654435769&4294967295,i=l>>>2&3;let e=0;for(;e<o;e++)s=n[e+1],a=(c>>>5^s<<2)+(s>>>3^c<<4)^(l^s)+(r[3&e^i]^c),c=n[e]=n[e]+a&4294967295;s=n[0],a=(c>>>5^s<<2)+(s>>>3^c<<4)^(l^s)+(r[3&e^i]^c),c=n[o]=n[o]+a&4294967295}return He(n)},decrypt:function(e,t){const n=$e(e),r=$e(t),o=n.length-1;let a=n[o-1],i=n[0];const c=2654435769;let s,u,l=Math.floor(6+52/(o+1))*c&4294967295;for(;0!==l;){u=l>>>2&3;let e=o;for(;e>0;e--)a=n[e-1],s=(a>>>5^i<<2)+(i>>>3^a<<4)^(l^i)+(r[3&e^u]^a),i=n[e]=n[e]-s&4294967295;a=n[o],s=(a>>>5^i<<2)+(i>>>3^a<<4)^(l^i)+(r[3&e^u]^a),i=n[0]=n[0]-s&4294967295,l=l-c&4294967295}return He(n)}},qe=()=>{if("undefined"!=typeof globalThis)try{return globalThis.__tyGlobal={},globalThis}catch(e){}return void 0===Object.prototype.__globalData&&Object.defineProperty(Object.prototype,"__globalData",{value:{},configurable:!1,enumerable:!1}),Object.prototype.__globalData};function Ge(e,t){const n=qe();return n[e]?n[e][t]:null}function Ke(e){const t=qe();return t[e]?t[e]:null}function Ne(e,t,n){const r=qe();r[e]||(r[e]={}),r[e][t]=n}function Je(e){const t=qe();t[e]&&(t[e]={})}export{Ae as BaseApi,xe as CRC16,ke as CRC32,ze as CRC8,De as ab2hex,t as bitToBoolean,o as bytesToBits,i as bytesToCharts,a as bytesToHex,n as bytesToInt,f as bytesToIntBy128,c as bytesToString,r as bytesToUint,je as checkVersion,Ue as checkWxVersion,Je as clearCache,me as dec2hex,Te as firstUpperCase,Ie as formatQuery,Ge as getCache,Ke as getCacheSpace,qe as getGlobal,Me as getImageUrl,Ee as hex2ab,Le as hex2string,p as hexToBytes,g as intToBytes,Ve as isAndroid,Pe as isIOS,Oe as keyToHump,u as randomBytes,Ne as setCache,Fe as sleep,s as stringToBytes,h as uintToBytes,l as uintToBytesBy128,Re as xxtea};

@@ -1,1 +0,1 @@

"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(o,a){function s(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}c((r=r.apply(e,t||[])).next())}))}function t(e){const t=new DataView(e.buffer);switch(e.length){case 0:throw new Error("data of Uint8Array is empty");case 1:return t.getUint8(0);case 2:return t.getUint16(0);case 3:return e.reduce(((e,t)=>e<<8|t),0);case 4:return t.getUint32(0);default:return parseInt(n(e),16)}}function n(e){return e.length?e.length<=4?t(e).toString(16).padStart(2*e.length,"0").toUpperCase():e.reduce(((e,t)=>(e.push(t.toString(16).padStart(2,"0")),e)),[]).join("").toUpperCase():""}Object.defineProperty(exports,"__esModule",{value:!0});const r=e=>{if(e.length%2!=0)throw new Error("hex length error");const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=parseInt(e.slice(2*r,2*r+2),16);return n},o="undefined"!=typeof wx?wx:"undefined"!=typeof my?my:"undefined"!=typeof ty?ty:{},a="undefined"!=typeof wx,s="undefined"!=typeof my;function i(e,t){return o[e]||t&&o[t]||(()=>{console.warn(`The Api ${e} is not found`)})}function c(e,t,n){"function"==typeof t&&(n=t,t="");const r=o[e]||t&&o[t];return r?e=>new Promise(((t,o)=>{const{success:a,fail:s}=e||{};r(Object.assign(Object.assign({},e),{success:e=>{n&&(e=n(e)),a&&a(e),t(e)},fail:e=>{s&&s(e),"undefined"!=typeof my&&e.error&&(e.errCode=e.error,e.errMsg=e.errorMessage),o(e)}}))})):()=>(console.warn(`The Api ${e} is not found`),Promise.resolve())}const u=i("getFileSystemManager"),l=c("downloadFile"),p=c("getFileInfo"),f=i("getSystemInfoSync"),h=i("getAccountInfoSync"),g=i("getAppAuthorizeSetting"),d=c("authorizeForMiniProgram"),y=c("authorize"),v=c("getBLEDeviceServices",(e=>s?{services:e.services.map((e=>({uuid:e.serviceId.toUpperCase(),isPrimary:e.isPrimary})))}:e)),C=c("getBLEDeviceCharacteristics",(e=>s?{characteristics:e.characteristics.map((e=>Object.assign(Object.assign({},e),{uuid:e.characteristicId.toUpperCase()})))}:e)),B=c("createBLEConnection","connectBLEDevice"),S=c("closeBLEConnection","disconnectBLEDevice"),b=c("startBluetoothDevicesDiscovery"),x=c("stopBluetoothDevicesDiscovery"),w=c("getBLEDeviceRSSI"),m=c("getConnectedBluetoothDevices"),A=i("onBLEConnectionStateChange","onBLEConnectionStateChanged"),D=i("offBLEConnectionStateChange","offBLEConnectionStateChanged"),I=i("onBluetoothAdapterStateChange"),L=c("notifyBLECharacteristicValueChange"),E=c("readBLECharacteristicValue"),T=c("getBLEMTU"),U=c("setBLEMTU"),j=c("getBluetoothAdapterState"),O=new Map,M=c("getBluetoothDevices",(e=>s?{devices:e.devices.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:r(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=r(e.serviceData[n]),t)),{})})))}:e)),V=c("writeBLECharacteristicValue"),P=c("createBLEPeripheralServer"),_=c("openBluetoothAdapter"),F=c("closeBluetoothAdapter"),k=i("connectSocket"),W=c("login"),z=c("getUserInfo"),R=i("createUDPSocket"),H=c("scanCode"),$=c("getSetting"),q=c("getLocalIPAddress"),G=c("startWifi"),K=c("stopWifi"),N=c("getConnectedWifi"),Q=c("request"),J=i("onAppHide"),X=i("offAppHide"),Y=i("onAppShow"),Z=i("offAppShow"),ee=c("navigateToMiniProgram"),te=c("navigateTo"),ne=c("redirectTo"),re=c("navigateBack"),oe=c("reLaunch"),ae=i("setStorageSync"),se=i("getStorageSync"),ie=i("removeStorageSync"),ce=i("showToast"),ue=o.env||{};var le=Object.freeze({__proto__:null,isWechat:a,isAlipay:s,hasBaseApi:e=>!!o[e]||!1,getFileSystemManager:u,downloadFile:l,getFileInfo:p,getSystemInfoSync:f,getAccountInfoSync:h,getAppAuthorizeSetting:g,authorizeForMiniProgram:d,authorize:y,getBLEDeviceServices:v,getBLEDeviceCharacteristics:C,createBLEConnection:B,closeBLEConnection:S,startBluetoothDevicesDiscovery:b,stopBluetoothDevicesDiscovery:x,getBLEDeviceRSSI:w,getConnectedBluetoothDevices:m,onBLEConnectionStateChange:A,offBLEConnectionStateChange:D,onBluetoothAdapterStateChange:I,notifyBLECharacteristicValueChange:L,readBLECharacteristicValue:E,getBLEMTU:T,setBLEMTU:U,getBluetoothAdapterState:j,onBluetoothDeviceFound:e=>{if(s){const t=({devices:t})=>{const n=t.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:r(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=r(e.serviceData[n]),t)),{})})));e({devices:n})};return O.set(e,t),void o.onBluetoothDeviceFound(t)}o.onBluetoothDeviceFound(e)},offBluetoothDeviceFound:e=>{s&&O.has(e)?o.offBluetoothDeviceFound(O.get(e)):o.offBluetoothDeviceFound(e)},getBluetoothDevices:M,onBLECharacteristicValueChange:e=>{if(s){const t=t=>{e(Object.assign(Object.assign({},t),{value:r(t.value)}))};return O.set(e,t),void o.onBLECharacteristicValueChange(t)}o.onBLECharacteristicValueChange(e)},offBLECharacteristicValueChange:e=>{s&&O.has(e)?o.offBLECharacteristicValueChange(O.get(e)):o.offBLECharacteristicValueChange(e)},writeBLECharacteristicValue:V,createBLEPeripheralServer:P,openBluetoothAdapter:_,closeBluetoothAdapter:F,connectSocket:k,login:W,getUserInfo:z,createUDPSocket:R,scanCode:H,getSetting:$,getLocalIPAddress:q,startWifi:G,stopWifi:K,getConnectedWifi:N,request:Q,onAppHide:J,offAppHide:X,onAppShow:Y,offAppShow:Z,navigateToMiniProgram:ee,navigateTo:te,redirectTo:ne,navigateBack:re,reLaunch:oe,setStorageSync:ae,getStorageSync:se,removeStorageSync:ie,showToast:ce,env:ue});const pe=f()||{};function fe(e,t=2){let n=e;return"string"==typeof e&&(n=parseInt(e)),n.toString(16).padStart(t,"0")}const he=(e,t,n=!0)=>{const r=e.split("."),o=t.split("."),a=Math.max(o.length,r.length);for(;o.length<a;)o.splice(0,0,"0");for(;r.length<a;)r.splice(0,0,"0");for(let e=0;e<a;e++){const t=parseInt(r[e]),n=parseInt(o[e]);if(t>n)return!0;if(t===n)break;return!1}return n},ge=e=>e.replace(/^\S/,(function(e){return e.toUpperCase()}));const de="ios"===pe.platform,ye="ios"===pe.platform,ve=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=1&t?t>>>1^3988292384:t>>>1;ve[e]=t}const Ce={initial_value:0,table:function(e){const t=[];for(let n=0;n<256;++n){let r=n;for(let t=0;t<8;++t)r=0!=(128&r)?(r<<1^e)%256:(r<<1)%256;t[n]=r}return t}(7)},Be=e=>{const t=new DataView(e.buffer),n=[];for(let r=0;r<e.length;r+=4)n.push(t.getInt32(r));return n},Se=e=>{const t=new Uint8Array(4*e.length),n=new DataView(t.buffer);for(let t=0;t<e.length;t++)n.setInt32(4*t,e[t]);return t};const be={encrypt:function(e,t){const n=Be(e),r=Be(t),o=n.length-1;let a,s,i=n[o],c=n[0],u=Math.floor(6+52/(o+1)),l=0;for(;u-- >0;){l=l+2654435769&4294967295,s=l>>>2&3;let e=0;for(;e<o;e++)c=n[e+1],a=(i>>>5^c<<2)+(c>>>3^i<<4)^(l^c)+(r[3&e^s]^i),i=n[e]=n[e]+a&4294967295;c=n[0],a=(i>>>5^c<<2)+(c>>>3^i<<4)^(l^c)+(r[3&e^s]^i),i=n[o]=n[o]+a&4294967295}return Se(n)},decrypt:function(e,t){const n=Be(e),r=Be(t),o=n.length-1;let a=n[o-1],s=n[0];const i=2654435769;let c,u,l=Math.floor(6+52/(o+1))*i&4294967295;for(;0!==l;){u=l>>>2&3;let e=o;for(;e>0;e--)a=n[e-1],c=(a>>>5^s<<2)+(s>>>3^a<<4)^(l^s)+(r[3&e^u]^a),s=n[e]=n[e]-c&4294967295;a=n[o],c=(a>>>5^s<<2)+(s>>>3^a<<4)^(l^s)+(r[3&e^u]^a),s=n[0]=n[0]-c&4294967295,l=l-i&4294967295}return Se(n)}},xe=()=>{if("undefined"!=typeof globalThis)try{return globalThis.__tyGlobal={},globalThis}catch(e){}return void 0===Object.prototype.__globalData&&Object.defineProperty(Object.prototype,"__globalData",{value:{},configurable:!1,enumerable:!1}),Object.prototype.__globalData};exports.BaseApi=le,exports.CRC16=function(e){let t,n,r=65535;for(t=0;t<e.length;t++)for(r^=255&e[t],n=0;n<8;n++)0!=(1&r)?(r>>=1,r^=40961):r>>=1;return r},exports.CRC32=function(e){let t=-1;for(let n=0,r=e.length;n<r;n++)t=t>>>8^ve[255&(t^e[n])];return-1^t},exports.CRC8=e=>{let t=Ce.initial_value;for(let n=0;n<e.length;n++)t=Ce.table[(t^e[n])%256];return t},exports.ab2hex=function(e){const t=[];return Array.prototype.map.call(new Uint8Array(e),(function(e){t.push(fe(e))})),t},exports.bitToBoolean=function(e,t){return(e&Math.pow(2,t))>>t==1},exports.bytesToBits=function(e){return e.reduceRight(((e,t)=>{const n=t.toString(2).padStart(8,"0").split("").map((e=>Number(e))).reverse();return e.concat(n)}),[])},exports.bytesToCharts=function(e){return e.length%2!=0?(console.error("Illegal Format UTF16 Code!"),""):e.reduce(((e,t)=>(e.push(String.fromCharCode(t)),e)),[]).join("")},exports.bytesToHex=n,exports.bytesToInt=function(e){if(e.length>6)throw new Error("The number of bytes exceeds 6");const n=new DataView(e.buffer);switch(e.length){case 1:return n.getInt8(0);case 2:return n.getInt16(0);case 4:return n.getInt32(0);default:{let n=t(e);const r=Math.pow(2,8*e.length)/2;return n>=r&&(n%=r,n=-1*(r-n)),n}}},exports.bytesToIntBy128=(e,t=0)=>{let n=0,r=t;for(;r<4&&r<e.length;r++){const o=e[r];if(n|=(127&o)<<7*(r-t),0==(o>>7&1))break}return{num:n,end:r-t<4?r+1:r}},exports.bytesToString=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];r<128?(t.push(String.fromCharCode(r)),n++):r>191&&r<224?(t.push(String.fromCharCode((31&r)<<6|63&e[n+1])),n+=2):(t.push(String.fromCharCode((15&r)<<12|(63&e[n+1])<<6|63&e[n+2])),n+=3)}return t.join("")},exports.bytesToUint=t,exports.checkVersion=he,exports.checkWxVersion=e=>he(e,pe.SDKVersion),exports.clearCache=function(e){const t=xe();t[e]&&(t[e]={})},exports.dec2hex=fe,exports.firstUpperCase=ge,exports.formatQuery=(e,t=!1)=>{if(!e)return"";return Object.keys(e).reduce(((n,r)=>{const o=e[r];return void 0!==o&&n.push(`${r}=${t?encodeURIComponent(o):o}`),n}),[]).join("&")},exports.getCache=function(e,t){const n=xe();return n[e]?n[e][t]:null},exports.getCacheSpace=function(e){const t=xe();return t[e]?t[e]:null},exports.getGlobal=xe,exports.getImageUrl=e=>{if(0!==e.indexOf("http")){return`https://images.tuyacn.com${/^\/[\w\W]+/.test(e)?"":"/"}${e}`}return e},exports.hex2ab=function(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2)t.push(parseInt(e.slice(n,n+2),16));else if("string"==typeof e[0])for(let n=0;n<e.length;n++)t.push(parseInt(e[n],16));return new Uint8Array(t)},exports.hex2string=function(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2){const r=parseInt(e.slice(n,n+2),16);t.push(String.fromCharCode(r))}else for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);t.push(String.fromCharCode(r))}return t.join("")},exports.hexToBytes=r,exports.intToBytes=(e,t)=>{const n=new Int32Array([e]),r=new Int8Array(n.buffer);return r.reverse(),t?new Uint8Array(r.slice(4-t)):new Uint8Array(r)},exports.isAndroid=ye,exports.isIOS=de,exports.keyToHump=function e(t){return"object"!=typeof t?t:Array.isArray(t)?t.map((t=>e(t))):Object.keys(t).reduce(((n,r)=>{const o=r.split("_").map(((e,t)=>t>0?ge(e):e)).join("");let a=t[r];return Array.isArray(a)?a=a.map((t=>e(t))):"object"==typeof a&&(a=e(a)),n[o]=a,n}),{})},exports.randomBytes=e=>{const t=new Uint8Array(e);for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t},exports.setCache=function(e,t,n){const r=xe();r[e]||(r[e]={}),r[e][t]=n},exports.sleep=(t,n)=>e(void 0,void 0,void 0,(function*(){return new Promise((e=>{if(n){const r=t/10;let o=0;const a=setInterval((()=>{o+=r,o>=t&&(clearInterval(a),e(!0)),n()&&(clearInterval(a),e(!0))}),r)}setTimeout((()=>{e(!0)}),t)}))})),exports.stringToBytes=function(e){const t=[],n=e.length;for(let r=0;r<n;r++){const n=e.charCodeAt(r);n>=65536&&n<=1114111?(t.push(n>>18&7|240),t.push(n>>12&63|128),t.push(n>>6&63|128),t.push(63&n|128)):n>=2048&&n<=65535?(t.push(n>>12&15|224),t.push(n>>6&63|128),t.push(63&n|128)):n>=128&&n<=2047?(t.push(n>>6&31|192),t.push(63&n|128)):t.push(255&n)}return new Uint8Array(t)},exports.uintToBytes=(e,t)=>{const n=new Uint32Array([e]),r=new Uint8Array(n.buffer);return r.reverse(),t?r.slice(4-t):r},exports.uintToBytesBy128=e=>{const t=[];do{let n=e%128;(e=parseInt(""+e/128))>0&&(n|=128),t.push(n)}while(e>0);return new Uint8Array(t)},exports.xxtea=be;
"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(o,a){function s(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}c((r=r.apply(e,t||[])).next())}))}function t(e){const t=new DataView(e.buffer);switch(e.length){case 0:throw new Error("data of Uint8Array is empty");case 1:return t.getUint8(0);case 2:return t.getUint16(0);case 3:return e.reduce(((e,t)=>e<<8|t),0);case 4:return t.getUint32(0);default:return parseInt(n(e),16)}}function n(e){return e.length?e.length<=4?t(e).toString(16).padStart(2*e.length,"0").toUpperCase():e.reduce(((e,t)=>(e.push(t.toString(16).padStart(2,"0")),e)),[]).join("").toUpperCase():""}Object.defineProperty(exports,"__esModule",{value:!0});const r=e=>{if(e.length%2!=0)throw new Error("hex length error");const t=e.length/2,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=parseInt(e.slice(2*r,2*r+2),16);return n},o="undefined"!=typeof wx?wx:"undefined"!=typeof my?my:"undefined"!=typeof ty?ty:{},a="undefined"!=typeof wx,s="undefined"!=typeof my;function i(e,t){return o[e]||t&&o[t]||(()=>{console.warn(`The Api ${e} is not found`)})}function c(e,t,n){"function"==typeof t&&(n=t,t="");const r=o[e]||t&&o[t];return r?e=>new Promise(((t,o)=>{const{success:a,fail:s}=e||{};r(Object.assign(Object.assign({},e),{success:e=>{n&&(e=n(e)),a&&a(e),t(e)},fail:e=>{s&&s(e),"undefined"!=typeof my&&e.error&&(e.errCode=e.error,e.errMsg=e.errorMessage),o(e)}}))})):()=>(console.warn(`The Api ${e} is not found`),Promise.resolve())}const u=i("getFileSystemManager"),l=c("downloadFile"),p=c("getFileInfo"),f=i("getSystemInfoSync"),h=i("getAccountInfoSync"),g=i("getAppAuthorizeSetting"),d=c("authorizeForMiniProgram"),y=c("authorize"),v=c("getBLEDeviceServices",(e=>s?{services:e.services.map((e=>({uuid:e.serviceId.toUpperCase(),isPrimary:e.isPrimary})))}:e)),C=c("getBLEDeviceCharacteristics",(e=>s?{characteristics:e.characteristics.map((e=>Object.assign(Object.assign({},e),{uuid:e.characteristicId.toUpperCase()})))}:e)),B=c("createBLEConnection","connectBLEDevice"),S=c("closeBLEConnection","disconnectBLEDevice"),b=c("startBluetoothDevicesDiscovery"),x=c("stopBluetoothDevicesDiscovery"),w=c("getBLEDeviceRSSI"),m=c("getConnectedBluetoothDevices"),A=i("onBLEConnectionStateChange","onBLEConnectionStateChanged"),D=i("offBLEConnectionStateChange","offBLEConnectionStateChanged"),I=i("onBluetoothAdapterStateChange"),L=c("notifyBLECharacteristicValueChange"),E=c("readBLECharacteristicValue"),T=c("getBLEMTU"),U=c("setBLEMTU"),j=c("getBluetoothAdapterState"),O=new Map,M=c("getBluetoothDevices",(e=>s?{devices:e.devices.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:r(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=r(e.serviceData[n]),t)),{})})))}:e)),P=c("writeBLECharacteristicValue"),V=c("createBLEPeripheralServer"),k=c("openBluetoothAdapter"),_=c("closeBluetoothAdapter"),F=i("connectSocket"),W=c("login"),z=c("getUserInfo"),R=i("createUDPSocket"),H=i("createTCPSocket"),$=c("scanCode"),q=c("getSetting"),G=c("getLocalIPAddress"),K=c("startWifi"),N=c("stopWifi"),Q=c("getConnectedWifi"),J=c("request"),X=i("onAppHide"),Y=i("offAppHide"),Z=i("onAppShow"),ee=i("offAppShow"),te=c("navigateToMiniProgram"),ne=c("navigateTo"),re=c("redirectTo"),oe=c("navigateBack"),ae=c("reLaunch"),se=i("setStorageSync"),ie=i("getStorageSync"),ce=i("removeStorageSync"),ue=i("showToast"),le=o.env||{};var pe=Object.freeze({__proto__:null,isWechat:a,isAlipay:s,hasBaseApi:e=>!!o[e]||!1,getFileSystemManager:u,downloadFile:l,getFileInfo:p,getSystemInfoSync:f,getAccountInfoSync:h,getAppAuthorizeSetting:g,authorizeForMiniProgram:d,authorize:y,getBLEDeviceServices:v,getBLEDeviceCharacteristics:C,createBLEConnection:B,closeBLEConnection:S,startBluetoothDevicesDiscovery:b,stopBluetoothDevicesDiscovery:x,getBLEDeviceRSSI:w,getConnectedBluetoothDevices:m,onBLEConnectionStateChange:A,offBLEConnectionStateChange:D,onBluetoothAdapterStateChange:I,notifyBLECharacteristicValueChange:L,readBLECharacteristicValue:E,getBLEMTU:T,setBLEMTU:U,getBluetoothAdapterState:j,onBluetoothDeviceFound:e=>{if(s){const t=({devices:t})=>{const n=t.map((e=>Object.assign(Object.assign({},e),{connectable:void 0===e.connectable||e.connectable,advertisData:r(e.advertisData),serviceData:Object.keys(e.serviceData||{}).reduce(((t,n)=>(t[n]=r(e.serviceData[n]),t)),{})})));e({devices:n})};return O.set(e,t),void o.onBluetoothDeviceFound(t)}o.onBluetoothDeviceFound(e)},offBluetoothDeviceFound:e=>{s&&O.has(e)?o.offBluetoothDeviceFound(O.get(e)):o.offBluetoothDeviceFound(e)},getBluetoothDevices:M,onBLECharacteristicValueChange:e=>{if(s){const t=t=>{e(Object.assign(Object.assign({},t),{value:r(t.value)}))};return O.set(e,t),void o.onBLECharacteristicValueChange(t)}o.onBLECharacteristicValueChange(e)},offBLECharacteristicValueChange:e=>{s&&O.has(e)?o.offBLECharacteristicValueChange(O.get(e)):o.offBLECharacteristicValueChange(e)},writeBLECharacteristicValue:P,createBLEPeripheralServer:V,openBluetoothAdapter:k,closeBluetoothAdapter:_,connectSocket:F,login:W,getUserInfo:z,createUDPSocket:R,createTCPSocket:H,scanCode:$,getSetting:q,getLocalIPAddress:G,startWifi:K,stopWifi:N,getConnectedWifi:Q,request:J,onAppHide:X,offAppHide:Y,onAppShow:Z,offAppShow:ee,navigateToMiniProgram:te,navigateTo:ne,redirectTo:re,navigateBack:oe,reLaunch:ae,setStorageSync:se,getStorageSync:ie,removeStorageSync:ce,showToast:ue,env:le});const fe=f()||{};function he(e,t=2){let n=e;return"string"==typeof e&&(n=parseInt(e)),n.toString(16).padStart(t,"0")}const ge=(e,t,n=!0)=>{const r=e.split("."),o=t.split("."),a=Math.max(o.length,r.length);for(;o.length<a;)o.splice(0,0,"0");for(;r.length<a;)r.splice(0,0,"0");for(let e=0;e<a;e++){const t=parseInt(r[e]),n=parseInt(o[e]);if(t>n)return!0;if(t===n)break;return!1}return n},de=e=>e.replace(/^\S/,(function(e){return e.toUpperCase()}));const ye="ios"===fe.platform,ve="ios"===fe.platform,Ce=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t=1&t?t>>>1^3988292384:t>>>1;Ce[e]=t}const Be={initial_value:0,table:function(e){const t=[];for(let n=0;n<256;++n){let r=n;for(let t=0;t<8;++t)r=0!=(128&r)?(r<<1^e)%256:(r<<1)%256;t[n]=r}return t}(7)},Se=e=>{const t=new DataView(e.buffer),n=[];for(let r=0;r<e.length;r+=4)n.push(t.getInt32(r));return n},be=e=>{const t=new Uint8Array(4*e.length),n=new DataView(t.buffer);for(let t=0;t<e.length;t++)n.setInt32(4*t,e[t]);return t};const xe={encrypt:function(e,t){const n=Se(e),r=Se(t),o=n.length-1;let a,s,i=n[o],c=n[0],u=Math.floor(6+52/(o+1)),l=0;for(;u-- >0;){l=l+2654435769&4294967295,s=l>>>2&3;let e=0;for(;e<o;e++)c=n[e+1],a=(i>>>5^c<<2)+(c>>>3^i<<4)^(l^c)+(r[3&e^s]^i),i=n[e]=n[e]+a&4294967295;c=n[0],a=(i>>>5^c<<2)+(c>>>3^i<<4)^(l^c)+(r[3&e^s]^i),i=n[o]=n[o]+a&4294967295}return be(n)},decrypt:function(e,t){const n=Se(e),r=Se(t),o=n.length-1;let a=n[o-1],s=n[0];const i=2654435769;let c,u,l=Math.floor(6+52/(o+1))*i&4294967295;for(;0!==l;){u=l>>>2&3;let e=o;for(;e>0;e--)a=n[e-1],c=(a>>>5^s<<2)+(s>>>3^a<<4)^(l^s)+(r[3&e^u]^a),s=n[e]=n[e]-c&4294967295;a=n[o],c=(a>>>5^s<<2)+(s>>>3^a<<4)^(l^s)+(r[3&e^u]^a),s=n[0]=n[0]-c&4294967295,l=l-i&4294967295}return be(n)}},we=()=>{if("undefined"!=typeof globalThis)try{return globalThis.__tyGlobal={},globalThis}catch(e){}return void 0===Object.prototype.__globalData&&Object.defineProperty(Object.prototype,"__globalData",{value:{},configurable:!1,enumerable:!1}),Object.prototype.__globalData};exports.BaseApi=pe,exports.CRC16=function(e){let t,n,r=65535;for(t=0;t<e.length;t++)for(r^=255&e[t],n=0;n<8;n++)0!=(1&r)?(r>>=1,r^=40961):r>>=1;return r},exports.CRC32=function(e){let t=-1;for(let n=0,r=e.length;n<r;n++)t=t>>>8^Ce[255&(t^e[n])];return-1^t},exports.CRC8=e=>{let t=Be.initial_value;for(let n=0;n<e.length;n++)t=Be.table[(t^e[n])%256];return t},exports.ab2hex=function(e){const t=[];return Array.prototype.map.call(new Uint8Array(e),(function(e){t.push(he(e))})),t},exports.bitToBoolean=function(e,t){return(e&Math.pow(2,t))>>t==1},exports.bytesToBits=function(e){return e.reduceRight(((e,t)=>{const n=t.toString(2).padStart(8,"0").split("").map((e=>Number(e))).reverse();return e.concat(n)}),[])},exports.bytesToCharts=function(e){return e.length%2!=0?(console.error("Illegal Format UTF16 Code!"),""):e.reduce(((e,t)=>(e.push(String.fromCharCode(t)),e)),[]).join("")},exports.bytesToHex=n,exports.bytesToInt=function(e){if(e.length>6)throw new Error("The number of bytes exceeds 6");const n=new DataView(e.buffer);switch(e.length){case 1:return n.getInt8(0);case 2:return n.getInt16(0);case 4:return n.getInt32(0);default:{let n=t(e);const r=Math.pow(2,8*e.length)/2;return n>=r&&(n%=r,n=-1*(r-n)),n}}},exports.bytesToIntBy128=(e,t=0)=>{let n=0,r=t;for(;r<4&&r<e.length;r++){const o=e[r];if(n|=(127&o)<<7*(r-t),0==(o>>7&1))break}return{num:n,end:r-t<4?r+1:r}},exports.bytesToString=function(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];r<128?(t.push(String.fromCharCode(r)),n++):r>191&&r<224?(t.push(String.fromCharCode((31&r)<<6|63&e[n+1])),n+=2):(t.push(String.fromCharCode((15&r)<<12|(63&e[n+1])<<6|63&e[n+2])),n+=3)}return t.join("")},exports.bytesToUint=t,exports.checkVersion=ge,exports.checkWxVersion=e=>ge(e,fe.SDKVersion),exports.clearCache=function(e){const t=we();t[e]&&(t[e]={})},exports.dec2hex=he,exports.firstUpperCase=de,exports.formatQuery=(e,t=!1)=>{if(!e)return"";return Object.keys(e).reduce(((n,r)=>{const o=e[r];return void 0!==o&&n.push(`${r}=${t?encodeURIComponent(o):o}`),n}),[]).join("&")},exports.getCache=function(e,t){const n=we();return n[e]?n[e][t]:null},exports.getCacheSpace=function(e){const t=we();return t[e]?t[e]:null},exports.getGlobal=we,exports.getImageUrl=e=>{if(0!==e.indexOf("http")){return`https://images.tuyacn.com${/^\/[\w\W]+/.test(e)?"":"/"}${e}`}return e},exports.hex2ab=function(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2)t.push(parseInt(e.slice(n,n+2),16));else if("string"==typeof e[0])for(let n=0;n<e.length;n++)t.push(parseInt(e[n],16));return new Uint8Array(t)},exports.hex2string=function(e){const t=[];if("string"==typeof e)for(let n=0;n<e.length;n+=2){const r=parseInt(e.slice(n,n+2),16);t.push(String.fromCharCode(r))}else for(let n=0;n<e.length;n++){const r=parseInt(e[n],16);t.push(String.fromCharCode(r))}return t.join("")},exports.hexToBytes=r,exports.intToBytes=(e,t)=>{const n=new Int32Array([e]),r=new Int8Array(n.buffer);return r.reverse(),t?new Uint8Array(r.slice(4-t)):new Uint8Array(r)},exports.isAndroid=ve,exports.isIOS=ye,exports.keyToHump=function e(t){return"object"!=typeof t?t:Array.isArray(t)?t.map((t=>e(t))):Object.keys(t).reduce(((n,r)=>{const o=r.split("_").map(((e,t)=>t>0?de(e):e)).join("");let a=t[r];return Array.isArray(a)?a=a.map((t=>e(t))):"object"==typeof a&&(a=e(a)),n[o]=a,n}),{})},exports.randomBytes=e=>{const t=new Uint8Array(e);for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t},exports.setCache=function(e,t,n){const r=we();r[e]||(r[e]={}),r[e][t]=n},exports.sleep=(t,n)=>e(void 0,void 0,void 0,(function*(){return new Promise((e=>{if(n){const r=t/10;let o=0;const a=setInterval((()=>{o+=r,o>=t&&(clearInterval(a),e(!0)),n()&&(clearInterval(a),e(!0))}),r)}setTimeout((()=>{e(!0)}),t)}))})),exports.stringToBytes=function(e){const t=[],n=e.length;for(let r=0;r<n;r++){const n=e.charCodeAt(r);n>=65536&&n<=1114111?(t.push(n>>18&7|240),t.push(n>>12&63|128),t.push(n>>6&63|128),t.push(63&n|128)):n>=2048&&n<=65535?(t.push(n>>12&15|224),t.push(n>>6&63|128),t.push(63&n|128)):n>=128&&n<=2047?(t.push(n>>6&31|192),t.push(63&n|128)):t.push(255&n)}return new Uint8Array(t)},exports.uintToBytes=(e,t)=>{const n=new Uint32Array([e]),r=new Uint8Array(n.buffer);return r.reverse(),t?r.slice(4-t):r},exports.uintToBytesBy128=e=>{const t=[];do{let n=e%128;(e=parseInt(""+e/128))>0&&(n|=128),t.push(n)}while(e>0);return new Uint8Array(t)},exports.xxtea=xe;
{
"name": "@ray-js/wechat-helper",
"version": "0.1.2-beta-1",
"version": "0.1.2-beta-2",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public",

@@ -95,3 +95,49 @@ declare type Callback = (...data: any[]) => void;

export declare const getUserInfo: (() => Promise<any>) | ((option?: any, ...rest: any[]) => Promise<any>);
export declare const createUDPSocket: (() => any) | ((option?: any, ...rest: any[]) => any);
export interface UDPScoket {
bind(port: number): number;
setTTL(ttl: number): void;
send(opt: {
address: string;
port: number;
message: string | ArrayBuffer;
offset?: number;
length?: number;
setBroadcast?: boolean;
}): void;
connect(opt: {
address: string;
port: number;
}): void;
write(): void;
close(): void;
onClose(listener: Callback): void;
offClose(listener: Callback): void;
onError(listener: Callback): void;
offError(listener: Callback): void;
onListening(listener: Callback): void;
offListening(listener: Callback): void;
onMessage(listener: Callback): void;
offMessage(listener: Callback): void;
}
export declare const createUDPSocket: () => UDPScoket;
export interface TCPSocket {
connect(option: {
address: string;
port: number;
timeout?: number;
}): void;
write(data: string | ArrayBuffer): void;
close(): void;
onClose(cb: Callback): void;
offClose(cb: Callback): void;
onConnect(cb: Callback): void;
offConnect(cb: Callback): void;
onError(cb: Callback): void;
offError(cb: Callback): void;
onMessage(cb: Callback): void;
offMessage(cb: Callback): void;
onBindWifi(cb: Callback): void;
offBindWifi(cb: Callback): void;
}
export declare const createTCPSocket: () => TCPSocket;
export declare const scanCode: (() => Promise<any>) | ((option?: any, ...rest: any[]) => Promise<any>);

@@ -98,0 +144,0 @@ export declare const getSetting: (() => Promise<any>) | ((option?: any, ...rest: any[]) => Promise<any>);

@@ -1,73 +0,11 @@

/**
* 对字节数据做处理
*/
/**
*
* @param data 无符号整形数据
* @param offset
* @returns
*/
export declare function bitToBoolean(data: number, offset: number): boolean;
/**
* 大端格式 字节数转为有符号位数据
* @param data
* @returns
*/
export declare function bytesToInt(data: Uint8Array): number;
/**
* 大端格式 字节数组转为无符号位数据
*
* @param data
* @returns
*/
export declare function bytesToUint(data: Uint8Array): number;
/**
* 大端格式 区取字节数据的比特位数据
* 注意:比特位的低到高位顺序与返回数组的下标顺序一致
* @param data
* @returns
*/
export declare function bytesToBits(data: Uint8Array): (0 | 1)[];
/**
* 大端格式 字节转为16进制字符串
* @param data
* @returns
*/
export declare function bytesToHex(data: Uint8Array): string;
/**
* 大端格式 字节转为字符
* @param hex
* @returns
*/
export declare function bytesToCharts(data: Uint8Array): string;
/**
* 字节转为UTF8格式字符串
* @param bytes 字节数据
* @returns
*/
export declare function bytesToString(bytes: Uint8Array): string;
/**
* 字符串转为字节
* @param str
* @returns
*/
export declare function stringToBytes(str: string): Uint8Array;
/**
* 生成一组随机的比特数据
* @param size
*/
export declare const randomBytes: (size: number) => Uint8Array;
/**
* 将可变长度整数转为字节
* @param value
* @returns
*/
export declare const uintToBytesBy128: (value: number) => Uint8Array;
/**
* 获取可变长度整数
* 每个字节的最高位为1时,表示下一个字节仍然是某个属性的数据
* @param data
* @param offset 偏移量
* @returns
*/
export declare const bytesToIntBy128: (data: Uint8Array, offset?: number) => {

@@ -77,20 +15,4 @@ num: number;

};
/**
* 数值转为字节,大端格式
* @param value 数值,最大支持32位数值
* @param byteLength 指定输出的字节数,不指定则为输出4个字节(即32位数值对应的字节数)
*/
export declare const uintToBytes: (value: number, byteLength?: number) => Uint8Array;
/**
* 有符号数值转为二进制数据
* @param data 有符号数值
* @param byteLength 位长度,可为8,16,32,64, 默认为32
* @returns
*/
export declare const intToBytes: (data: number, byteLength?: number) => Uint8Array;
/**
* 将 hex 字符串转为字节数据
* @param value
* @returns
*/
export declare const hexToBytes: (value: string) => Uint8Array;

@@ -1,30 +0,6 @@

/**
* 统一 global 管理
*/
export declare const getGlobal: () => Record<string, any>;
/**
* 获取缓存
* @param spaceName
* @param key
* @returns
*/
declare function getCache<T>(spaceName: string, key: string): T | null;
/**
* 获取某个空间的所有数据
* @param spaceName
* @returns
*/
declare function getCacheSpace<T>(spaceName: string): Record<string, T> | null;
/**
* 设置缓存
* @param spaceName
* @param key
* @param value
*/
declare function setCache<T>(spaceName: string, key: string, value: T): void;
/**
* 清除缓存
* @param spaceName
*/
declare function clearCache(spaceName: string): void;
export { getCacheSpace, getCache, setCache, clearCache };
export declare function CRC32(bytes: Uint8Array): number;
/**
* 获得 CRC16 校验位
* @param bytes 比特数据
*/
export declare function CRC16(bytes: Uint8Array | number[]): number;
export declare const CRC8: (byte_array: Uint8Array | number[]) => number;

@@ -1,64 +0,13 @@

/**
* 将十进制数据转为十六进制数字符串
* @param dec 十进制数
* @param length 输出的长度
* @returns
*/
export declare function dec2hex(dec: number | string, length?: number): string;
/**
* 把 ArrayBuffer 转换成 16 进制内容
* @param data 二进制内容
* @returns
*/
export declare function ab2hex(data: ArrayBuffer | number[]): string[];
/**
* 将十六进制数据转为对应的字符,返回对应的字符串
* @param hex 十六进制字符串
* @returns
*/
export declare function hex2string(hex: string | string[]): string;
/**
* 十六进制数据转二进制
* 注:一个十六进制数用 8 bit 表示
* @param hex
* @returns
*/
export declare function hex2ab(hex: string | string[] | number[]): Uint8Array;
/**
* 将对象数据转为 url query string
* @param data
* @param encode 是否需要转义
* @returns
*/
export declare const formatQuery: (data: Record<string, any>, encode?: boolean) => string;
/**
* 检查微信小程序基础库版本是否大于等于某个版本
* @param version
* @returns
*/
export declare const checkWxVersion: (version: string) => boolean;
/**
* 检测某个版本是否大于等于目标版本
* @param source
* @param target
* @param includeEquel 是否包含等于,默认包含
* @returns
*/
export declare const checkVersion: (source: string, target: string, includeEquel?: boolean) => boolean;
export declare const firstUpperCase: (txt: string) => string;
export declare const getImageUrl: (img: string) => string;
/**
* 将属名性名转为驼峰格式
* @param data
* @returns
*/
export declare function keyToHump(data: any): any;
export declare const isIOS: boolean;
export declare const isAndroid: boolean;
/**
* 让程序等待一段时间,再往下执行
* @param wait 等待最大时间,单位毫秒
* @param checkStopSleep 在等待过程中确认是否要停止等待的回调,请在等待时间超过 50ms 时使用
* @returns
*/
export declare const sleep: (wait: number, checkStopSleep?: () => boolean) => Promise<unknown>;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc