mm_config 2.1.5 → 2.1.6

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "test": "cache1_new"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "test": "cache2_new"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "test": "cache3_new"
3
+ }
package/config1.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "test1",
3
+ "state": 1,
4
+ "sort": 1,
5
+ "age": 26
6
+ }
package/config2.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "test2",
3
+ "sort": 2
4
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "asyncTest2",
3
+ "state": 3,
4
+ "timestamp": "2025-12-16T06:38:43.309Z"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "debounceDemo",
3
+ "value": 4,
4
+ "timestamp": "2025-12-16T06:38:43.314Z"
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "json5Demo",
3
+ "description": "This uses JSON5 format"
4
+ }
@@ -0,0 +1,68 @@
1
+ const jsdoc = require('eslint-plugin-jsdoc');
2
+
3
+ module.exports = [
4
+ {
5
+ files: ['lib/**/*.js'],
6
+ languageOptions: {
7
+ ecmaVersion: 2020,
8
+ sourceType: 'script'
9
+ },
10
+ plugins: {
11
+ jsdoc: jsdoc
12
+ },
13
+ rules: {
14
+ // JSDoc相关规则 - 设置为error级别强制要求
15
+ 'jsdoc/require-jsdoc': ['error', {
16
+ require: {
17
+ FunctionDeclaration: true,
18
+ MethodDefinition: true,
19
+ ClassDeclaration: true,
20
+ ArrowFunctionExpression: true
21
+ }
22
+ }],
23
+ 'jsdoc/check-param-names': 'off',
24
+ 'jsdoc/check-tag-names': 'off',
25
+ 'jsdoc/check-types': 'off',
26
+ 'jsdoc/require-param': 'off',
27
+ 'jsdoc/require-param-description': 'off',
28
+ 'jsdoc/require-returns': 'off',
29
+ 'jsdoc/require-returns-description': 'off',
30
+
31
+ // 基础语法规则
32
+ 'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
33
+ 'no-console': 'warn',
34
+
35
+ // 代码风格规则
36
+ 'indent': ['error', 2],
37
+ 'quotes': ['error', 'single'],
38
+ 'semi': ['error', 'always'],
39
+ 'comma-dangle': ['error', 'never'],
40
+ 'no-trailing-spaces': 'error',
41
+ 'eol-last': 'error',
42
+ 'max-len': ['error', { code: 100 }],
43
+ 'max-lines-per-function': ['error', { max: 40 }],
44
+ 'complexity': ['error', 12],
45
+ 'max-depth': ['error', 4],
46
+ 'max-params': ['error', 4],
47
+
48
+ // 命名规则
49
+ 'id-length': ['error', {
50
+ min: 1,
51
+ max: 20,
52
+ properties: 'always'
53
+ }]
54
+ }
55
+ },
56
+ {
57
+ files: ['test/**/*.js'],
58
+ languageOptions: {
59
+ ecmaVersion: 2020,
60
+ sourceType: 'script'
61
+ },
62
+ rules: {
63
+ // 测试文件中允许使用console
64
+ 'no-console': 'off',
65
+ 'no-unused-vars': 'off'
66
+ }
67
+ }
68
+ ];
package/index.js CHANGED
@@ -35,13 +35,13 @@ class Config {
35
35
  this._conn = null;
36
36
  this._timer = null;
37
37
  this._promise = Promise.resolve();
38
-
38
+ this._logger = $.log || console;
39
39
  // 如果没有提供配置且有文件路径,则从文件加载
40
40
  if (!options && file) {
41
41
  try {
42
42
  this.options = file.loadJson();
43
43
  } catch (err) {
44
- $.log.error(`[options] Error loading options from ${file}:`, err.message);
44
+ this.log('error', `Error loading options from ${file}:`, err.message);
45
45
  this.options = {};
46
46
  }
47
47
  }
@@ -52,6 +52,16 @@ class Config {
52
52
  }
53
53
  }
54
54
 
55
+ /**
56
+ * 日志输出
57
+ * @param {String} level - 日志级别(debug/info/warn/error)
58
+ * @param {String} message - 日志消息
59
+ * @param {...*} args - 可选参数
60
+ */
61
+ Config.prototype.log = function(level, message, ...args){
62
+ this._logger[level](`[${this.constructor.name}] ${message}`, ...args);
63
+ }
64
+
55
65
  /**
56
66
  * 设置配置
57
67
  * @param {Object} config - 配置对象
@@ -88,7 +98,7 @@ Config.prototype.saveSync = function () {
88
98
  this._file.saveJson(this.options);
89
99
  return true;
90
100
  } catch (err) {
91
- $.log.error(`[options] Error saving options to ${this._file}:`, err.message);
101
+ this.log('error', `Error saving options to ${this._file}:`, err.message);
92
102
  return false;
93
103
  }
94
104
  };
@@ -109,7 +119,7 @@ Config.prototype.saveAsync = async function () {
109
119
  return true;
110
120
  })
111
121
  .catch(err => {
112
- $.log.error(`[options] Error saving options to ${this._file}:`, err.message);
122
+ this.log('error', `Error saving options to ${this._file}:`, err.message);
113
123
  return false;
114
124
  });
115
125
 
@@ -218,7 +228,6 @@ function create(file, options = {}, config = {}) {
218
228
  let f = file.fullname();
219
229
  // 检查是否已存在配置
220
230
  if (dict[f]) {
221
- // $.log.warn(`[options] Config for file ${f} already exists.`);
222
231
  return dict[f].getProxy();
223
232
  }
224
233
  var cfg = new Config(options, f, config);
@@ -239,7 +248,7 @@ async function createAsync(file, options = {}, config = {}) {
239
248
  let f = file.fullname();
240
249
  // 检查是否已存在配置
241
250
  if (dict[f]) {
242
- $.log.warn(`[options] Config for file ${f} already exists.`);
251
+ this.log('warn', `Config for file ${f} already exists.`);
243
252
  return dict[f].getAsyncProxy();
244
253
  }
245
254
  var cfg = new Config(options, f, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_config",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "这是超级美眉配置同步器,用于更改配置同步保存为JSON文件",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,6 +26,6 @@
26
26
  },
27
27
  "homepage": "https://gitee.com/qiuwenwu91/mm_config#readme",
28
28
  "dependencies": {
29
- "mm_expand": "^1.9.7"
29
+ "mm_expand": "^2.0.0"
30
30
  }
31
31
  }