taro-bluetooth-print 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.
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/bluetooth/adapter.d.ts +31 -0
- package/dist/bluetooth/adapter.js +47 -0
- package/dist/bluetooth/adapter.js.map +1 -0
- package/dist/bluetooth/h5.d.ts +66 -0
- package/dist/bluetooth/h5.js +302 -0
- package/dist/bluetooth/h5.js.map +1 -0
- package/dist/bluetooth/harmony.d.ts +82 -0
- package/dist/bluetooth/harmony.js +342 -0
- package/dist/bluetooth/harmony.js.map +1 -0
- package/dist/bluetooth/index.d.ts +45 -0
- package/dist/bluetooth/index.js +175 -0
- package/dist/bluetooth/index.js.map +1 -0
- package/dist/bluetooth/rn.d.ts +35 -0
- package/dist/bluetooth/rn.js +368 -0
- package/dist/bluetooth/rn.js.map +1 -0
- package/dist/bluetooth/weapp.d.ts +16 -0
- package/dist/bluetooth/weapp.js +177 -0
- package/dist/bluetooth/weapp.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/printer/commands.d.ts +28 -0
- package/dist/printer/commands.js +90 -0
- package/dist/printer/commands.js.map +1 -0
- package/dist/printer/image.d.ts +59 -0
- package/dist/printer/image.js +258 -0
- package/dist/printer/image.js.map +1 -0
- package/dist/printer/index.d.ts +87 -0
- package/dist/printer/index.js +362 -0
- package/dist/printer/index.js.map +1 -0
- package/dist/printer/template.d.ts +95 -0
- package/dist/printer/template.js +262 -0
- package/dist/printer/template.js.map +1 -0
- package/dist/utils/buffer.d.ts +35 -0
- package/dist/utils/buffer.js +96 -0
- package/dist/utils/buffer.js.map +1 -0
- package/dist/utils/encoding.d.ts +26 -0
- package/dist/utils/encoding.js +149 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/logger.d.ts +18 -0
- package/dist/utils/logger.js +91 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 日志工具
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = exports.getLogLevel = exports.setLogLevel = exports.LogLevel = void 0;
|
|
7
|
+
// 日志级别
|
|
8
|
+
var LogLevel;
|
|
9
|
+
(function (LogLevel) {
|
|
10
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
11
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
12
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
13
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
14
|
+
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
15
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
16
|
+
// 当前日志级别
|
|
17
|
+
let currentLogLevel = LogLevel.INFO;
|
|
18
|
+
// 设置日志级别
|
|
19
|
+
function setLogLevel(level) {
|
|
20
|
+
currentLogLevel = level;
|
|
21
|
+
}
|
|
22
|
+
exports.setLogLevel = setLogLevel;
|
|
23
|
+
// 获取当前日志级别
|
|
24
|
+
function getLogLevel() {
|
|
25
|
+
return currentLogLevel;
|
|
26
|
+
}
|
|
27
|
+
exports.getLogLevel = getLogLevel;
|
|
28
|
+
// 获取时间戳
|
|
29
|
+
function getTimestamp() {
|
|
30
|
+
const now = new Date();
|
|
31
|
+
return now.toISOString();
|
|
32
|
+
}
|
|
33
|
+
// 格式化日志消息
|
|
34
|
+
function formatMessage(level, message, ...args) {
|
|
35
|
+
const timestamp = getTimestamp();
|
|
36
|
+
let formattedMessage = `[${timestamp}] [${level}] [蓝牙打印库] ${message}`;
|
|
37
|
+
// 处理参数
|
|
38
|
+
if (args.length > 0) {
|
|
39
|
+
try {
|
|
40
|
+
// 尝试格式化参数
|
|
41
|
+
const formattedArgs = args.map(arg => {
|
|
42
|
+
if (arg instanceof Error) {
|
|
43
|
+
return arg.stack || arg.message;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof arg === 'object') {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.stringify(arg);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return String(arg);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return String(arg);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
formattedMessage += ` - ${formattedArgs.join(', ')}`;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
formattedMessage += ` - [无法格式化参数: ${e}]`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return formattedMessage;
|
|
64
|
+
}
|
|
65
|
+
exports.logger = {
|
|
66
|
+
debug: (message, ...args) => {
|
|
67
|
+
if (currentLogLevel <= LogLevel.DEBUG) {
|
|
68
|
+
const formattedMessage = formatMessage('DEBUG', message, ...args);
|
|
69
|
+
console.log(formattedMessage);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
info: (message, ...args) => {
|
|
73
|
+
if (currentLogLevel <= LogLevel.INFO) {
|
|
74
|
+
const formattedMessage = formatMessage('INFO', message, ...args);
|
|
75
|
+
console.info(formattedMessage);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
warn: (message, ...args) => {
|
|
79
|
+
if (currentLogLevel <= LogLevel.WARN) {
|
|
80
|
+
const formattedMessage = formatMessage('WARN', message, ...args);
|
|
81
|
+
console.warn(formattedMessage);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
error: (message, ...args) => {
|
|
85
|
+
if (currentLogLevel <= LogLevel.ERROR) {
|
|
86
|
+
const formattedMessage = formatMessage('ERROR', message, ...args);
|
|
87
|
+
console.error(formattedMessage);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=logger.js.map
|
|
@@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W,EAAQ,EAAE;QAC/C,IAAI,eAAe,IAAI,QAAQ,CAAC,KAAK,EAAE;YACrC,MAAM,gBAAgB,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YAClE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;SACjC;IACH,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "taro-bluetooth-print",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "跨平台蓝牙打印库,支持微信小程序、H5、React Native和鸿蒙等平台",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"lint": "eslint --ext .ts src",
|
|
11
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
12
|
+
"test": "jest"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"taro",
|
|
16
|
+
"bluetooth",
|
|
17
|
+
"printer",
|
|
18
|
+
"esc/pos",
|
|
19
|
+
"thermal-printer",
|
|
20
|
+
"weapp",
|
|
21
|
+
"h5",
|
|
22
|
+
"react-native",
|
|
23
|
+
"harmony"
|
|
24
|
+
],
|
|
25
|
+
"author": "Agions",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Agions/taro-bluetooth-print.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Agions/taro-bluetooth-print/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/Agions/taro-bluetooth-print#readme",
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@tarojs/taro": ">=3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tarojs/taro": "^3.6.0",
|
|
40
|
+
"@types/jest": "^29.5.0",
|
|
41
|
+
"@types/node": "^18.15.0",
|
|
42
|
+
"@types/yargs": "^17.0.33",
|
|
43
|
+
"@types/yargs-parser": "^21.0.3",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
45
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
46
|
+
"eslint": "^8.36.0",
|
|
47
|
+
"jest": "^29.5.0",
|
|
48
|
+
"prettier": "^2.8.4",
|
|
49
|
+
"ts-jest": "^29.0.5",
|
|
50
|
+
"typescript": "^4.9.5"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
]
|
|
57
|
+
}
|