Skip to content

Commit

Permalink
Change the db name
Browse files Browse the repository at this point in the history
  • Loading branch information
yasmikash committed Apr 12, 2021
1 parent dbb94d6 commit 80e95b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Simple and lightweight JSON database that stores data using keys.

# Install

`npm i dropdb --save`
`npm i leafdb --save`
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./src/dropdb");
module.exports = require("./src/leafdb");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dropdb",
"name": "leafdb",
"version": "1.0.0",
"description": "Simple and lightweight JSON database that stores data using keys.",
"main": "index.js",
Expand Down
40 changes: 20 additions & 20 deletions src/dropdb.js → src/leafdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const EventEmitter = require("events");

const { readFromFile, writeToFile } = require("./util/file-process");

class DropDB extends EventEmitter {
class LEAFDB extends EventEmitter {
constructor(path) {
super();
if (path) {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be a string value");
throw new TypeError("LEAFDB: Path should be a string value");
this._path = osPath.join(__dirname, path, "db.json");
} else {
this._path = osPath.join(__dirname, "/db.json");
Expand All @@ -23,7 +23,7 @@ class DropDB extends EventEmitter {
if (err.code === "ENOENT") await writeToFile(this._path, []);
}
} catch (err) {
throw new Error("DROPDB: Init database failed");
throw new Error("LEAFDB: Init database failed");
}
this.emit("ready");
};
Expand All @@ -34,21 +34,21 @@ class DropDB extends EventEmitter {

set path(path) {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be a string value");
throw new TypeError("LEAFDB: Path should be a string value");
this._path = path + ".json";
}

async put(path, object, cb) {
if (cb) {
if (typeof cb !== "function")
throw new TypeError("DROPDB: Callback should be a function");
throw new TypeError("LEAFDB: Callback should be a function");
}

try {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be a string value");
throw new TypeError("LEAFDB: Path should be a string value");
if (typeof object !== "object")
throw new TypeError("DROPDB: Data should be passed as object");
throw new TypeError("LEAFDB: Data should be passed as object");
const dataArray = await readFromFile(this._path);

const itemId = v4();
Expand Down Expand Up @@ -76,13 +76,13 @@ class DropDB extends EventEmitter {

async getById(path, id, cb) {
if (typeof cb !== "function")
throw new TypeError("DROPDB: Callback should be a function");
throw new TypeError("LEAFDB: Callback should be a function");

try {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be a string value");
throw new TypeError("LEAFDB: Path should be a string value");
if (typeof id !== "string")
throw new TypeError("DROPDB: Id should be a string value");
throw new TypeError("LEAFDB: Id should be a string value");

const dataArray = await readFromFile(this._path);

Expand Down Expand Up @@ -114,16 +114,16 @@ class DropDB extends EventEmitter {
async editById(path, id, object, cb) {
if (cb) {
if (typeof cb !== "function")
throw new TypeError("DROPDB: Callback should be a function");
throw new TypeError("LEAFDB: Callback should be a function");
}

try {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be string value");
throw new TypeError("LEAFDB: Path should be string value");
if (typeof id !== "string")
throw new TypeError("DROPDB: Id should be passed as data");
throw new TypeError("LEAFDB: Id should be passed as data");
if (typeof object !== "object")
throw new TypeError("DROPDB: Data should be passed as object");
throw new TypeError("LEAFDB: Data should be passed as object");

const dataArray = await readFromFile(this._path);

Expand Down Expand Up @@ -171,14 +171,14 @@ class DropDB extends EventEmitter {
async deleteById(path, id, cb) {
if (cb) {
if (typeof cb !== "function")
throw new TypeError("DROPDB: Callback should be a function");
throw new TypeError("LEAFDB: Callback should be a function");
}

try {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be string value");
throw new TypeError("LEAFDB: Path should be string value");
if (typeof id !== "string")
throw new TypeError("DROPDB: Id should be passed as data");
throw new TypeError("LEAFDB: Id should be passed as data");

const dataArray = await readFromFile(this._path);

Expand Down Expand Up @@ -225,11 +225,11 @@ class DropDB extends EventEmitter {

async getPathData(path, cb) {
if (typeof cb !== "function")
throw new TypeError("DROPDB: Callback should be a function");
throw new TypeError("LEAFDB: Callback should be a function");

try {
if (typeof path !== "string")
throw new TypeError("DROPDB: Path should be a string value");
throw new TypeError("LEAFDB: Path should be a string value");

const dataArray = await readFromFile(this._path);

Expand All @@ -251,4 +251,4 @@ class DropDB extends EventEmitter {
}
}

module.exports = DropDB;
module.exports = LEAFDB;
6 changes: 3 additions & 3 deletions src/util/file-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const readFromFile = (path) => {
fs.readFile(path, (err, data) => {
if (err) {
if (err.code === "ENOENT") {
const error = new Error("DROPDB: Could not read data");
const error = new Error("LEAFDB: Could not read data");
error.code = "ENOENT";
reject(error);
} else {
reject(new Error("DROPDB: Could not read data"));
reject(new Error("LEAFDB: Could not read data"));
}
} else resolve(JSON.parse(data));
});
Expand All @@ -19,7 +19,7 @@ const readFromFile = (path) => {
const writeToFile = (path, data) => {
return new Promise((resolve, reject) => {
fs.writeFile(path, JSON.stringify(data), (err) => {
if (err) reject(new Error("DROPDB: Could not write data"));
if (err) reject(new Error("LEAFDB: Could not write data"));
else resolve(true);
});
});
Expand Down

0 comments on commit 80e95b9

Please sign in to comment.