UNPKG

dbcopycat

Version:

A JSON Database that saves your Json data in a file and makes it easy for you to perform CRUD operations.

16 lines (14 loc) 543 B
const getAllData = require("./getAllData"); const writeDataJson = require("./writeDataJson"); const log = require("../utils/log"); function removeData(arrayName, dataId) { var dataAll = getAllData(); if (dataAll[arrayName] == undefined) { log(`${arrayName} array not found.`, "Error", "error"); return undefined } const index = dataAll[arrayName].findIndex(x => x.id == dataId); dataAll[arrayName].splice(index, 1); writeDataJson(JSON.stringify(dataAll)); } module.exports = removeData;