@iot9x.com/ipc-utils
Version:
九星云、九星小程序、九星配置工具所共用的库方法
32 lines (31 loc) • 942 B
TypeScript
/// <reference types="node" />
export declare enum PackageType {
/** 纯文本 */
PlainText = 1,
/** 16进制 */
Hex = 2,
/** json */
JSON = 3,
/** base64 */
Base64 = 4
}
export interface Options {
/** 是否需要空格分隔符 */
needSpace?: boolean;
/** 编码格式 */
encoding?: string;
}
/**
* 进制转换
* @param encoding 字符集: utf8, gb2312, cesu8...
* @returns { bufferToHex, hexToStr, strToHex, onHexSendChange, decodePackage, encodePackage }
*/
declare function useConversionUtil(encoding: string): {
bufferToHex: (buffer: Buffer) => string;
hexToStr: (hexStr: string) => string;
strToHex: (hex: string, options?: Options) => string;
onHexSendChange: (value: string, isHex: boolean) => string;
decodePackage: (str: string) => [PackageType, string];
encodePackage: (value: string, type?: PackageType) => string;
};
export default useConversionUtil;