Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
inventionpro authored Feb 15, 2024
1 parent aee454f commit cef938b
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
Functions:
set(key, value)
get(key)
has(key)
remove(key)
all()
*/

const fs = require('fs')
const write = require('write')

Expand Down Expand Up @@ -52,6 +43,42 @@ class DB {
all() {
return getFile(this.file)
}
add(key, number) {
let data = getFile(this.file);
data[key] = (Number(data[key]) || 0) + number;
setFile(this.file, data);
}
sub(key, number) {
let data = getFile(this.file);
data[key] = (Number(data[key]) || 0) - number;
setFile(this.file, data);
}
push(key, value) {
let data = getFile(this.file);
data[key].push(value)
setFile(this.file, data);
}
pull(key, index) {
let data = getFile(this.file);
data[key] = data[key].slice(0,index).concat(data[key].slice(index+1,data[key].length))
setFile(this.file, data);
}
pop(key) {
let data = getFile(this.file);
let value = data[key].pop()
setFile(this.file, data);
return value;
}
flat(key) {
let data = getFile(this.file);
data[key] = data[key].flat()
setFile(this.file, data);
}
concat(key, value) {
let data = getFile(this.file);
data[key] = data[key].concat(value)
setFile(this.file, data);
}
}

module.exports = DB;

0 comments on commit cef938b

Please sign in to comment.