mm_expand 2.4.3 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base.js +1 -1
- package/lib/object.js +3 -2
- package/lib/string.js +2 -1
- package/package.json +2 -2
package/lib/base.js
CHANGED
|
@@ -861,7 +861,7 @@ Base.prototype._helpFormatResult = function (target) {
|
|
|
861
861
|
}
|
|
862
862
|
} else if (Array.isArray(target)) {
|
|
863
863
|
try {
|
|
864
|
-
return JSON.stringify(target);
|
|
864
|
+
return JSON.stringify(target, null, 2);
|
|
865
865
|
} catch (error) {
|
|
866
866
|
this.log('error', '序列化数组失败', error);
|
|
867
867
|
return '[Array]';
|
package/lib/object.js
CHANGED
|
@@ -337,11 +337,12 @@ function isEmptyValue(value, zero = false) {
|
|
|
337
337
|
* 转为json字符串
|
|
338
338
|
* @param {object} source 被转换的对象
|
|
339
339
|
* @param {boolean} format 是否格式化
|
|
340
|
+
* @param {number} space 缩进宽度,默认2个空格
|
|
340
341
|
* @returns {string} json格式字符串
|
|
341
342
|
*/
|
|
342
|
-
function toJson(source, format) {
|
|
343
|
+
function toJson(source, format, space = 2) {
|
|
343
344
|
if (format) {
|
|
344
|
-
return JSON.stringify(source, null,
|
|
345
|
+
return JSON.stringify(source, null, space);
|
|
345
346
|
} else {
|
|
346
347
|
return JSON.stringify(source);
|
|
347
348
|
}
|
package/lib/string.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const json5 = require('json5');
|
|
5
5
|
const pinyin = require('pinyinlite');
|
|
6
6
|
const { createHash, createCipheriv, createDecipheriv } = require('crypto');
|
|
7
|
+
const { XMLParser } = require('fast-xml-parser');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* form-data转对象
|
|
@@ -132,7 +133,7 @@ String.prototype.toJson = function () {
|
|
|
132
133
|
*/
|
|
133
134
|
String.prototype.toXml = function () {
|
|
134
135
|
try {
|
|
135
|
-
const parser = new
|
|
136
|
+
const parser = new XMLParser();
|
|
136
137
|
return parser.parse(this);
|
|
137
138
|
} catch (error) {
|
|
138
139
|
throw new Error('xml反序列化错误: ' + error.message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.5",
|
|
4
4
|
"description": "超级美眉原型函数扩展模块 - 增强的字符串、数组、对象、日期操作,具备错误预防功能并简化业务逻辑",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"eslint": "^10.6.0",
|
|
49
|
-
"eslint-plugin-jsdoc": "^63.0.
|
|
49
|
+
"eslint-plugin-jsdoc": "^63.0.12",
|
|
50
50
|
"mm_eslint": "^1.7.5"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|