Comparing version 0.9.10 to 0.9.11
@@ -0,30 +1,49 @@ | ||
const { off } = require("process"); | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true, | ||
'env': { | ||
'browser': true, | ||
'es2021': true, | ||
'commonjs': true, | ||
'node': true | ||
}, | ||
"extends": [ | ||
"google" | ||
'extends': [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended' | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
'parser': '@typescript-eslint/parser', | ||
'parserOptions': { | ||
'ecmaVersion': 2018, | ||
'sourceType': 'module' | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"prettier-eslint", | ||
'plugins': [ | ||
'@typescript-eslint' | ||
], | ||
"rules": { | ||
"tabWidth": 4, | ||
"indent": ["error", 4], | ||
"linebreak-style": ["warn", "windows"], | ||
"quotes": 0, | ||
"semi": ["error", "always"], | ||
"max-len": ["error", { | ||
"code": 160, | ||
'rules': { | ||
'indent': [ | ||
'error', | ||
4 | ||
], | ||
'linebreak-style': [ | ||
'error', | ||
'windows' | ||
], | ||
'no-constant-condition': [ | ||
'error', { 'checkLoops': false } | ||
], | ||
'quotes': [ | ||
'error', | ||
'single' | ||
], | ||
'@typescript-eslint/no-inferrable-types':'off', | ||
'@typescript-eslint/ban-types': 'off', | ||
'no-explicit-any': 'off', | ||
'max-len': ['error', { | ||
'code': 160, | ||
}], | ||
"requireParamType": true, | ||
}, | ||
'semi': [ | ||
'error', | ||
'always' | ||
] | ||
} | ||
}; |
@@ -18,10 +18,5 @@ "use strict"; | ||
const BIT_VALUE = [ | ||
0x00000001, 0x00000002, 0x00000004, 0x00000008, | ||
0x00000010, 0x00000020, 0x00000040, 0x00000080, | ||
0x00000100, 0x00000200, 0x00000400, 0x00000800, | ||
0x00001000, 0x00002000, 0x00004000, 0x00008000, | ||
0x00010000, 0x00020000, 0x00040000, 0x00080000, | ||
0x00100000, 0x00200000, 0x00400000, 0x00800000, | ||
0x01000000, 0x02000000, 0x04000000, 0x08000000, | ||
0x10000000, 0x20000000, 0x40000000, | ||
0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, | ||
0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x01000000, 0x02000000, | ||
0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, | ||
]; | ||
@@ -32,10 +27,5 @@ /** | ||
const BIT_VALUE_EX = [ | ||
0xfffffffe, 0xfffffffd, 0xfffffffb, 0xfffffff7, | ||
0xffffffef, 0xffffffdf, 0xffffffbf, 0xffffff7f, | ||
0xfffffeff, 0xfffffdff, 0xfffffbff, 0xfffff7ff, | ||
0xffffefff, 0xffffdfff, 0xffffbfff, 0xffff7fff, | ||
0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff, | ||
0xffefffff, 0xffdfffff, 0xffbfffff, 0xff7fffff, | ||
0xfeffffff, 0xfdffffff, 0xfbffffff, 0xf7ffffff, | ||
0xefffffff, 0xdfffffff, 0xbfffffff, | ||
0xfffffffe, 0xfffffffd, 0xfffffffb, 0xfffffff7, 0xffffffef, 0xffffffdf, 0xffffffbf, 0xffffff7f, 0xfffffeff, 0xfffffdff, 0xfffffbff, 0xfffff7ff, 0xffffefff, | ||
0xffffdfff, 0xffffbfff, 0xffff7fff, 0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff, 0xffefffff, 0xffdfffff, 0xffbfffff, 0xff7fffff, 0xfeffffff, 0xfdffffff, | ||
0xfbffffff, 0xf7ffffff, 0xefffffff, 0xdfffffff, 0xbfffffff, | ||
]; | ||
@@ -42,0 +32,0 @@ /** |
@@ -115,3 +115,3 @@ "use strict"; | ||
else { | ||
return (this.buffer).byteLength; | ||
return this.buffer.byteLength; | ||
} | ||
@@ -267,3 +267,3 @@ } | ||
if (!Buffer.isBuffer(paramBuffer)) { | ||
ret.setError(EnumBufferWapperError.DATA_IS_NOT_BUFFER, `paramBuffer不是Buffer对象!`); | ||
ret.setError(EnumBufferWapperError.DATA_IS_NOT_BUFFER, 'paramBuffer不是Buffer对象!'); | ||
break; | ||
@@ -270,0 +270,0 @@ } |
@@ -55,3 +55,3 @@ /** 大写的Chinese函数参数选项 */ | ||
/** 判断指定的对象,是不是指定的CNYCurrency对象 */ | ||
static isCurrency(paramV: any): boolean; | ||
static isCurrency(paramV: unknown): boolean; | ||
/** 货币值 */ | ||
@@ -58,0 +58,0 @@ get value(): number; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// const _ = require("lodash"); | ||
const { utils } = require('./utils'); | ||
const utils_1 = require("./utils"); | ||
/** 货币精度 */ | ||
@@ -40,3 +40,3 @@ const Precision = 100; | ||
}; | ||
if (utils.isNumber(paramValue)) { | ||
if (utils_1.utils.isNumber(paramValue)) { | ||
r.value = paramValue; | ||
@@ -347,3 +347,3 @@ } | ||
const n = this.m_intValue; | ||
return (n - n % Precision) / Precision; | ||
return (n - (n % Precision)) / Precision; | ||
} | ||
@@ -379,13 +379,13 @@ /** | ||
let stZheng = '整'; | ||
if (utils.isObject(paramOpts)) { | ||
if (utils_1.utils.isObject(paramOpts)) { | ||
// 人民币前缀 | ||
if (utils.isString(paramOpts.prefix)) { | ||
if (utils_1.utils.isString(paramOpts.prefix)) { | ||
stPrefix = paramOpts.prefix; | ||
} | ||
// 负数前缀 | ||
if (utils.isString(paramOpts.negative)) { | ||
if (utils_1.utils.isString(paramOpts.negative)) { | ||
stNegative = paramOpts.negative; | ||
} | ||
// 整或正字 | ||
if (utils.isString(paramOpts.zheng)) { | ||
if (utils_1.utils.isString(paramOpts.zheng)) { | ||
stZheng = paramOpts.zheng; | ||
@@ -469,3 +469,3 @@ } | ||
} | ||
if ((cent % 10) === 0) { | ||
if (cent % 10 === 0) { | ||
// 当分为0的时候,有整 | ||
@@ -472,0 +472,0 @@ chineseStr += stZheng; |
@@ -52,4 +52,3 @@ "use strict"; | ||
const hash = crypto_1.default.createHmac(EnumCryptoAlgorithm.sha256, paramKey); | ||
return hash.update(paramText) | ||
.digest(EncodingHex); | ||
return hash.update(paramText).digest(EncodingHex); | ||
} | ||
@@ -88,2 +87,3 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
static MD5FromArgs(paramOptions, ...args) { | ||
@@ -111,3 +111,4 @@ let encode = EncodingHex; | ||
let md5string = crypto_1.default.createHash(EnumCryptoAlgorithm.md5).update(s, EncodingUTF8).digest(encode); | ||
if (capital) { // 如果是要求大写 | ||
if (capital) { | ||
// 如果是要求大写 | ||
md5string = md5string.toUpperCase(); | ||
@@ -114,0 +115,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XCommonRet = exports.common_ret = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const common_error_1 = require("./common_error"); | ||
@@ -5,0 +6,0 @@ const constant_1 = require("./constant"); |
@@ -49,2 +49,1 @@ "use strict"; | ||
})(DatetimeConstant = exports.DatetimeConstant || (exports.DatetimeConstant = {})); | ||
; |
@@ -167,4 +167,11 @@ "use strict"; | ||
const d = paramDate; | ||
const dateString = [d.getFullYear(), pad2(d.getMonth() + 1), pad2(d.getDate()), '_', | ||
pad2(d.getHours()), pad2(d.getMinutes()), pad2(d.getSeconds()), paramMillisFlag ? pad3(d.getMilliseconds()) : '', | ||
const dateString = [ | ||
d.getFullYear(), | ||
pad2(d.getMonth() + 1), | ||
pad2(d.getDate()), | ||
'_', | ||
pad2(d.getHours()), | ||
pad2(d.getMinutes()), | ||
pad2(d.getSeconds()), | ||
paramMillisFlag ? pad3(d.getMilliseconds()) : '', | ||
].join(''); | ||
@@ -277,3 +284,3 @@ return dateString; | ||
const localTime = this.ToLocalTime(paramUTC); | ||
return this.ToUTCTime(localTime - localTime % constant_1.DatetimeConstant.MILLIS_PRE_DAY); | ||
return this.ToUTCTime(localTime - (localTime % constant_1.DatetimeConstant.MILLIS_PRE_DAY)); | ||
} | ||
@@ -321,3 +328,3 @@ /** | ||
const localTime = this.ToLocalTime(paramUTC); | ||
return (localTime - localTime % constant_1.DatetimeConstant.MILLIS_PRE_DAY) / constant_1.DatetimeConstant.MILLIS_PRE_DAY; | ||
return (localTime - (localTime % constant_1.DatetimeConstant.MILLIS_PRE_DAY)) / constant_1.DatetimeConstant.MILLIS_PRE_DAY; | ||
} | ||
@@ -324,0 +331,0 @@ /** |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare function logPrefix(paramFilename: string, ...args: any[]): [shortpath: string, ...args: any[]]; | ||
export declare function logPrefix(paramFilename: string, ...args: any[]): any[]; | ||
export interface ILog { | ||
@@ -48,3 +48,2 @@ name: string; | ||
private m_createLog; | ||
constructor(); | ||
/** | ||
@@ -51,0 +50,0 @@ * 取指定tag的日志 |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.getLogger = exports.setGetLogger = exports.getLocalLogger = exports.GetLogManager = exports.LogConsole = exports.logPrefix = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const path_1 = __importDefault(require("path")); | ||
@@ -9,0 +10,0 @@ const util_1 = __importDefault(require("util")); |
@@ -35,6 +35,2 @@ /// <reference types="node" /> | ||
/** | ||
* 构造函数 | ||
*/ | ||
constructor(); | ||
/** | ||
* 数据编码 | ||
@@ -41,0 +37,0 @@ * @param paramSeed 编码种子 |
@@ -24,5 +24,2 @@ "use strict"; | ||
class SimpleCode { | ||
/** | ||
* 构造函数 | ||
*/ | ||
constructor() { | ||
@@ -69,9 +66,12 @@ /** 当前的种子 */ | ||
static __checkParam(paramSeed, paramData, paramMinLength = 0) { | ||
if (!Number.isInteger(paramSeed)) { // 如果不是整数 | ||
if (!Number.isInteger(paramSeed)) { | ||
// 如果不是整数 | ||
return EnumSimpleCodeError.SEED_NOT_INTEGER; | ||
} | ||
if (!Buffer.isBuffer(paramData)) { // 如果不是buffer | ||
if (!Buffer.isBuffer(paramData)) { | ||
// 如果不是buffer | ||
return EnumSimpleCodeError.DATA_NOT_BUFFER; | ||
} | ||
if (paramData.length < paramMinLength) { // 如果长度为0 | ||
if (paramData.length < paramMinLength) { | ||
// 如果长度为0 | ||
return EnumSimpleCodeError.DATA_SIZE_TO_LOW; | ||
@@ -78,0 +78,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.utils = exports.EnumCheckObjectCode = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -283,5 +284,4 @@ const fs_1 = __importDefault(require("fs")); | ||
*/ | ||
// tslint:disable-next-line: ban-types | ||
static async WaitFunction(paramFunc, ...args) { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramFunc((...result) => { | ||
@@ -305,3 +305,3 @@ resolve(result); | ||
static async WaitFunctionEx(paramFunc, ...args) { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramFunc(...args, (...result) => { | ||
@@ -324,3 +324,3 @@ resolve(result); | ||
static async WaitClassFunction(paramObject, paramFunctionName, ...args) { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramObject[paramFunctionName]((...result) => { | ||
@@ -343,3 +343,3 @@ resolve(result); | ||
static async WaitClassFunctionEx(paramObject, paramFunctionName, ...args) { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramObject[paramFunctionName](...args, (...result) => { | ||
@@ -418,15 +418,16 @@ resolve(result); | ||
} | ||
else if (bytes < constant_1.MemorySize.M) { // 1KB | ||
else if (bytes < constant_1.MemorySize.M) { | ||
// 1KB | ||
return (bytes / constant_1.MemorySize.K).toFixed(2) + 'KB'; | ||
} | ||
else if (bytes < constant_1.MemorySize.G) // 1M | ||
{ | ||
else if (bytes < constant_1.MemorySize.G) { | ||
// 1M | ||
return (bytes / constant_1.MemorySize.M).toFixed(2) + 'MB'; | ||
} | ||
else if (bytes < constant_1.MemorySize.T) // 1T | ||
{ | ||
else if (bytes < constant_1.MemorySize.T) { | ||
// 1T | ||
return (bytes / constant_1.MemorySize.G).toFixed(2) + 'GB'; | ||
} | ||
else if (bytes < constant_1.MemorySize.P) // 1T | ||
{ | ||
else if (bytes < constant_1.MemorySize.P) { | ||
// 1T | ||
return (bytes / constant_1.MemorySize.T).toFixed(2) + 'TB'; | ||
@@ -567,3 +568,2 @@ } | ||
} | ||
; | ||
/** | ||
@@ -584,3 +584,2 @@ * 将字符串转换为json,如果出错返回undefined | ||
} | ||
; | ||
/** | ||
@@ -649,3 +648,4 @@ * 原路径移动到新路径 | ||
let pathTemp; | ||
paramPath.split(/[\/\\]/).forEach((dirName) => { | ||
paramPath.split(/[/\\]/).forEach(dirName => { | ||
// 这里指用/ 或\ 都可以分隔目录 如 linux的/usr/local/services 和windows的 d:\temp\aaaa | ||
if (pathTemp) { | ||
@@ -727,14 +727,16 @@ pathTemp = path_1.default.join(pathTemp, dirName); | ||
/** | ||
* 取参数名称 | ||
* - | ||
* @param paramArg 要解析的参数 | ||
* @return 处理结果 | ||
*/ | ||
* 取参数名称 | ||
* - | ||
* @param paramArg 要解析的参数 | ||
* @return 处理结果 | ||
*/ | ||
function GetArgsName(paramArg) { | ||
const localRet = { isArg: false, argName: '', argOri: paramArg }; | ||
let strName = null; | ||
if (paramArg.substring(0, 2) === '--') { // 如果是前缀-- | ||
if (paramArg.substring(0, 2) === '--') { | ||
// 如果是前缀-- | ||
strName = paramArg.substring(2).trim(); | ||
} | ||
else if (paramArg.substring(0, 1) === '-') { // 如果是前缀- | ||
else if (paramArg.substring(0, 1) === '-') { | ||
// 如果是前缀- | ||
strName = paramArg.substring(1).trim(); | ||
@@ -769,3 +771,4 @@ } | ||
} | ||
if (argPre.is) { // 如果存在前缀 | ||
if (argPre.is) { | ||
// 如果存在前缀 | ||
ret.args[argPre.argName] = arg; | ||
@@ -791,3 +794,4 @@ argPre.is = false; | ||
} | ||
if (argPre.is) { // 如果存在前缀,但是,没有值,则加到_中 | ||
if (argPre.is) { | ||
// 如果存在前缀,但是,没有值,则加到_中 | ||
ret._.push(argPre.argOri); | ||
@@ -820,3 +824,3 @@ } | ||
static randomBetween(paramMin, paramMax) { | ||
return this.randomInteger() % (paramMax - paramMin + 1) + paramMin; | ||
return (this.randomInteger() % (paramMax - paramMin + 1)) + paramMin; | ||
} | ||
@@ -823,0 +827,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.watchRequire = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -30,2 +31,3 @@ const path_1 = __importDefault(require("path")); | ||
for (let i = len; 0 <= i; i--) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
cbList[i](require(realPath)); | ||
@@ -37,2 +39,3 @@ } | ||
if (!paramChangeCallback) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
paramCallback(require(realPath)); // 只有变化 | ||
@@ -39,0 +42,0 @@ } |
@@ -15,10 +15,5 @@ /** 关于位的常量 */ | ||
const BIT_VALUE = [ | ||
0x00000001, 0x00000002, 0x00000004, 0x00000008, | ||
0x00000010, 0x00000020, 0x00000040, 0x00000080, | ||
0x00000100, 0x00000200, 0x00000400, 0x00000800, | ||
0x00001000, 0x00002000, 0x00004000, 0x00008000, | ||
0x00010000, 0x00020000, 0x00040000, 0x00080000, | ||
0x00100000, 0x00200000, 0x00400000, 0x00800000, | ||
0x01000000, 0x02000000, 0x04000000, 0x08000000, | ||
0x10000000, 0x20000000, 0x40000000, | ||
0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, | ||
0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x01000000, 0x02000000, | ||
0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, | ||
]; | ||
@@ -29,10 +24,5 @@ /** | ||
const BIT_VALUE_EX = [ | ||
0xfffffffe, 0xfffffffd, 0xfffffffb, 0xfffffff7, | ||
0xffffffef, 0xffffffdf, 0xffffffbf, 0xffffff7f, | ||
0xfffffeff, 0xfffffdff, 0xfffffbff, 0xfffff7ff, | ||
0xffffefff, 0xffffdfff, 0xffffbfff, 0xffff7fff, | ||
0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff, | ||
0xffefffff, 0xffdfffff, 0xffbfffff, 0xff7fffff, | ||
0xfeffffff, 0xfdffffff, 0xfbffffff, 0xf7ffffff, | ||
0xefffffff, 0xdfffffff, 0xbfffffff, | ||
0xfffffffe, 0xfffffffd, 0xfffffffb, 0xfffffff7, 0xffffffef, 0xffffffdf, 0xffffffbf, 0xffffff7f, 0xfffffeff, 0xfffffdff, 0xfffffbff, 0xfffff7ff, 0xffffefff, | ||
0xffffdfff, 0xffffbfff, 0xffff7fff, 0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff, 0xffefffff, 0xffdfffff, 0xffbfffff, 0xff7fffff, 0xfeffffff, 0xfdffffff, | ||
0xfbffffff, 0xf7ffffff, 0xefffffff, 0xdfffffff, 0xbfffffff, | ||
]; | ||
@@ -57,7 +47,7 @@ /** | ||
/** | ||
* 取指定标志位的标 | ||
* @param paramFlag 存放标志的31位整数 | ||
* @param paramBitSite 对应的标志位,在[0,30]之间 | ||
* @return 返回0或1 | ||
*/ | ||
* 取指定标志位的标 | ||
* @param paramFlag 存放标志的31位整数 | ||
* @param paramBitSite 对应的标志位,在[0,30]之间 | ||
* @return 返回0或1 | ||
*/ | ||
public static GetFlag(paramFlag: number, paramBitSite: number): 0 | 1 { | ||
@@ -78,8 +68,8 @@ if (!Number.isSafeInteger(paramFlag)) { | ||
/** | ||
* 设置标志位的值 | ||
* @param paramFlag 存放标志的31位整数 | ||
* @param paramBitSite 对应的标志位,在[0,30]之间 | ||
* @param paramValue 要设置的值,只能是0或1 | ||
* @return 修改标志的新值 | ||
*/ | ||
* 设置标志位的值 | ||
* @param paramFlag 存放标志的31位整数 | ||
* @param paramBitSite 对应的标志位,在[0,30]之间 | ||
* @param paramValue 要设置的值,只能是0或1 | ||
* @return 修改标志的新值 | ||
*/ | ||
public static SetFlag(paramFlag: number, paramBitSite: number, paramValue: number) { | ||
@@ -86,0 +76,0 @@ if (!Number.isSafeInteger(paramFlag)) { |
@@ -7,10 +7,10 @@ import { common_ret } from './common_ret'; | ||
export enum EnumBufferWapperError { | ||
OK = error_common.ERR_OK, | ||
FAIL = error_common.ERR_FAIL, | ||
OK = error_common.ERR_OK, | ||
FAIL = error_common.ERR_FAIL, | ||
/** 数据为NULL */ | ||
DATA_IS_NULL = 1, | ||
DATA_IS_NULL = 1, | ||
/** 数据不是Buffer对象 */ | ||
DATA_IS_NOT_BUFFER = 2, | ||
DATA_IS_NOT_BUFFER = 2, | ||
/** 超出范围 */ | ||
OUT_OF_RANGE = 3, | ||
OUT_OF_RANGE = 3, | ||
} | ||
@@ -23,13 +23,13 @@ | ||
/** 8位整数的字节数 */ | ||
int8 = 1, | ||
int8 = 1, | ||
/** 16位整数的字节数 */ | ||
int16 = 2, | ||
int16 = 2, | ||
/** 32位整数的字节数 */ | ||
int32 = 4, | ||
int32 = 4, | ||
/** 64位整数的字节数 */ | ||
int64 = 8, | ||
int64 = 8, | ||
/** 单精度浮点数字节数 */ | ||
float = 4, | ||
float = 4, | ||
/** 双精度浮点数字节数 */ | ||
double = 8 | ||
double = 8, | ||
} | ||
@@ -51,3 +51,3 @@ | ||
*/ | ||
public constructor(paramData ?: Buffer, paramOffset ?: number) { | ||
public constructor(paramData?: Buffer, paramOffset?: number) { | ||
this.bindBuffer(paramData, paramOffset); | ||
@@ -117,3 +117,3 @@ } | ||
} else { | ||
return ((this.buffer) as Buffer).byteLength; | ||
return (this.buffer as Buffer).byteLength; | ||
} | ||
@@ -155,3 +155,2 @@ } | ||
public readInt8(): number { | ||
@@ -169,3 +168,2 @@ const ret = (this.m_buffer as Buffer).readInt8(this.m_offset); | ||
public readInt16(): number { | ||
@@ -194,3 +192,3 @@ const ret = (this.m_buffer as Buffer).readInt16BE(this.m_offset); | ||
const high = this.readInt32(); | ||
const low = this.readUInt32(); | ||
const low = this.readUInt32(); | ||
@@ -205,4 +203,3 @@ const sign = high < 0; | ||
public readString(paramEncoding: BufferEncoding ='utf8'): string { | ||
public readString(paramEncoding: BufferEncoding = 'utf8'): string { | ||
return this.readPackBuffer().toString(paramEncoding); | ||
@@ -247,3 +244,3 @@ } | ||
} else { | ||
const v= paramValue; | ||
const v = paramValue; | ||
const low = v % 0x100000000; | ||
@@ -261,3 +258,2 @@ const high = (v - low) / 0x100000000; | ||
public writeDouble(paramValue: number): void { | ||
@@ -268,3 +264,3 @@ (this.m_buffer as Buffer).writeDoubleBE(paramValue, this.m_offset); | ||
public writeBuffer(paramBuffer: Buffer, paramBytes ?:number): void { | ||
public writeBuffer(paramBuffer: Buffer, paramBytes?: number): void { | ||
const bytes = Number.isSafeInteger(paramBytes) ? (paramBytes as number) : paramBuffer.byteLength; | ||
@@ -280,8 +276,6 @@ paramBuffer.copy(this.m_buffer as Buffer, this.m_offset, 0, bytes); | ||
public writeString(paramString: string, paramEncoding: BufferEncoding ='utf8'): void { | ||
public writeString(paramString: string, paramEncoding: BufferEncoding = 'utf8'): void { | ||
this.writePackBuffer(Buffer.from(paramString, paramEncoding)); | ||
} | ||
/** | ||
@@ -293,3 +287,3 @@ * 绑定buffer对象 | ||
*/ | ||
public bindBuffer(paramBuffer ?: Buffer, paramOffset ?: number): common_ret { | ||
public bindBuffer(paramBuffer?: Buffer, paramOffset?: number): common_ret { | ||
const ret = new common_ret(); | ||
@@ -302,6 +296,6 @@ do { | ||
if (!Buffer.isBuffer(paramBuffer)) { | ||
ret.setError(EnumBufferWapperError.DATA_IS_NOT_BUFFER, `paramBuffer不是Buffer对象!`); | ||
ret.setError(EnumBufferWapperError.DATA_IS_NOT_BUFFER, 'paramBuffer不是Buffer对象!'); | ||
break; | ||
} | ||
const offset = Number.isSafeInteger(paramOffset as unknown) ? (paramOffset as number) : 0 | ||
const offset = Number.isSafeInteger(paramOffset as unknown) ? (paramOffset as number) : 0; | ||
// ESLint检查这块,不能正确识别参数,只好as一下,语法糖,无性能影响 | ||
@@ -308,0 +302,0 @@ if (!this.checkOffset(offset, (paramBuffer as unknown as Buffer).byteLength, ret)) { |
// const _ = require("lodash"); | ||
const {utils} = require('./utils'); | ||
import { utils } from './utils'; | ||
/** 货币精度 */ | ||
@@ -17,3 +17,3 @@ const Precision = 100; | ||
// 基本单位 | ||
const cnIntRadice =['', '拾', '佰', '仟']; | ||
const cnIntRadice = ['', '拾', '佰', '仟']; | ||
// 对应整数部分扩展单位 | ||
@@ -55,3 +55,3 @@ const cnIntUnits = ['', '万', '亿', '兆']; | ||
function Parse(paramValue: number | string) { | ||
const r = {value: 0, errFlag: false, errMsg: ''}; | ||
const r = { value: 0, errFlag: false, errMsg: '' }; | ||
if (typeof paramValue === 'number') { | ||
@@ -89,7 +89,7 @@ if (paramValue > MAX_VALUE || paramValue < MIN_VALUE) { | ||
/** 指定输出大写的前缀,默认为:人民币 */ | ||
prefix ?: string; | ||
prefix?: string; | ||
/** 是否负数字符:如负 */ | ||
negative ?: string; | ||
negative?: string; | ||
/** 关于“整”的定义 */ | ||
zheng ?: string; | ||
zheng?: string; | ||
} | ||
@@ -134,4 +134,4 @@ | ||
private m_intValue: number; | ||
private m_errFlag : boolean; | ||
private m_errMsg : string; | ||
private m_errFlag: boolean; | ||
private m_errMsg: string; | ||
/** | ||
@@ -148,3 +148,3 @@ * 构造函数 | ||
} else { | ||
const v = Parse(paramValue as (string| number)); | ||
const v = Parse(paramValue as string | number); | ||
if (v.errFlag) { | ||
@@ -162,3 +162,3 @@ this.m_intValue = 0; | ||
/** 判断指定的对象,是不是指定的CNYCurrency对象 */ | ||
public static isCurrency(paramV: any): boolean { | ||
public static isCurrency(paramV: unknown): boolean { | ||
return paramV instanceof CNYCurrency; | ||
@@ -183,3 +183,3 @@ } | ||
} else { | ||
const v = Parse(paramValue as (string| number)); | ||
const v = Parse(paramValue as string | number); | ||
if (v.errFlag) { | ||
@@ -355,3 +355,3 @@ this.m_intValue = 0; | ||
const n = this.m_intValue; | ||
return (n - n % Precision)/Precision; | ||
return (n - (n % Precision)) / Precision; | ||
} | ||
@@ -389,3 +389,3 @@ /** | ||
if (utils.isObject(paramOpts)) { | ||
// 人民币前缀 | ||
// 人民币前缀 | ||
if (utils.isString(paramOpts.prefix)) { | ||
@@ -411,3 +411,3 @@ stPrefix = paramOpts.prefix as string; | ||
if (intValue < 0) { | ||
negative = stNegative;// '负'; | ||
negative = stNegative; // '负'; | ||
} | ||
@@ -428,3 +428,3 @@ | ||
if (this.intValue === 0) { | ||
// 如果金额为0 | ||
// 如果金额为0 | ||
chineseStr = [stPrefix, cnNums[0], cnIntLast, stZheng].join(''); | ||
@@ -435,4 +435,4 @@ return chineseStr; | ||
if (yuan === 0 && cent < 10) { | ||
// 如果只存在分的情况 就是零元零角几分 | ||
// chineseStr = [paramPrefix, negative, cnNums[0], cnIntLast, cnNums[0], cnDecUnits[0],cnNums[cent],cnDecUnits[1]].join(''); | ||
// 如果只存在分的情况 就是零元零角几分 | ||
// chineseStr = [paramPrefix, negative, cnNums[0], cnIntLast, cnNums[0], cnDecUnits[0],cnNums[cent],cnDecUnits[1]].join(''); | ||
chineseStr = [stPrefix, negative, cnNums[cent], cnDecUnits[1]].join(''); | ||
@@ -466,3 +466,3 @@ return chineseStr; | ||
} else if (yuan === 0 && cent > 0) { | ||
// chineseStr = cnNums[0] + cnIntLast; | ||
// chineseStr = cnNums[0] + cnIntLast; | ||
} | ||
@@ -484,4 +484,4 @@ | ||
} | ||
if ((cent % 10) === 0) { | ||
// 当分为0的时候,有整 | ||
if (cent % 10 === 0) { | ||
// 当分为0的时候,有整 | ||
chineseStr += stZheng; | ||
@@ -516,3 +516,3 @@ } | ||
} | ||
return [strSymbol, negative, yuan, '.', cent].join('');// `${strSymbol}${negative}${yuan}.${cent}`; | ||
return [strSymbol, negative, yuan, '.', cent].join(''); // `${strSymbol}${negative}${yuan}.${cent}`; | ||
} | ||
@@ -519,0 +519,0 @@ |
@@ -16,15 +16,14 @@ // 这里提供一些编解码的功能函数 | ||
/** hex 16进制编码 */ | ||
const EncodingHex : HexBase64Encoding = 'hex'; | ||
const EncodingHex: HexBase64Encoding = 'hex'; | ||
/** utf-8 字符集编码 */ | ||
const EncodingUTF8 = 'utf8'; | ||
/** 函数MD5FromArgs中 md5 生成选项 */ | ||
export interface IMD5Options { | ||
/** 生成后的编码,默认是hex */ | ||
encode ?: HexBase64Encoding, | ||
encode?: HexBase64Encoding; | ||
/** 是否是大写, 默认是小写 */ | ||
capital ?: boolean, | ||
capital?: boolean; | ||
/** 多个参数之间的分隔符,默认是"" */ | ||
split ?: string | ||
split?: string; | ||
} | ||
@@ -50,3 +49,3 @@ /** | ||
*/ | ||
public static StringBase64Decode(paramBase64Value: string, encoding ?: string): string { | ||
public static StringBase64Decode(paramBase64Value: string, encoding?: string): string { | ||
return Buffer.from(paramBase64Value, EncodingBase64).toString(encoding); | ||
@@ -63,4 +62,3 @@ } | ||
const hash = crypto.createHmac(EnumCryptoAlgorithm.sha256, paramKey); | ||
return hash.update(paramText) | ||
.digest(EncodingHex); | ||
return hash.update(paramText).digest(EncodingHex); | ||
} | ||
@@ -102,2 +100,3 @@ | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
public static MD5FromArgs(paramOptions: IMD5Options, ...args: any[]) { | ||
@@ -109,3 +108,3 @@ let encode = EncodingHex; | ||
if (_.isObjectLike(paramOptions)) { | ||
if (paramOptions.encode === EncodingHex|| paramOptions.encode === EncodingBase64) { | ||
if (paramOptions.encode === EncodingHex || paramOptions.encode === EncodingBase64) { | ||
encode = paramOptions.encode; | ||
@@ -128,3 +127,4 @@ } | ||
if (capital) { // 如果是要求大写 | ||
if (capital) { | ||
// 如果是要求大写 | ||
md5string = md5string.toUpperCase(); | ||
@@ -131,0 +131,0 @@ } |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { error_utils } from './common_error'; | ||
@@ -8,4 +9,4 @@ import { error_common } from './constant'; | ||
/** 错误码 */ | ||
err : number; | ||
msg : string; | ||
err: number; | ||
msg: string; | ||
data: T | null; | ||
@@ -17,5 +18,5 @@ isOK: boolean; | ||
/** 错误码 */ | ||
err : number; | ||
err: number; | ||
/** 错误信息 */ | ||
errmsg : string; | ||
errmsg: string; | ||
} | ||
@@ -32,5 +33,5 @@ | ||
export class common_ret implements ICommonRetData<any> { | ||
private m_err : number = error_common.ERR_OK; | ||
private m_msg : string = ''; | ||
private m_data: any = null; | ||
private m_err: number = error_common.ERR_OK; | ||
private m_msg: string = ''; | ||
private m_data: any = null; | ||
/** | ||
@@ -43,5 +44,5 @@ * 构造函数 | ||
public constructor(paramErr: number = error_common.ERR_OK, paramMsg: string = '', paramData: any = null) { | ||
this.m_err = paramErr; // 错误码 | ||
this.m_msg = paramMsg; // 错误信息 | ||
this.m_data = paramData; // 返回的数据,默认空数据 | ||
this.m_err = paramErr; // 错误码 | ||
this.m_msg = paramMsg; // 错误信息 | ||
this.m_data = paramData; // 返回的数据,默认空数据 | ||
} | ||
@@ -169,3 +170,3 @@ /** | ||
public setOK(data = null): common_ret { | ||
this.m_err = error_common.ERR_OK; | ||
this.m_err = error_common.ERR_OK; | ||
this.m_data = data; | ||
@@ -196,3 +197,3 @@ return this; | ||
public addErrorPre(paramMsgPre: string): common_ret { | ||
this.m_msg =`${paramMsgPre}${this.m_msg}`; | ||
this.m_msg = `${paramMsgPre}${this.m_msg}`; | ||
return this; | ||
@@ -207,3 +208,3 @@ } | ||
public copyTo(paramHead: ICommonMsgHead): common_ret { | ||
paramHead.err = this.m_err; | ||
paramHead.err = this.m_err; | ||
paramHead.errmsg = this.m_msg; | ||
@@ -246,4 +247,4 @@ return this; | ||
isOK: this.isOK, | ||
err : this.m_err, | ||
msg : this.m_msg, | ||
err: this.m_err, | ||
msg: this.m_msg, | ||
data: this.m_data, | ||
@@ -254,3 +255,2 @@ }; | ||
/** | ||
@@ -274,5 +274,5 @@ * 这是一个新增的通用返回类, 因为common_ret已经在很多项目使用了,变更它的设计可能会引用很多问题,所以 | ||
public constructor(paramErr: number = error_common.ERR_OK, paramMsg: string = '', paramData: any = null) { | ||
this.m_err = paramErr; // 错误码 | ||
this.m_msg = paramMsg; // 错误信息 | ||
this.m_data = paramData; // 返回的数据,默认空数据 | ||
this.m_err = paramErr; // 错误码 | ||
this.m_msg = paramMsg; // 错误信息 | ||
this.m_data = paramData; // 返回的数据,默认空数据 | ||
} | ||
@@ -287,3 +287,3 @@ /** | ||
*/ | ||
public setError(paramErr: number, paramMsg: string = '', paramData: T | null = null, paramMsgPre: string | null = null): XCommonRet<T> { | ||
public setError(paramErr: number, paramMsg: string = '', paramData: T | null = null, paramMsgPre: string | null = null): XCommonRet<T> { | ||
this.m_err = paramErr; | ||
@@ -401,3 +401,3 @@ if (utils.isNotNull(paramMsgPre)) { | ||
public setOK(data = null): XCommonRet<T> { | ||
this.m_err = error_common.ERR_OK; | ||
this.m_err = error_common.ERR_OK; | ||
this.m_data = data; | ||
@@ -428,3 +428,3 @@ return this; | ||
public addErrorPre(paramMsgPre: string): XCommonRet<T> { | ||
this.m_msg =`${paramMsgPre}${this.m_msg}`; | ||
this.m_msg = `${paramMsgPre}${this.m_msg}`; | ||
return this; | ||
@@ -439,3 +439,3 @@ } | ||
public copyTo(paramHead: ICommonMsgHead): XCommonRet<T> { | ||
paramHead.err = this.m_err; | ||
paramHead.err = this.m_err; | ||
paramHead.errmsg = this.m_msg; | ||
@@ -478,4 +478,4 @@ return this; | ||
isOK: this.isOK, | ||
err : this.m_err, | ||
msg : this.m_msg, | ||
err: this.m_err, | ||
msg: this.m_msg, | ||
data: this.m_data, | ||
@@ -482,0 +482,0 @@ }; |
// 这里定义一些必要的常量 | ||
/** 内存的容量常量定义 */ | ||
export enum MemorySize{ | ||
export enum MemorySize { | ||
/** 1K字节数 1024 */ | ||
@@ -29,3 +29,2 @@ K = 1024, | ||
/** | ||
@@ -35,10 +34,10 @@ * 日期时间的常量 | ||
export enum DatetimeConstant { | ||
/** 最小的UTC时间 */ | ||
MIN_UTC = 1, | ||
/** 最大的UTC时间 */ | ||
MAX_UTC = 253370736000000, | ||
/** 无效的UTC时间 */ | ||
INVALID_UTC= 0, | ||
/** 每天最大的毫少数 */ | ||
MILLIS_PRE_DAY = 86400000, | ||
/** 最小的UTC时间 */ | ||
MIN_UTC = 1, | ||
/** 最大的UTC时间 */ | ||
MAX_UTC = 253370736000000, | ||
/** 无效的UTC时间 */ | ||
INVALID_UTC = 0, | ||
/** 每天最大的毫少数 */ | ||
MILLIS_PRE_DAY = 86400000, | ||
/** 每分钟的秒数 */ | ||
@@ -48,2 +47,2 @@ SECOND_PRE_MINUTE = 60, | ||
MILLIS_PRE_SECOND = 1000, | ||
}; | ||
} |
// 这里将提供日期相关的工具函数 | ||
import {DatetimeConstant} from './constant'; | ||
import { DatetimeConstant } from './constant'; | ||
@@ -67,5 +67,5 @@ const PadRadix = 10; | ||
/** | ||
* 取当前本地时间戳 | ||
* @return 当前本地时间戳 | ||
*/ | ||
* 取当前本地时间戳 | ||
* @return 当前本地时间戳 | ||
*/ | ||
public static getLocalNow(): number { | ||
@@ -148,4 +148,10 @@ return Date.now() - TimeZoneMillis; | ||
*/ | ||
public static dateString(paramDate: Date, paramMillisFlag = true, paramDaySplit = '-', paramTimeSplit = ':', paramMillisSplit = '.', | ||
paramDatetimeSplit = ' '): string { | ||
public static dateString( | ||
paramDate: Date, | ||
paramMillisFlag = true, | ||
paramDaySplit = '-', | ||
paramTimeSplit = ':', | ||
paramMillisSplit = '.', | ||
paramDatetimeSplit = ' ', | ||
): string { | ||
const d = paramDate; | ||
@@ -172,4 +178,11 @@ const dateString = [d.getFullYear(), pad2(d.getMonth() + 1), pad2(d.getDate())].join(paramDaySplit); | ||
const d = paramDate; | ||
const dateString = [d.getFullYear(), pad2(d.getMonth()+1), pad2(d.getDate()), '_', | ||
pad2(d.getHours()), pad2(d.getMinutes()), pad2(d.getSeconds()), paramMillisFlag ? pad3(d.getMilliseconds()):'', | ||
const dateString = [ | ||
d.getFullYear(), | ||
pad2(d.getMonth() + 1), | ||
pad2(d.getDate()), | ||
'_', | ||
pad2(d.getHours()), | ||
pad2(d.getMinutes()), | ||
pad2(d.getSeconds()), | ||
paramMillisFlag ? pad3(d.getMilliseconds()) : '', | ||
].join(''); | ||
@@ -220,4 +233,10 @@ return dateString; | ||
*/ | ||
public static dateStringByUTC(paramUTC: number, paramMillisFlag = true, paramDaySplit = '-', paramTimeSplit = ':', | ||
paramMillisSplt = '.', paramDatetimeSplit = ' '): string | null { | ||
public static dateStringByUTC( | ||
paramUTC: number, | ||
paramMillisFlag = true, | ||
paramDaySplit = '-', | ||
paramTimeSplit = ':', | ||
paramMillisSplt = '.', | ||
paramDatetimeSplit = ' ', | ||
): string | null { | ||
if (!this.isValidUTC(paramUTC)) { | ||
@@ -243,4 +262,10 @@ return null; | ||
*/ | ||
public static dateStringByMillis(paramLocalTime: number, paramMillisFlag = true, paramDaysSplit = '-', paramTimeSplit = ':', | ||
paramMillisSplit = '.', paramDatetimeSplit = ' '): string | null { | ||
public static dateStringByMillis( | ||
paramLocalTime: number, | ||
paramMillisFlag = true, | ||
paramDaysSplit = '-', | ||
paramTimeSplit = ':', | ||
paramMillisSplit = '.', | ||
paramDatetimeSplit = ' ', | ||
): string | null { | ||
return this.dateStringByUTC(this.ToUTCTime(paramLocalTime), paramMillisFlag, paramDaysSplit, paramTimeSplit, paramMillisSplit, paramDatetimeSplit); | ||
@@ -263,6 +288,6 @@ } | ||
/** | ||
* 将UTC时间转换为本地时间 | ||
* @param paramUTC | ||
* @return {Number} | ||
*/ | ||
* 将UTC时间转换为本地时间 | ||
* @param paramUTC | ||
* @return {Number} | ||
*/ | ||
public static ToLocalTime(paramUTC: number): number { | ||
@@ -272,6 +297,6 @@ return paramUTC - TimeZoneMillis; | ||
/** | ||
* 将本地时间转换为UTC时间 | ||
* @param paramLocalTime | ||
* @return {Number} | ||
*/ | ||
* 将本地时间转换为UTC时间 | ||
* @param paramLocalTime | ||
* @return {Number} | ||
*/ | ||
public static ToUTCTime(paramLocalTime: number): number { | ||
@@ -281,16 +306,16 @@ return paramLocalTime + TimeZoneMillis; | ||
/** | ||
* 取当天0点时间的UTC时间 | ||
* @param paramUTC 当前的UTC时间,单位毫秒 | ||
* @return | ||
*/ | ||
* 取当天0点时间的UTC时间 | ||
* @param paramUTC 当前的UTC时间,单位毫秒 | ||
* @return | ||
*/ | ||
public static getTodayZeroTime(paramUTC: number): number { | ||
const localTime = this.ToLocalTime(paramUTC); | ||
return this.ToUTCTime(localTime - localTime % DatetimeConstant.MILLIS_PRE_DAY); | ||
return this.ToUTCTime(localTime - (localTime % DatetimeConstant.MILLIS_PRE_DAY)); | ||
} | ||
/** | ||
* 判断是不是同一天 | ||
* @param paramUTC1 | ||
* @param paramUTC2 | ||
* @return {boolean} | ||
*/ | ||
* 判断是不是同一天 | ||
* @param paramUTC1 | ||
* @param paramUTC2 | ||
* @return {boolean} | ||
*/ | ||
public static isSameDay(paramUTC1: number, paramUTC2: number) { | ||
@@ -303,7 +328,7 @@ const t1 = this.getTodayZeroTime(paramUTC1); | ||
/** | ||
* 比较本地时间相关的天数差 | ||
* @param paramUTC1 毫秒数 | ||
* @param paramUTC2 毫秒数 | ||
* @return 相差的天数,同一天,返回0 | ||
*/ | ||
* 比较本地时间相关的天数差 | ||
* @param paramUTC1 毫秒数 | ||
* @param paramUTC2 毫秒数 | ||
* @return 相差的天数,同一天,返回0 | ||
*/ | ||
public static diffLocalDays(paramUTC1: number, paramUTC2: number): number { | ||
@@ -329,16 +354,16 @@ const t1 = this.CalcLocalDaysByUTC(paramUTC1); | ||
/** | ||
* 计算,元年到指定时间戳的本地天数 | ||
* @param paramUTC 指定日期的时间戳 | ||
* @return 计算出来的本地天数 | ||
*/ | ||
* 计算,元年到指定时间戳的本地天数 | ||
* @param paramUTC 指定日期的时间戳 | ||
* @return 计算出来的本地天数 | ||
*/ | ||
public static CalcLocalDaysByUTC(paramUTC: number): number { | ||
const localTime = this.ToLocalTime(paramUTC); | ||
return (localTime - localTime % DatetimeConstant.MILLIS_PRE_DAY) / DatetimeConstant.MILLIS_PRE_DAY; | ||
return (localTime - (localTime % DatetimeConstant.MILLIS_PRE_DAY)) / DatetimeConstant.MILLIS_PRE_DAY; | ||
} | ||
/** | ||
* 计算,元年到指定时间的本地天数 | ||
* @param paramDate 指定的日期 | ||
* @return 计算出来的本地天数 | ||
*/ | ||
* 计算,元年到指定时间的本地天数 | ||
* @param paramDate 指定的日期 | ||
* @return 计算出来的本地天数 | ||
*/ | ||
public static CalcLocalDaysByDate(paramDate: Date): number { | ||
@@ -345,0 +370,0 @@ return this.CalcLocalDaysByUTC(paramDate.getTime()); |
@@ -0,5 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import path from 'path'; | ||
import util from 'util'; | ||
import {utils} from './utils'; | ||
import {datetimeUtils} from './datetimeUtils'; | ||
import { utils } from './utils'; | ||
import { datetimeUtils } from './datetimeUtils'; | ||
@@ -47,5 +48,5 @@ const workdir = process.cwd(); | ||
*/ | ||
export function logPrefix(paramFilename: string, ...args: any[]): [shortpath: string, ...args: any[]] { | ||
export function logPrefix(paramFilename: string, ...args: any[]): any[] { | ||
if (paramFilename === null || paramFilename === undefined) { | ||
return [...args] as any; | ||
return [...args]; | ||
} else { | ||
@@ -61,3 +62,3 @@ return [shortpath(paramFilename), ...args]; | ||
/** log级别日志,等同于info */ | ||
log(...paramLog: any[]):void; | ||
log(...paramLog: any[]): void; | ||
info(...paramLog: any[]): void; | ||
@@ -95,3 +96,3 @@ error(...paramLog: any[]): void; | ||
// tslint:disable-next-line: no-console | ||
console.log( this.buildLog(this.name, 'TRACE', ...paramLog)); | ||
console.log(this.buildLog(this.name, 'TRACE', ...paramLog)); | ||
} | ||
@@ -133,5 +134,4 @@ public debug(...paramLog: any[]) { | ||
private m_MapLogger = new Map<string, ILog>(); | ||
private m_createLog: (paramTag:string) => ILog = (paramTag: string) => new LogConsole(paramTag); | ||
public constructor() { | ||
} | ||
private m_createLog: (paramTag: string) => ILog = (paramTag: string) => new LogConsole(paramTag); | ||
/** | ||
@@ -159,3 +159,3 @@ * 取指定tag的日志 | ||
/** 设置创建log */ | ||
public setCreateLog(paramCreateLog: (paramTag:string)=>ILog) { | ||
public setCreateLog(paramCreateLog: (paramTag: string) => ILog) { | ||
this.m_createLog = paramCreateLog; | ||
@@ -162,0 +162,0 @@ } |
@@ -1,2 +0,1 @@ | ||
const RANDOM_MULTIPLIER = 0x015a4e35; | ||
@@ -13,3 +12,3 @@ const RANDOM_INCREMENT = 1; | ||
/** Data的长度,小于指定的长度 */ | ||
DATA_SIZE_TO_LOW = 3 | ||
DATA_SIZE_TO_LOW = 3, | ||
} | ||
@@ -24,5 +23,5 @@ | ||
/** seed表示编码的种子 */ | ||
seed ?: number; | ||
seed?: number; | ||
/** data表示编码后的数据 */ | ||
data ?: Buffer; | ||
data?: Buffer; | ||
} | ||
@@ -41,8 +40,2 @@ | ||
/** | ||
* 构造函数 | ||
*/ | ||
public constructor() { | ||
} | ||
/** | ||
* 数据编码 | ||
@@ -56,3 +49,3 @@ * @param paramSeed 编码种子 | ||
if (r !== 0) { | ||
return {code: r}; | ||
return { code: r }; | ||
} | ||
@@ -69,3 +62,3 @@ // tslint:disable-next-line: no-bitwise | ||
} | ||
return {code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet}; | ||
return { code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet }; | ||
} | ||
@@ -85,9 +78,12 @@ /** | ||
private static __checkParam(paramSeed: number, paramData: Buffer, paramMinLength = 0): EnumSimpleCodeError { | ||
if (!Number.isInteger(paramSeed)) { // 如果不是整数 | ||
if (!Number.isInteger(paramSeed)) { | ||
// 如果不是整数 | ||
return EnumSimpleCodeError.SEED_NOT_INTEGER; | ||
} | ||
if (!Buffer.isBuffer(paramData)) { // 如果不是buffer | ||
if (!Buffer.isBuffer(paramData)) { | ||
// 如果不是buffer | ||
return EnumSimpleCodeError.DATA_NOT_BUFFER; | ||
} | ||
if (paramData.length < paramMinLength) { // 如果长度为0 | ||
if (paramData.length < paramMinLength) { | ||
// 如果长度为0 | ||
return EnumSimpleCodeError.DATA_SIZE_TO_LOW; | ||
@@ -117,3 +113,3 @@ } | ||
if (r !== 0) { | ||
return {code: r}; | ||
return { code: r }; | ||
} | ||
@@ -135,3 +131,3 @@ | ||
} | ||
return {code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet}; | ||
return { code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet }; | ||
} | ||
@@ -147,3 +143,3 @@ /** | ||
if (r !== 0) { | ||
return {code: r}; | ||
return { code: r }; | ||
} | ||
@@ -156,3 +152,3 @@ | ||
const nCnt = paramData.length; | ||
const bRet = Buffer.alloc(nCnt+1); | ||
const bRet = Buffer.alloc(nCnt + 1); | ||
bRet.writeUInt8(this.m_seed, 0); | ||
@@ -163,3 +159,3 @@ for (let i = 0; i < nCnt; i++) { | ||
} | ||
return {code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet}; | ||
return { code: EnumSimpleCodeError.OK, seed: paramSeed, data: bRet }; | ||
} | ||
@@ -174,3 +170,3 @@ /** | ||
if (r !== 0) { | ||
return {code: r}; | ||
return { code: r }; | ||
} | ||
@@ -181,3 +177,3 @@ const seed = paramData.readUInt8(0); | ||
const nCnt = paramData.length-1; | ||
const nCnt = paramData.length - 1; | ||
const bRet = Buffer.alloc(nCnt); | ||
@@ -187,7 +183,7 @@ for (let i = 0; i < nCnt; i++) { | ||
let mm = paramData.readUInt8(i+1) - rr; | ||
let mm = paramData.readUInt8(i + 1) - rr; | ||
if (mm < 0) mm = (mm + 256) % 256; | ||
bRet.writeUInt8(mm, i); | ||
} | ||
return {code: 0, seed, data: bRet}; | ||
return { code: 0, seed, data: bRet }; | ||
} | ||
@@ -194,0 +190,0 @@ } |
214
lib/utils.ts
@@ -0,5 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import _ from 'lodash'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {MemorySize} from './constant'; | ||
import { MemorySize } from './constant'; | ||
@@ -20,3 +21,3 @@ /** 日期偏移值,主要用于测试 */ | ||
/** code = 1 表示缺少必要的属性 */ | ||
MissAttrib = 1 | ||
MissAttrib = 1, | ||
} | ||
@@ -28,7 +29,7 @@ /** | ||
/** 检查对象属性结果,枚举 */ | ||
code : EnumCheckObjectCode, | ||
code: EnumCheckObjectCode; | ||
/** 多余属性名称列表 */ | ||
extra: string[], | ||
extra: string[]; | ||
/** 缺少的属性名称列表 */ | ||
lack : string[] | ||
lack: string[]; | ||
} | ||
@@ -51,7 +52,7 @@ | ||
/** | ||
* 取调用堆栈 | ||
* @static | ||
* @memberOf utils | ||
* @return 调用堆栈列表 | ||
*/ | ||
* 取调用堆栈 | ||
* @static | ||
* @memberOf utils | ||
* @return 调用堆栈列表 | ||
*/ | ||
public static GetStack(): NodeJS.CallSite[] { | ||
@@ -70,8 +71,8 @@ const orig = Error.prepareStackTrace; | ||
/** | ||
* 取当前调用所在的文件名 | ||
* @static | ||
* @memberOf utils | ||
* @param paramStack 调用堆栈列表 | ||
* @return 返回的文件名 | ||
*/ | ||
* 取当前调用所在的文件名 | ||
* @static | ||
* @memberOf utils | ||
* @param paramStack 调用堆栈列表 | ||
* @return 返回的文件名 | ||
*/ | ||
public static GetFileNameByStack(paramStack: NodeJS.CallSite[]): string | null { | ||
@@ -85,8 +86,8 @@ if (Array.isArray(paramStack) && paramStack.length > 1) { | ||
/** | ||
* 取当前调用所在的行号 | ||
* @static | ||
* @memberOf utils | ||
* @param paramStack 调用堆栈列表 | ||
* @return 返回的行号 | ||
*/ | ||
* 取当前调用所在的行号 | ||
* @static | ||
* @memberOf utils | ||
* @param paramStack 调用堆栈列表 | ||
* @return 返回的行号 | ||
*/ | ||
public static GetLineNumberByStack(paramStack: NodeJS.CallSite[]): number | null { | ||
@@ -116,7 +117,7 @@ if (Array.isArray(paramStack) && paramStack.length > 1) { | ||
/** | ||
* 取当前调用堆栈信息 | ||
* @static | ||
* @memberOf utils | ||
* @return 当前的栈信息 | ||
*/ | ||
* 取当前调用堆栈信息 | ||
* @static | ||
* @memberOf utils | ||
* @return 当前的栈信息 | ||
*/ | ||
public static GetStackInfo(): NodeJS.CallSite | null { | ||
@@ -132,6 +133,6 @@ const stackList = this.GetStack(); | ||
/** | ||
* 将src的属性复制到dest,只要用for in能够访问到的,都需要复制 | ||
* @param paramDest 接收属的目标 | ||
* @param paramSrc 定义属性的目标 | ||
*/ | ||
* 将src的属性复制到dest,只要用for in能够访问到的,都需要复制 | ||
* @param paramDest 接收属的目标 | ||
* @param paramSrc 定义属性的目标 | ||
*/ | ||
public static dataAssign(paramDest: unknown, paramSrc: object): void { | ||
@@ -144,14 +145,14 @@ for (const k in paramSrc) { | ||
/** | ||
* 检查对象的属性,是否符号要求 | ||
* extra表示是多余的属性,lack表示是缺少的数据 | ||
* @static | ||
* @memberOf utils | ||
* @param paramDestObject 被检查的属性 | ||
* @param paramSimpleObject 参考属性 | ||
* @return 返回结果 | ||
* - code = EnumCheckObjectCode.TotallySuitable: 0 表示完全符合,否则存在问题 | ||
* - code = EnumCheckObjectCode.DestIsNotObject:-1 表示paramDestObject不是object对象 | ||
* - code = EnumCheckObjectCode.SampleIsNotObject:-2 表示paramSimpleObject不是object对象 | ||
* - code = EnumCheckObjectCode.MissAttrib:1 表示缺少必要的属性 | ||
*/ | ||
* 检查对象的属性,是否符号要求 | ||
* extra表示是多余的属性,lack表示是缺少的数据 | ||
* @static | ||
* @memberOf utils | ||
* @param paramDestObject 被检查的属性 | ||
* @param paramSimpleObject 参考属性 | ||
* @return 返回结果 | ||
* - code = EnumCheckObjectCode.TotallySuitable: 0 表示完全符合,否则存在问题 | ||
* - code = EnumCheckObjectCode.DestIsNotObject:-1 表示paramDestObject不是object对象 | ||
* - code = EnumCheckObjectCode.SampleIsNotObject:-2 表示paramSimpleObject不是object对象 | ||
* - code = EnumCheckObjectCode.MissAttrib:1 表示缺少必要的属性 | ||
*/ | ||
public static checkObjectProperty(paramDestObject: any, paramSimpleObject: any): ICheckObjectResult { | ||
@@ -204,3 +205,3 @@ const ret: ICheckObjectResult = { | ||
*/ | ||
public static isString(paramV: unknown) : boolean { | ||
public static isString(paramV: unknown): boolean { | ||
return _.isString(paramV); | ||
@@ -219,8 +220,8 @@ } | ||
/** | ||
* 判断指定的参数,是否是function | ||
* @static | ||
* @memberOf utils | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
* 判断指定的参数,是否是function | ||
* @static | ||
* @memberOf utils | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
public static isFunction(paramV: unknown): boolean { | ||
@@ -231,7 +232,7 @@ return _.isFunction(paramV); | ||
/** | ||
* 检查指定的参数,是否是整数 | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
* 检查指定的参数,是否是整数 | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
public static isInteger(paramV: unknown): boolean { | ||
@@ -252,7 +253,7 @@ return Number.isInteger(paramV); | ||
/** | ||
* 检查指定的参数,是否是数组 | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
* 检查指定的参数,是否是数组 | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
public static isArray(paramV: unknown) { | ||
@@ -262,7 +263,7 @@ return Array.isArray(paramV); | ||
/** | ||
* 检查指定的参数,是否是number | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
* 检查指定的参数,是否是number | ||
* @static | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
public static isNumber(paramV: unknown) { | ||
@@ -273,8 +274,8 @@ return _.isNumber(paramV); | ||
/** | ||
* 判断指定的参数,是否是Object | ||
* @static | ||
* @memberOf utils | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
* 判断指定的参数,是否是Object | ||
* @static | ||
* @memberOf utils | ||
* @param paramV 被检查的对象 | ||
* @return 如果是,则返回true,否则返回false | ||
*/ | ||
public static isObject(paramV: unknown): boolean { | ||
@@ -316,5 +317,4 @@ return _.isObject(paramV); | ||
*/ | ||
// tslint:disable-next-line: ban-types | ||
public static async WaitFunction(paramFunc: Function, ...args: any[]): Promise<any[]> { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramFunc((...result: any[]) => { | ||
@@ -339,3 +339,3 @@ resolve(result); | ||
public static async WaitFunctionEx(paramFunc: Function, ...args: any[]): Promise<any[]> { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramFunc(...args, (...result: any[]) => { | ||
@@ -359,3 +359,3 @@ resolve(result); | ||
public static async WaitClassFunction(paramObject: any, paramFunctionName: string, ...args: any[]): Promise<any[]> { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramObject[paramFunctionName]((...result: any[]) => { | ||
@@ -367,3 +367,2 @@ resolve(result); | ||
/** | ||
@@ -381,3 +380,3 @@ * 异步调用类成员函数,注意:要求最后一个参数回调函数 | ||
public static async WaitClassFunctionEx(paramObject: any, paramFunctionName: string, ...args: any[]): Promise<any[]> { | ||
return new Promise((resolve) => { | ||
return new Promise(resolve => { | ||
paramObject[paramFunctionName](...args, (...result: any[]) => { | ||
@@ -457,12 +456,13 @@ resolve(result); | ||
return bytes.toString(10); | ||
} else if (bytes < MemorySize.M) { // 1KB | ||
} else if (bytes < MemorySize.M) { | ||
// 1KB | ||
return (bytes / MemorySize.K).toFixed(2) + 'KB'; | ||
} else if (bytes < MemorySize.G) // 1M | ||
{ | ||
} else if (bytes < MemorySize.G) { | ||
// 1M | ||
return (bytes / MemorySize.M).toFixed(2) + 'MB'; | ||
} else if (bytes < MemorySize.T) // 1T | ||
{ | ||
} else if (bytes < MemorySize.T) { | ||
// 1T | ||
return (bytes / MemorySize.G).toFixed(2) + 'GB'; | ||
} else if (bytes < MemorySize.P) // 1T | ||
{ | ||
} else if (bytes < MemorySize.P) { | ||
// 1T | ||
return (bytes / MemorySize.T).toFixed(2) + 'TB'; | ||
@@ -490,3 +490,3 @@ } else { | ||
*/ | ||
public static keyValues(paramObject: any): { keys: string[], values: any[] } { | ||
public static keyValues(paramObject: any): { keys: string[]; values: any[] } { | ||
const r = { | ||
@@ -529,3 +529,2 @@ keys: Object.keys(paramObject), | ||
for (let f = fmt.length - 1; f >= 0; f--) { | ||
@@ -537,3 +536,4 @@ switch (fmt.substr(f, 1)) { | ||
case '0': | ||
if (i >= 0) retString = str.substr(i--, 1) + retString; else retString = '0' + retString; | ||
if (i >= 0) retString = str.substr(i--, 1) + retString; | ||
else retString = '0' + retString; | ||
break; | ||
@@ -569,3 +569,4 @@ case ',': | ||
case '0': | ||
if (i < str.length) retString += str.substr(i++, 1); else retString += '0'; | ||
if (i < str.length) retString += str.substr(i++, 1); | ||
else retString += '0'; | ||
break; | ||
@@ -603,3 +604,3 @@ default: | ||
return n; | ||
}; | ||
} | ||
/** | ||
@@ -618,3 +619,3 @@ * 将字符串转换为json,如果出错返回undefined | ||
return undefined; | ||
}; | ||
} | ||
/** | ||
@@ -631,3 +632,3 @@ * 原路径移动到新路径 | ||
*/ | ||
public static async renameFile(paramOldFilename: string, paramNewFilename: string): Promise<{ret: boolean, errInfo: string}> { | ||
public static async renameFile(paramOldFilename: string, paramNewFilename: string): Promise<{ ret: boolean; errInfo: string }> { | ||
const [error] = await this.WaitClassFunctionEx(fs, 'rename', paramOldFilename, paramNewFilename); | ||
@@ -677,3 +678,3 @@ if (utils.isNull(error)) { | ||
*/ | ||
public static mkdirsSyncEx(paramPath: string, paramMode = 0o777): {ret: boolean, msg: string} { | ||
public static mkdirsSyncEx(paramPath: string, paramMode = 0o777): { ret: boolean; msg: string } { | ||
const r = { | ||
@@ -686,3 +687,4 @@ ret: false, | ||
let pathTemp: string; | ||
paramPath.split(/[\/\\]/).forEach((dirName) => { // 这里指用/ 或\ 都可以分隔目录 如 linux的/usr/local/services 和windows的 d:\temp\aaaa | ||
paramPath.split(/[/\\]/).forEach(dirName => { | ||
// 这里指用/ 或\ 都可以分隔目录 如 linux的/usr/local/services 和windows的 d:\temp\aaaa | ||
if (pathTemp) { | ||
@@ -718,3 +720,3 @@ pathTemp = path.join(pathTemp, dirName); | ||
public static roundPercentage(paramValue: number | string): number { | ||
/** 最小保留的位数 */ | ||
/** 最小保留的位数 */ | ||
const minNumber = 1000000; | ||
@@ -763,4 +765,4 @@ /** 精度 */ | ||
*/ | ||
public static options(paramArgs: string[]): {_: string[], args: object} { | ||
/** | ||
public static options(paramArgs: string[]): { _: string[]; args: object } { | ||
/** | ||
* 取参数名称 | ||
@@ -771,9 +773,11 @@ * - | ||
*/ | ||
function GetArgsName(paramArg: string): { isArg: boolean, argName: string, argOri: string } { | ||
const localRet = {isArg: false, argName: '', argOri: paramArg}; | ||
function GetArgsName(paramArg: string): { isArg: boolean; argName: string; argOri: string } { | ||
const localRet = { isArg: false, argName: '', argOri: paramArg }; | ||
let strName = null; | ||
if (paramArg.substring(0, 2) === '--') { // 如果是前缀-- | ||
if (paramArg.substring(0, 2) === '--') { | ||
// 如果是前缀-- | ||
strName = paramArg.substring(2).trim(); | ||
} else if (paramArg.substring(0, 1) === '-') { // 如果是前缀- | ||
} else if (paramArg.substring(0, 1) === '-') { | ||
// 如果是前缀- | ||
strName = paramArg.substring(1).trim(); | ||
@@ -791,3 +795,3 @@ } else { | ||
const ret = {_: [] as string[], args: {} as any}; | ||
const ret = { _: [] as string[], args: {} as any }; | ||
@@ -813,3 +817,4 @@ let args = paramArgs || []; | ||
if (argPre.is) { // 如果存在前缀 | ||
if (argPre.is) { | ||
// 如果存在前缀 | ||
ret.args[argPre.argName] = arg; | ||
@@ -836,3 +841,4 @@ | ||
if (argPre.is) { // 如果存在前缀,但是,没有值,则加到_中 | ||
if (argPre.is) { | ||
// 如果存在前缀,但是,没有值,则加到_中 | ||
ret._.push(argPre.argOri); | ||
@@ -865,3 +871,3 @@ } | ||
public static randomBetween(paramMin: number, paramMax: number) { | ||
return this.randomInteger() % (paramMax - paramMin + 1) + paramMin; | ||
return (this.randomInteger() % (paramMax - paramMin + 1)) + paramMin; | ||
} | ||
@@ -868,0 +874,0 @@ } |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import fs from 'fs'; | ||
@@ -16,7 +17,7 @@ import path from 'path'; | ||
*/ | ||
export function watchRequire( paramCallback: (paramData: any) => void, paramPath: string, paramFile: string, paramChangeCallback: boolean = true): void { | ||
export function watchRequire(paramCallback: (paramData: any) => void, paramPath: string, paramFile: string, paramChangeCallback = true): void { | ||
const realPath = path.join(paramPath, paramFile); | ||
if (!callbackmap[realPath]) { | ||
const cbList: TCallBack [] = []; | ||
const cbList: TCallBack[] = []; | ||
callbackmap[realPath] = cbList; | ||
@@ -30,2 +31,3 @@ | ||
for (let i = len; 0 <= i; i--) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
cbList[i](require(realPath)); | ||
@@ -38,4 +40,5 @@ } | ||
if (!paramChangeCallback) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
paramCallback(require(realPath)); // 只有变化 | ||
} | ||
} |
{ | ||
"name": "xmcommon", | ||
"version": "0.9.10", | ||
"version": "0.9.11", | ||
"description": "javascript common lib for es6", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"compile": "tsc", | ||
"format": "prettier --write \"lib/**/*.ts\"", | ||
"lint": "eslint \"lib/**/*.ts\"", | ||
"build": "npm run lint & tsc", | ||
"compile": "npm run lint & tsc", | ||
"test": "mocha" | ||
@@ -38,8 +40,9 @@ }, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.176", | ||
"@types/lodash": "^4.14.177", | ||
"@types/node": "^8.10.66", | ||
"@typescript-eslint/eslint-plugin": "^5.3.1", | ||
"@typescript-eslint/parser": "^5.3.1", | ||
"@typescript-eslint/eslint-plugin": "^5.4.0", | ||
"@typescript-eslint/parser": "^5.4.0", | ||
"eslint": "^8.2.0", | ||
"eslint-config-google": "^0.14.0", | ||
"prettier": "^2.4.1", | ||
"prettier-eslint": "^13.0.0", | ||
@@ -46,0 +49,0 @@ "typescript-tslint-plugin": "^1.0.1" |
@@ -39,3 +39,6 @@ # xmcommon | ||
# 版本变更说明 | ||
## 0.9.11 | ||
- 2021-11-16 | ||
- \* 使用prettier格式化代码 | ||
- \* 使用eslint对代码进行检查 | ||
## 0.9.10 | ||
@@ -42,0 +45,0 @@ - 2021-11-15 |
@@ -1,2 +0,2 @@ | ||
let { utils } = require('../dist/index'); | ||
import { utils } from '../dist/index'; | ||
let assert = require('assert').strict; | ||
@@ -3,0 +3,0 @@ describe('utils', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
297315
50
8271
289
9