twin-db 1.0.3 → 1.1.0

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/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { TwinDB } from './structures/database.js';
1
+ import { TwinDB } from './structures/database';
2
2
  export default TwinDB;
@@ -33,7 +33,7 @@ export class TwinDB {
33
33
  if (typeof searchedValue !== 'object')
34
34
  await eval('this.data' + mappedKeys.join('') + ' = {}');
35
35
  } // percorre todos os objetos definindo eles como {} para não dar erro abaixo
36
- await eval(`this.data` +
36
+ await eval('this.data' +
37
37
  keys.map((key) => `['${key}']`).join('') +
38
38
  ` = ${JSON.stringify(value)}`);
39
39
  writeFileSync(this.path, JSON.stringify(this.data, null, 2), 'utf8');
@@ -82,9 +82,9 @@ export class TwinDB {
82
82
  const isSum = type === 'sum';
83
83
  if (!value || typeof value !== 'number')
84
84
  throw new Error(`The value to ${isSum ? 'sum' : 'sub'} must be a number`);
85
- const currentValue = this.get(path);
85
+ let currentValue = (this.get(path) || 0);
86
86
  if (typeof currentValue !== 'number')
87
- throw new Error(`The value to ${isSum ? 'sum' : 'sub'} is not a number or the path does not exists`);
87
+ currentValue = 0;
88
88
  return this.update(path, isSum ? currentValue + value : currentValue - value);
89
89
  }
90
90
  sum(path, value) {
@@ -108,9 +108,9 @@ export class TwinDB {
108
108
  throw new Error(pathErrorMessage);
109
109
  if (!values || values.length === 0)
110
110
  throw new Error('You must provide a value to update');
111
- const currentValue = this.get(path);
111
+ let currentValue = (this.get(path) || []);
112
112
  if (!Array.isArray(currentValue))
113
- throw new Error('The current value of this path is not an array or the path does not exists');
113
+ currentValue = [];
114
114
  currentValue.push(...values);
115
115
  return this.update(path, currentValue);
116
116
  }
@@ -121,7 +121,7 @@ export class TwinDB {
121
121
  throw new Error('You must provide a value to update');
122
122
  const currentValue = this.get(path);
123
123
  if (!Array.isArray(currentValue))
124
- throw new Error('The current value of this path is not an array or the path does not exists');
124
+ throw new Error('The value to pull is not an array or the path does not exists');
125
125
  for (const value of values) {
126
126
  const index = currentValue.indexOf(value);
127
127
  if (index < 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twin-db",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "A usefully local database.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",