fkg 1.0.6 → 1.0.7

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/README.md CHANGED
@@ -33,9 +33,8 @@ user.set('id_2',{account:"wangwu",emai:"1001@qq.com",phone:"13800138002",name:"
33
33
  **5. Get user data**
34
34
 
35
35
  ```javascript
36
- user.list(10); //默认100条数据
37
- user.list(50); //默认100条数据
38
- ```
36
+ user.list(); //默认100条数据
37
+ user.list(50);
39
38
 
40
39
  **6. Get list data**
41
40
 
package/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
  const {
3
3
  isDir,
4
- isFile,
5
4
  link,
6
5
  addDir,
7
6
  addJson,
@@ -12,9 +11,7 @@ const {
12
11
  const {str,obj,arr} = require('./utils/type');
13
12
  class fkg {
14
13
  constructor(arg) {
15
- this.data = {};
16
- this.dirs = {};
17
- this.dir = null;
14
+ this.close();
18
15
  if(arg&&obj(arg)) {
19
16
  if(arg.dir&&isDir(arg.dir)){
20
17
  this.dir = link(arg.dir,'./data');
@@ -34,6 +31,7 @@ class fkg {
34
31
  const value = readJson(link(this.dirs[n],'./'+list[i]));
35
32
  if(value!==null) this.data[n][list[i]] = value;
36
33
  };
34
+ list = null;
37
35
  }
38
36
  }
39
37
  };
@@ -41,18 +39,14 @@ class fkg {
41
39
  }
42
40
  }
43
41
  close(){
42
+ this.data = {};
43
+ this.dirs = {};
44
44
  this.dir = null;
45
- this.data = null;
46
- this.dirs = null;
47
45
  }
48
46
  table(n) {
49
47
  const that = this;
50
48
  if(!n||!str(n)) return;
51
49
  if(!that.data[n]) that.data[n] = {};
52
- if(that.dir&&!that.dirs[n]) {
53
- that.dirs[n] = link(that.dir,'./'+n);
54
- addDir(that.dirs[n]);
55
- }
56
50
  return {
57
51
  list(page){
58
52
  function getOBJ(obj, n) {
@@ -65,7 +59,7 @@ class fkg {
65
59
  return getOBJ(that.data[n],page>0?page:100);
66
60
  },
67
61
  clear(){
68
- if(that.dir){
62
+ if(that.dir&&that.dirs[n]){
69
63
  let list = readdirSync(that.dirs[n]);
70
64
  for (let i = 0;i < list.length;i++) {
71
65
  delFile(link(that.dirs[n],'./'+list[i]));
@@ -76,23 +70,16 @@ class fkg {
76
70
  return true;
77
71
  },
78
72
  get(id){
79
- if(that.dir&&!that.data[n][id]) {
80
- const url = link(that.dirs[n],'./'+id);
81
- if(isFile(url)){
82
- const res = readJson(url);
83
- if(res) that.data[n][id] = res;
84
- }
85
- }
86
73
  return that.data[n][id];
87
74
  },
88
75
  set(id,d){
89
76
  that.data[n][id] = d;
90
- if(that.dir) addJson(link(that.dirs[n],'./'+id),d);
77
+ if(that.dir&&that.dirs[n]) addJson(link(that.dirs[n],'./'+id),d);
91
78
  return true;
92
79
  },
93
80
  del(id){
94
81
  delete that.data[n][id];
95
- if(that.dir) delFile(link(that.dirs[n],'./'+id));
82
+ if(that.dir&&that.dirs[n]) delFile(link(that.dirs[n],'./'+id));
96
83
  return true;
97
84
  }
98
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fkg",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Read and set memory key!",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [