UNPKG

@onurege3467/zerohelper

Version:

ZeroHelper is a versatile JavaScript library offering helper functions and database utilities for developers. It supports MongoDB, MySQL, SQLite, Redis, and PostgreSQL.

24 lines (20 loc) 792 B
"use strict"; const errors = require("../errors/strings.js"); module.exports = async function (key, value, table = "default", option) { if (!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table)); if (!key || typeof key !== "string") throw new TypeError(errors.key.replace("{received}", typeof key)); if (value === undefined) throw new TypeError(errors.value.replace("{received}", typeof value)); await this.create(table); let data = (await this.get(table, key)) || []; if (!Array.isArray(data)) throw new TypeError(errors.array.replace("{key}", key)); if (option === true) { if (!data.includes(value)) data.push(value); } else { data.push(value); } return await this.set(key, data, table); };