Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aiot-toolkit/shared-utils

Package Overview
Dependencies
Maintainers
5
Versions
368
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aiot-toolkit/shared-utils - npm Package Compare versions

Comparing version 2.0.1-alpha.13 to 2.0.2-batchmanifest-beta.1

20

lib/ColorConsole.d.ts

@@ -9,4 +9,4 @@ import { ILog, LOG_LEVEL } from './interface/ILog';

}
type Message = string | number | boolean | undefined | {
word: string;
export type StyleMessage = string | number | boolean | undefined | {
word: string | number;
style?: IStyle;

@@ -23,8 +23,8 @@ };

static getStyle(logLevel: LOG_LEVEL): IStyle;
static log(...message: Message[]): void;
static error(...message: Message[]): void;
static info(...message: Message[]): void;
static success(...message: Message[]): void;
static throw(...message: Message[]): void;
static warn(...message: Message[]): void;
static log(...message: StyleMessage[]): void;
static error(...message: StyleMessage[]): void;
static info(...message: StyleMessage[]): void;
static success(...message: StyleMessage[]): void;
static throw(...message: StyleMessage[]): void;
static warn(...message: StyleMessage[]): void;
/**

@@ -40,3 +40,3 @@ * 创建复杂格式的消息,可单独设置词语样式

*/
static createMessage(...words: Message[]): string;
static createMessage(words: StyleMessage | StyleMessage[]): string;
private static _log;

@@ -49,4 +49,4 @@ private static formatWord;

*/
static logger(log: ILog): string;
static logger(log: ILog): void;
}
export default ColorConsole;

@@ -31,3 +31,2 @@ "use strict";

this._log(ILog_1.LOG_LEVEL.Throw, ...message);
process.exit();
}

@@ -47,4 +46,5 @@ static warn(...message) {

*/
static createMessage(...words) {
return words
static createMessage(words) {
const list = Array.isArray(words) ? words : [words];
return list
.map((item) => {

@@ -60,5 +60,10 @@ if (typeof item === 'object') {

const style = this.styleDic[logLevel] || this.defaultStyle;
const time = this.formatWord(`[${(0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss')}]:`, style);
const time = this.formatWord(`[${(0, dayjs_1.default)().format('MM-DD HH:mm:ss')}] [toolkit]:`, style);
const icon = style.icon ? style.icon : '';
console.log(icon, time, this.createMessage(...message));
console.log(icon, time, this.createMessage(message.map((item) => {
if (typeof item === 'object') {
return Object.assign(Object.assign({}, item), { style: item.style || style });
}
return item;
})));
}

@@ -91,24 +96,15 @@ static formatWord(word, style) {

static logger(log) {
const time = (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss');
const { message, position, level = ILog_1.LOG_LEVEL.Info, isOnlyPrintError = false } = log;
let result = position ? `${message}\n${JSON.stringify(position)}` : `${message}`;
switch (level) {
case ILog_1.LOG_LEVEL.Success:
case ILog_1.LOG_LEVEL.Info:
console.log(`${chalk_1.default.green.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
break;
case ILog_1.LOG_LEVEL.Warn:
console.log(`${chalk_1.default.yellow.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
break;
case ILog_1.LOG_LEVEL.Error:
case ILog_1.LOG_LEVEL.Throw:
result = message;
if (isOnlyPrintError) {
console.log(`${chalk_1.default.red.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
}
else {
throw new Error(result);
}
const { message, position, filePath, level = ILog_1.LOG_LEVEL.Info } = log;
let positionMessage;
positionMessage = {
style: this.getStyle(ILog_1.LOG_LEVEL.Info),
word: [filePath, position === null || position === void 0 ? void 0 : position.startLine, position === null || position === void 0 ? void 0 : position.startColumn]
.filter((item) => Boolean(item))
.join(':')
};
const logs = Array.isArray(message) ? message : [message];
if (positionMessage) {
logs.unshift(positionMessage);
}
return result;
this._log(level, ...logs);
}

@@ -145,3 +141,1 @@ }

exports.default = ColorConsole;
//# sourceMappingURL=ColorConsole.js.map

@@ -11,3 +11,1 @@ "use strict";

exports.default = MapData;
//# sourceMappingURL=MapData.js.map

@@ -13,3 +13,1 @@ "use strict";

exports.default = PositionError;
//# sourceMappingURL=PositionError.js.map

@@ -22,3 +22,1 @@ "use strict";

exports.outputQRCodeOnTerminal = outputQRCodeOnTerminal;
//# sourceMappingURL=index.js.map

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

import { StyleMessage } from '../ColorConsole';
import IPosition from './IPosition';

@@ -15,6 +16,6 @@ export declare enum LOG_LEVEL {

level?: LOG_LEVEL;
message: string;
message: StyleMessage[] | StyleMessage;
position?: IPosition;
isOnlyPrintError?: boolean;
filePath?: string;
}
export type Logger = (log: ILog) => void;

@@ -14,3 +14,1 @@ "use strict";

})(LOG_LEVEL || (exports.LOG_LEVEL = LOG_LEVEL = {}));
//# sourceMappingURL=ILog.js.map

@@ -29,3 +29,7 @@ /**

endColumn: number;
/**
* 节点所在文件
*/
source?: string;
}
export default IPosition;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IPosition.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Type.js.map

@@ -16,2 +16,3 @@ /// <reference types="node" />

static calcDataDigest(buffer: Buffer): Buffer;
static calcImageDigest(filePath: string): string;
/**

@@ -18,0 +19,0 @@ * 从开发者项目的 node_module 中加载指定依赖;

@@ -28,2 +28,7 @@ "use strict";

}
static calcImageDigest(filePath) {
const data = fs_1.default.readFileSync(filePath);
const hash = crypto_1.default.createHash('md5').update(data);
return hash.digest('hex').substring(0, 8);
}
/**

@@ -37,11 +42,16 @@ * 从开发者项目的 node_module 中加载指定依赖;

if (!fs_1.default.existsSync(modulePath)) {
return Promise.reject(new Error(ColorConsole_1.default.createMessage({
word: packageName,
style: ColorConsole_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
}, 'is missing, run', {
word: `npm i ${packageName}`,
style: ColorConsole_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
}, 'to install it')));
return Promise.reject(new Error(ColorConsole_1.default.createMessage([
{
word: packageName,
style: ColorConsole_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
},
'is missing, run',
{
word: `npm i ${packageName}`,
style: ColorConsole_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
},
'to install it'
])));
}
return require(modulePath);
return Promise.resolve(require(modulePath));
}

@@ -103,3 +113,1 @@ static requireModule(path, throwError = false) {

exports.default = CommonUtil;
//# sourceMappingURL=CommonUtil.js.map

@@ -119,6 +119,3 @@ "use strict";

static updatePath(path, fullName) {
if (fs_extra_1.default.statSync(path).isFile()) {
return path_1.default.join(path_1.default.dirname(path), fullName);
}
return path;
return path_1.default.join(path_1.default.dirname(path), fullName);
}

@@ -157,3 +154,1 @@ /**

exports.default = FileUtil;
//# sourceMappingURL=FileUtil.js.map

@@ -53,3 +53,1 @@ "use strict";

exports.default = NetworkUtil;
//# sourceMappingURL=NetworkUtil.js.map

@@ -19,3 +19,19 @@ /**

static string2arrayByComma(value?: string): string[];
/**
* 数组转字符串
* @param arr
* @param styleTransform 是否为style解析树的数组转换
* @returns
*/
static arrayToString(arr: any[], styleTransform?: boolean): string;
/**
* 对象转字符串
* @param obj
* @param styleTransform 是否为style解析树的数组转换
* @returns
*/
static objectToString(obj: {
[key: string]: any;
}, styleTransform?: boolean): string;
}
export default StringUtil;

@@ -31,5 +31,89 @@ "use strict";

}
/**
* 数组转字符串
* @param arr
* @param styleTransform 是否为style解析树的数组转换
* @returns
*/
static arrayToString(arr, styleTransform = false) {
if (Array.isArray(arr)) {
if (arr.length <= 0) {
return '[]';
}
}
else {
return '';
}
const tempArr = arr.map((item) => {
let valueStr = '';
switch (typeof item) {
case 'object':
if (Array.isArray(item)) {
valueStr = StringUtil.arrayToString(item, styleTransform);
}
else {
valueStr = StringUtil.objectToString(item, styleTransform);
}
break;
case 'string':
valueStr = JSON.stringify(item);
break;
default:
valueStr = item;
break;
}
return valueStr;
});
return `[${tempArr.join(',')}]`;
}
/**
* 对象转字符串
* @param obj
* @param styleTransform 是否为style解析树的数组转换
* @returns
*/
static objectToString(obj, styleTransform = false) {
return `{
${Object.keys(obj)
.map((key) => {
const value = obj[key];
if (value === undefined) {
return '';
}
let valueStr = '';
switch (typeof value) {
case 'object':
if (Array.isArray(value)) {
valueStr = StringUtil.arrayToString(value, styleTransform);
}
else {
valueStr = StringUtil.objectToString(value, styleTransform);
}
break;
case 'function':
valueStr = value.toString();
break;
case 'string':
if (styleTransform) {
// 匹配require函数调用
const testReg = new RegExp(/require\(['"](.+?)['"]\)/g);
if (testReg.test(value)) {
valueStr = value;
}
else {
valueStr = JSON.stringify(value);
}
break;
}
default:
valueStr = value;
break;
}
return `"${StringUtil.hyphenedToCamel(key)}":${valueStr}`;
})
.filter((item) => Boolean(item))
.join(',')}
}`;
}
}
exports.default = StringUtil;
//# sourceMappingURL=StringUtil.js.map

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const ColorConsole_1 = __importDefault(require("../ColorConsole"));
const PositionError_1 = __importDefault(require("../data/PositionError"));

@@ -26,5 +27,5 @@ const ILog_1 = require("../interface/ILog");

if (position) {
throw new PositionError_1.default(position, message);
throw new PositionError_1.default(position, ColorConsole_1.default.createMessage(message));
}
throw new Error(message);
throw new Error(ColorConsole_1.default.createMessage(message));
}

@@ -35,3 +36,1 @@ };

exports.default = WrapCallback;
//# sourceMappingURL=WrapCallback.js.map
{
"name": "@aiot-toolkit/shared-utils",
"version": "2.0.1-alpha.13",
"version": "2.0.2-batchmanifest-beta.1",
"description": "The common method functions of the aiot-toolkit.",

@@ -15,6 +15,2 @@ "homepage": "",

],
"repository": {
"type": "git",
"url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
},
"scripts": {

@@ -26,3 +22,2 @@ "test": "node ./__tests__/shared-utils.test.js"

"chalk": "^4.0.0",
"crypto": "^1.0.1",
"dayjs": "^1.11.9",

@@ -33,5 +28,6 @@ "fs-extra": "^11.2.0",

"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/qrcode-terminal": "^0.12.0"
},
"gitHead": "49040b26a267943df4d0b202b200d4df5bcbc1ef"
"gitHead": "9e58a0cbe0e2d35a38e99d669398caaa8fd648a8"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc