Socket
Socket
Sign inDemoInstall

xmcommon

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmcommon - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

lib/bitUtils.js

13

example/test.js

@@ -7,2 +7,15 @@ function testLog() {

function testwritedir(paramPath) {
let comm = require("../index");
let log = comm.getLogger(__filename);
let utils = comm.utils;
let path = "c:/a/b/c/d/e/f/g";
let r = utils.mkdirsSync(path);
log.info("make path:" + path + " result=" + r);
let v = utils.ToInteger("100",99);
let v1 = utils.ToInteger("abcd1111100",99);
log.info("v=" + v + ",v1=" + v1);
}
testLog();
testwritedir();

4

lib/index.js

@@ -10,2 +10,3 @@ const { datetimeUtils } = require('./datetimeUtils');

const { common_ret } = require("./common_ret");
const { bitUtils } = require("./bitUtils");

@@ -24,4 +25,5 @@ exports = module.exports = {

error_common,
common_ret,
common_ret,
bitUtils,
error_utils
};
const _ = require("lodash");
const fs = require("fs");
const path = require("path");

@@ -292,2 +294,3 @@ /**内存的容量常量定义*/

/**

@@ -465,3 +468,73 @@ * 异步调用类成员函数,注意:要求第一个参数回调函数

}
/**
* 将指定的内容,转换为整数,如果转换失败,则用缺省值
* @param {String} paramSrcInteger 要被转换为整数的字符串
* @param {Number} paramDefault 缺省值
* @return {Number} 转换后的整数
*/
static ToInteger (paramSrcInteger, paramDefault = 0) {
let n = Number.parseInt(paramSrcInteger);
if(Number.isNaN(n)) {
n = paramDefault;
}
return n;
}
/**
* 将指定的内容,转换为数字,如果转换失败,则用缺省值
* @param {string} paramSrcNumber 要被转换为数字的字符串
* @param {number} paramDefault 缺省值
* @return {number} 转换后的浮点数
*/
static ToFloat(paramSrcNumber, paramDefault = 0) {
let n = Number.parseFloat(paramSrcNumber);
if (Number.isNaN(n)) {
n = paramDefault;
}
return n;
};
/**
* 将字符串转换为json,如果出错返回undefined
* 这个主要的做是,对异常做了处理,减少其它地方对异常处理的问题。
* @param {String} paramJsonString Json格式的字符串
* @return {*} 转换后的对象
*/
static JsonParse (paramJsonString) {
try{
let r = JSON.parse(paramJsonString);
return r;
}catch(e) {
//
}
return undefined;
};
/**
* 创建目录
* @param {string} dirpath 要创建的目录,支持多层级创建
* @param {number} mode 创建后,目录的权限,默认为0o777
* @return {boolean} 返回创建结果
*/
static mkdirsSync(dirpath, mode) {
try {
if (!fs.existsSync(dirpath)) {
let pathtmp;
dirpath.split(/[/\\]/).forEach((dirname)=> { //这里指用/ 或\ 都可以分隔目录 如 linux的/usr/local/services 和windows的 d:\temp\aaaa
if (pathtmp) {
pathtmp = path.join(pathtmp, dirname);
} else {
pathtmp = dirname;
}
if (!fs.existsSync(pathtmp)) {
if (!fs.mkdirSync(pathtmp, mode)) {
return false;
}
}
});
}
return true;
} catch (e) {
let log = require("./log").getLogger(__filename);
log.error("create director fail! path=" + dirpath + " errorMsg:" + e);
return false;
}
}
}

@@ -468,0 +541,0 @@ exports = module.exports = {

{
"name": "xmcommon",
"version": "0.0.5",
"version": "0.0.6",
"description": "javascript common lib for es6",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,2 +11,6 @@ # xmcommon

# 版本变更说明
## 0.06
- 2018-11-01
- \+ 增加了bitUtil对整数位处理函数,可以用于标志位处理
- \+ 增加utils中的ToInteger, ToFloat, JsonParse和mkdirsSync等几个函数
## 0.0.5

@@ -13,0 +17,0 @@ - 2018-10-31

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