feat: 中文
This commit is contained in:
parent
922d82e27c
commit
42af6d8906
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@taoya7/print-help",
|
"name": "@taoya7/print-help",
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -26,10 +26,12 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.11.25",
|
"@types/node": "^20.11.25",
|
||||||
|
"buffer": "^6.0.3",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.4.2",
|
||||||
"unbuild": "^2.0.0"
|
"unbuild": "^2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"rollup-obfuscator": "^4.1.1"
|
"rollup-obfuscator": "^4.1.1"
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ settings:
|
|||||||
excludeLinksFromLockfile: false
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
iconv-lite:
|
||||||
|
specifier: ^0.6.3
|
||||||
|
version: 0.6.3
|
||||||
lodash-es:
|
lodash-es:
|
||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
@ -19,6 +22,9 @@ devDependencies:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.11.25
|
specifier: ^20.11.25
|
||||||
version: 20.11.25
|
version: 20.11.25
|
||||||
|
buffer:
|
||||||
|
specifier: ^6.0.3
|
||||||
|
version: 6.0.3
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ^5.4.2
|
specifier: ^5.4.2
|
||||||
version: 5.4.2
|
version: 5.4.2
|
||||||
@ -711,6 +717,10 @@ packages:
|
|||||||
/balanced-match@1.0.2:
|
/balanced-match@1.0.2:
|
||||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||||
|
|
||||||
|
/base64-js@1.5.1:
|
||||||
|
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/boolbase@1.0.0:
|
/boolbase@1.0.0:
|
||||||
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
|
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
|
||||||
dev: true
|
dev: true
|
||||||
@ -750,6 +760,13 @@ packages:
|
|||||||
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
|
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/buffer@6.0.3:
|
||||||
|
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
||||||
|
dependencies:
|
||||||
|
base64-js: 1.5.1
|
||||||
|
ieee754: 1.2.1
|
||||||
|
dev: true
|
||||||
|
|
||||||
/builtin-modules@3.3.0:
|
/builtin-modules@3.3.0:
|
||||||
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
|
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@ -1351,6 +1368,17 @@ packages:
|
|||||||
resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==}
|
resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/iconv-lite@0.6.3:
|
||||||
|
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||||
|
engines: {node: '>=0.10.0'}
|
||||||
|
dependencies:
|
||||||
|
safer-buffer: 2.1.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/ieee754@1.2.1:
|
||||||
|
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/ignore@5.3.1:
|
/ignore@5.3.1:
|
||||||
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
|
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
|
||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
@ -2145,6 +2173,10 @@ packages:
|
|||||||
queue-microtask: 1.2.3
|
queue-microtask: 1.2.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/safer-buffer@2.1.2:
|
||||||
|
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/scule@1.3.0:
|
/scule@1.3.0:
|
||||||
resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==}
|
resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==}
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
|
import iconv from "iconv-lite";
|
||||||
export enum FOOT {
|
export enum FOOT {
|
||||||
F2 = 0,
|
F2 = 0,
|
||||||
F5 = 1,
|
F5 = 1,
|
||||||
@ -171,9 +171,16 @@ export class LabelCommand {
|
|||||||
}
|
}
|
||||||
private addStrToCommand(str: string): void {
|
private addStrToCommand(str: string): void {
|
||||||
if (str !== "") {
|
if (str !== "") {
|
||||||
let bs: Buffer = Buffer.from(str, "utf8");
|
let bs;
|
||||||
for (let i = 0; i < bs.length; ++i) {
|
try {
|
||||||
this.command.push(bs[i]);
|
bs = iconv.encode(str, "GB2312");
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
if (bs) {
|
||||||
|
for (let i = 0; i < bs.length; ++i) {
|
||||||
|
this.command.push(bs[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,10 +485,12 @@ export class LabelCommand {
|
|||||||
* 获取命令字符串
|
* 获取命令字符串
|
||||||
*/
|
*/
|
||||||
getCommandStr(command: number[]) {
|
getCommandStr(command: number[]) {
|
||||||
let str = "";
|
// 创建一个Buffer实例来存储字节数组
|
||||||
for (let i = 0; i < command.length; i++) {
|
const buffer = Buffer.from(command);
|
||||||
str += String.fromCharCode(command[i]);
|
|
||||||
}
|
// 使用iconv-lite将Buffer从GB2312解码成字符串
|
||||||
|
const str = iconv.decode(buffer, "GB2312");
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
addQueryPrinterType(): void {
|
addQueryPrinterType(): void {
|
||||||
|
26
src/index.ts
26
src/index.ts
@ -1,27 +1 @@
|
|||||||
export * from "./command";
|
export * from "./command";
|
||||||
|
|
||||||
import {
|
|
||||||
FONTMUL,
|
|
||||||
FONTTYPE,
|
|
||||||
LabelCommand,
|
|
||||||
ROTATION,
|
|
||||||
EEC,
|
|
||||||
} from "@/command/Label";
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
let label = new LabelCommand(50, 30, 0); // 长,宽,gap
|
|
||||||
label.addText(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
FONTTYPE.FONT_1,
|
|
||||||
ROTATION.ROTATION_0,
|
|
||||||
FONTMUL.MUL_1,
|
|
||||||
FONTMUL.MUL_1,
|
|
||||||
"Hello World"
|
|
||||||
);
|
|
||||||
label.addQRCode(0, 0, EEC.LEVEL_L, 5, ROTATION.ROTATION_0, "taoya.art");
|
|
||||||
var command = label.getCommand();
|
|
||||||
console.log(command); // 获取字节码
|
|
||||||
console.log(label.getCommandStr(command));
|
|
||||||
}
|
|
||||||
main();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user