Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

megadb

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

megadb - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

114

index.js

@@ -199,7 +199,13 @@ const fs = require('graceful-fs'),

if(database_name.includes("/")) throw new Error(`[ERROR] El nombre de la base de datos ${database_name} no debes contener el simbolo de barra ascendente: /`)
database_name = database_name.trim()
if(database_name.length <= 0) throw new Error(`[ERROR] Necesitas colocar un nombre a la base de datos`)
if(sub_directory) {
if(typeof sub_directory != "string") throw new Error(`[ERROR] El nombre del sub directorio ${database_name} debe ser un string`)
if(sub_directory.includes("/")) throw new Error(`[ERROR] El nombre del sub directorio ${sub_directory} no debe contener el simbolo de barra ascendente: /`)
sub_directory = sub_directory.trim()
if(sub_directory.length <= 0) throw new Error(`[ERROR] Necesitas colocar un nombre al sub directorio`)
}
this.database_name = database_name
this.object_id = sub_directory ? `${sub_directory}/${database_name}` : database_name
this.path_main_carpet = get_path(sub_directory)

@@ -214,9 +220,9 @@ //En caso de que no encuentre la ruta correcta

}
this.preprare_db = function(path_file_name, database_name) {
if(!global_object[database_name]) {
global_object[database_name] = readJSON(path_file_name)
this.preprare_db = function(path_file_name, object_id) {
if(!global_object[object_id]) {
global_object[object_id] = readJSON(path_file_name)
return
}
return
}(this.path_file_name, database_name)
}(this.path_file_name, this.object_id)
}

@@ -284,3 +290,3 @@

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -301,5 +307,5 @@

}
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {
return Promise.resolve(global_object[this.database_name])
return Promise.resolve(global_object[this.object_id])
}

@@ -320,3 +326,3 @@ return Promise.reject(ErrorDesc("DATABASE NO EXISTENTE", `La base de datos ${this.database_name} no existe: ${this.path_main_file}`)) //tal vez ocurre algun error ?)

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in split_object) {

@@ -345,3 +351,3 @@ var key = split_object[x]

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in split_object) {

@@ -371,3 +377,3 @@ var key = split_object[x]

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -380,3 +386,3 @@

delete object_data[key]
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -400,6 +406,6 @@ return true

function purgeall() { //retorna true o false
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))
global_object[this.database_name] = {}
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
global_object[this.object_id] = {}
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -426,3 +432,3 @@ return true

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -435,3 +441,3 @@ for(var x in split_object) {

object_data[key] += number
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -463,3 +469,3 @@ return Promise.resolve(object_data[key])

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -473,3 +479,3 @@

object_data[key] -= number
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -500,3 +506,3 @@ return Promise.resolve(object_data[key])

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -509,3 +515,3 @@ for(var x in split_object) {

object_data[key].unshift(valor)
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -536,3 +542,3 @@ return Promise.resolve(object_data[key])

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
let old_object = JSON.parse(JSON.stringify(object_data))

@@ -546,3 +552,3 @@ for(var x in split_object) {

object_data[key].splice(object_data[key].indexOf(valor), 1)
let save_data = saveJSON(this.path_file_name, global_object[this.database_name], old_object)
let save_data = saveJSON(this.path_file_name, global_object[this.object_id], old_object)
if(save_data) {

@@ -566,3 +572,3 @@ return Promise.resolve(object_data[key])

function datos() { //retorna promesa
return Promise.resolve(global_object[this.database_name])
return Promise.resolve(global_object[this.object_id])
}

@@ -589,6 +595,6 @@

//si la clave y valor son false
if(Object.keys(global_object[this.database_name]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
for(var key in global_object[this.database_name]) {
if(typeof global_object[this.database_name][key] != "number") return Promise.reject(ErrorDesc("NUMERO NO EXISTENTE", `El valor de la propiedad ${key} no es un numero`))
final_array.push({clave: key, valor: global_object[this.database_name][key]})
if(Object.keys(global_object[this.object_id]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
for(var key in global_object[this.object_id]) {
if(typeof global_object[this.object_id][key] != "number") return Promise.reject(ErrorDesc("NUMERO NO EXISTENTE", `El valor de la propiedad ${key} no es un numero`))
final_array.push({clave: key, valor: global_object[this.object_id][key]})
}

@@ -609,4 +615,4 @@ final_array.sort(function (a,b) {

for(var key1 in global_object[this.database_name]) {
var object_data = global_object[this.database_name][key1]
for(var key1 in global_object[this.object_id]) {
var object_data = global_object[this.object_id][key1]
for(var x in properties) {

@@ -638,3 +644,3 @@ var index = properties[x]

var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in properties) {

@@ -678,3 +684,3 @@ var index = properties[x]

var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]

@@ -731,4 +737,4 @@ for(var x = 0; x < properties.length; x++) {

if(clave === false) {
if(Object.keys(global_object[this.database_name]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
let keys = Object.keys(global_object[this.database_name])
if(Object.keys(global_object[this.object_id]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
let keys = Object.keys(global_object[this.object_id])
for (var i = 0; i < cantidad; i++) {

@@ -750,4 +756,4 @@ if(i >= keys.length) break

let random_array = []
if(array.length <= 0) return random_array
array.map(r => random_array.push({clave: r, valor: global_object[this.database_name][r]}))
if(array.length <= 0) return Promise.resolve(random_array)
array.map(r => random_array.push({clave: r, valor: global_object[this.object_id][r]}))
return Promise.resolve(random_array)

@@ -757,3 +763,3 @@ }

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]

@@ -774,3 +780,3 @@ for(var x in split_object) {

random_number = parseInt((Math.random() * keys.length));
}
}
else {

@@ -784,3 +790,3 @@ array.push(keys[random_number]);

let random_array = []
if(array.length <= 0) return random_array
if(array.length <= 0) return Promise.resolve(random_array)
array.map(r => random_array.push({clave: r, valor: object_data[key][r]}))

@@ -834,3 +840,3 @@ return Promise.resolve(random_array)

if(clave === false) {
let keys = Object.keys(global_object[this.database_name])
let keys = Object.keys(global_object[this.object_id])
return Promise.resolve(keys)

@@ -840,3 +846,3 @@ }

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]

@@ -867,3 +873,3 @@ for(var x in split_object) {

if(clave === false) {
let values = Object.keys(global_object[this.database_name]).map(o => global_object[this.database_name][o])
let values = Object.keys(global_object[this.object_id]).map(o => global_object[this.object_id][o])
return Promise.resolve(values)

@@ -874,3 +880,3 @@ }

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]

@@ -898,3 +904,3 @@ for(var x in split_object) {

function size() { //retorna promesa
return Object.keys(global_object[this.database_name]).length
return Object.keys(global_object[this.object_id]).length
}

@@ -912,5 +918,5 @@

if(clave === false) {
if(Object.keys(global_object[this.database_name]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
for(var key in global_object[this.database_name]) {
if(callback(global_object[this.database_name][key], key)) return Promise.resolve(global_object[this.database_name][key])
if(Object.keys(global_object[this.object_id]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
for(var key in global_object[this.object_id]) {
if(callback(global_object[this.object_id][key], key)) return Promise.resolve(global_object[this.object_id][key])
}

@@ -922,3 +928,3 @@ return Promise.resolve(undefined)

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in split_object) {

@@ -953,6 +959,6 @@ var key = split_object[x]

if(clave === false) {
if(Object.keys(global_object[this.database_name]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
if(Object.keys(global_object[this.object_id]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
for(var key in global_object[this.database_name]) {
if(callback(global_object[this.database_name][key], key)) filter_array[key] = global_object[this.database_name][key]
for(var key in global_object[this.object_id]) {
if(callback(global_object[this.object_id][key], key)) filter_array[key] = global_object[this.object_id][key]
}

@@ -966,3 +972,3 @@

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in split_object) {

@@ -997,6 +1003,6 @@ var key = split_object[x]

if(clave === false) {
if(Object.keys(global_object[this.database_name]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
if(Object.keys(global_object[this.object_id]).length <= 0) return Promise.reject(ErrorDesc("PROPIEDAD NO EXISTENTE", `Actualmente no hay ninguna propiedad`))
let map_array = new Array()
for(var key in global_object[this.database_name]) map_array.push(callback(global_object[this.database_name][key], key))
for(var key in global_object[this.object_id]) map_array.push(callback(global_object[this.object_id][key], key))

@@ -1008,3 +1014,3 @@ return Promise.resolve(map_array)

var split_object = clave.split(split_object)
var object_data = global_object[this.database_name]
var object_data = global_object[this.object_id]
for(var x in split_object) {

@@ -1011,0 +1017,0 @@ var key = split_object[x]

{
"name": "megadb",
"version": "2.4.0",
"version": "2.5.0",
"description": "base de datos usando JSON",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -22,2 +22,5 @@ ```

V2.5.0
* Se añadio un identificador interno para cada base de datos, esto hara que se puedan diferenciar en caso de que tengas una db con el mismo nombre en diferentes sub directorios.
V2.4.0

@@ -95,2 +98,6 @@ * Se agrego 3 nuevos metodos (find, map, filter)

__Actualizacion__
En la version 2.5.0 se añadio un identificador interno a cada base de datos, esto hara que se puedan diferenciar en caso de que uses una db con el mismo nombre en diferentes sub directorios.
__Ejemplos__

@@ -97,0 +104,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc