@jiabaida/tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const BleApiManager={version:"1.0.0"};exports.BleApiManager=BleApiManager,exports.default=BleApiManager;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.chunk=(array,size)=>{const chunks=[];for(let i=0;i<array.length;i+=size)chunks.push(array.slice(i,i+size));return chunks},exports.unique=array=>[...new Set(array)];
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const commonfun={inArray(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1},decimalToHex:(decimal,padding=2)=>Number(decimal).toString(16).padStart(padding,"0"),hexToDecimal:hex=>parseInt(hex,16),ab2hex:buffer=>Array.prototype.map.call(new Uint8Array(buffer),function(bit){return("00"+bit.toString(16)).slice(-2)}).join(""),areArraysEqual:(arr1,arr2)=>arr1.length===arr2.length&&arr1.every((value,index)=>value===arr2[index]),convertASCIItoHex(asciiVal){let asciiCode=asciiVal.charCodeAt(0);return this.decimalToHex(asciiCode)},getParamCheck(content){let sum=0;for(let i=0;i<content.length;i++)sum+=255&content[i];let check1="",check2="";return sum?(sum^=65535,sum+=1,sum=this.decimalToHex(sum),check1=sum.substr(0,2),check2=sum.substr(2,2)):(check1="00",check2="00"),{check1:"0x"+check1,check2:"0x"+check2}},splitNumberToHexArray(decimalNumber){let hexString=decimalNumber.toString(16);hexString=hexString.length%2==0?hexString:"0"+hexString;let hexArray=hexString.match(/.{1,2}/g);for(;hexArray.length<2;)hexArray.unshift("00");return hexArray.map(hex=>"0x"+hex)},decimalToHexConcat:(num1,num2)=>"0x"+num1.toString(16).padStart(2,"0")+num2.toString(16).padStart(2,"0"),decimalToTwoByteHexArray(decimal){if(decimal<0||decimal>65535)throw new Error("输入的十进制数超出 16 位无符号整数范围(0 - 65535)");return[`0x${`00${(decimal>>8).toString(16)}`.slice(-2)}`,`0x${`00${(255&decimal).toString(16)}`.slice(-2)}`]},stringToTwoHexArray(str){const paddedStr=str.padStart(4,"0");return[`0x${paddedStr.slice(0,2)}`,`0x${paddedStr.slice(2,4)}`]},base64ToHexArray(base64,withPrefix=!0){if("undefined"!=typeof uni&&uni.base64ToArrayBuffer){const arrayBuffer=uni.base64ToArrayBuffer(base64);return Array.prototype.map.call(new Uint8Array(arrayBuffer),x=>{let hex=("00"+x.toString(16)).slice(-2);return withPrefix?`0x${hex}`:hex})}return["0x41","0x42","0x43"].slice(0,3)},handleDelay:ms=>new Promise(resolve=>setTimeout(resolve,ms)),formatTime(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`}};exports.commonfun=commonfun,exports.default=commonfun;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var array=require("./core/array.js"),BleApiManager=require("./core/BleApiManager.js"),commonfun=require("./core/commonfun.js");exports.chunk=array.chunk,exports.unique=array.unique,exports.BleApiManager=BleApiManager.BleApiManager,exports.commonfun=commonfun.commonfun;
@@ -0,0 +1 @@
1
+ const BleApiManager={version:"1.0.0"};export{BleApiManager,BleApiManager as default};
@@ -0,0 +1 @@
1
+ const chunk=(array,size)=>{const chunks=[];for(let i=0;i<array.length;i+=size)chunks.push(array.slice(i,i+size));return chunks},unique=array=>[...new Set(array)];export{chunk,unique};
@@ -0,0 +1 @@
1
+ const commonfun={inArray(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1},decimalToHex:(decimal,padding=2)=>Number(decimal).toString(16).padStart(padding,"0"),hexToDecimal:hex=>parseInt(hex,16),ab2hex:buffer=>Array.prototype.map.call(new Uint8Array(buffer),function(bit){return("00"+bit.toString(16)).slice(-2)}).join(""),areArraysEqual:(arr1,arr2)=>arr1.length===arr2.length&&arr1.every((value,index)=>value===arr2[index]),convertASCIItoHex(asciiVal){let asciiCode=asciiVal.charCodeAt(0);return this.decimalToHex(asciiCode)},getParamCheck(content){let sum=0;for(let i=0;i<content.length;i++)sum+=255&content[i];let check1="",check2="";return sum?(sum^=65535,sum+=1,sum=this.decimalToHex(sum),check1=sum.substr(0,2),check2=sum.substr(2,2)):(check1="00",check2="00"),{check1:"0x"+check1,check2:"0x"+check2}},splitNumberToHexArray(decimalNumber){let hexString=decimalNumber.toString(16);hexString=hexString.length%2==0?hexString:"0"+hexString;let hexArray=hexString.match(/.{1,2}/g);for(;hexArray.length<2;)hexArray.unshift("00");return hexArray.map(hex=>"0x"+hex)},decimalToHexConcat:(num1,num2)=>"0x"+num1.toString(16).padStart(2,"0")+num2.toString(16).padStart(2,"0"),decimalToTwoByteHexArray(decimal){if(decimal<0||decimal>65535)throw new Error("输入的十进制数超出 16 位无符号整数范围(0 - 65535)");return[`0x${`00${(decimal>>8).toString(16)}`.slice(-2)}`,`0x${`00${(255&decimal).toString(16)}`.slice(-2)}`]},stringToTwoHexArray(str){const paddedStr=str.padStart(4,"0");return[`0x${paddedStr.slice(0,2)}`,`0x${paddedStr.slice(2,4)}`]},base64ToHexArray(base64,withPrefix=!0){if("undefined"!=typeof uni&&uni.base64ToArrayBuffer){const arrayBuffer=uni.base64ToArrayBuffer(base64);return Array.prototype.map.call(new Uint8Array(arrayBuffer),x=>{let hex=("00"+x.toString(16)).slice(-2);return withPrefix?`0x${hex}`:hex})}return["0x41","0x42","0x43"].slice(0,3)},handleDelay:ms=>new Promise(resolve=>setTimeout(resolve,ms)),formatTime(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`}};export{commonfun,commonfun as default};
@@ -0,0 +1 @@
1
+ export{chunk,unique}from"./core/array.js";export{BleApiManager}from"./core/BleApiManager.js";export{commonfun}from"./core/commonfun.js";
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jiabaida/tools",
3
+ "version": "1.0.0",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/esm/index.js",
9
+ "require": "./dist/cjs/index.js"
10
+ },
11
+ "./array": "./dist/esm/core/array.js",
12
+ "./BleApiManager": "./dist/esm/core/BleApiManager.js",
13
+ "./commonfun": "./dist/esm/core/commonfun.js"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "build": "rollup -c",
21
+ "prepublishOnly": "npm run build",
22
+ "test": "jest --no-cache",
23
+ "test:watch": "jest --watch"
24
+ },
25
+ "keywords": [],
26
+ "author": "",
27
+ "license": "ISC",
28
+ "description": "",
29
+ "devDependencies": {
30
+ "@babel/core": "^7.28.0",
31
+ "@babel/preset-env": "^7.28.0",
32
+ "@rollup/plugin-babel": "^6.0.4",
33
+ "@rollup/plugin-node-resolve": "^16.0.1",
34
+ "babel-jest": "^30.0.5",
35
+ "jest": "^30.0.5",
36
+ "rollup": "^2.79.2",
37
+ "rollup-plugin-terser": "^7.0.2"
38
+ }
39
+ }
package/readme.md ADDED
@@ -0,0 +1,42 @@
1
+ # 登录 npm(需先注册)
2
+ npm login
3
+ 账号:
4
+ 密码:
5
+
6
+ # 发布作用域包
7
+ npm publish --access public
8
+
9
+ # 更新版本号
10
+ * npm version patch # 修复 bug
11
+ * npm version minor # 新增功能
12
+ * npm version major # 不兼容改动
13
+
14
+
15
+ # 使用方法
16
+ ## 全量引用
17
+ ```
18
+ import { chunk, unique } from '@jiabaida/tools';
19
+ ```
20
+
21
+ ## 按需引用(推荐)
22
+ ```
23
+ // 直接引入特定模块(tree shaking 自动生效)
24
+ import { unique } from '@jiabaida/tools/core/array'; --貌似不生效
25
+ // 或使用子路径导出
26
+ import { unique } from '@jiabaida/tools/array'; --推荐使用这个
27
+ ```
28
+ 按需引用package.json要对应配置
29
+ ```
30
+ {
31
+ ...
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/esm/index.js",
35
+ "require": "./dist/cjs/index.js"
36
+ },
37
+ "./array": "./dist/esm/core/array.js" // 子路径导出
38
+ "./BleApiManager": "./dist/esm/core/BleApiManager.js"
39
+ },
40
+ ...
41
+ }
42
+ ```