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.8.0 to 3.0.0

methods/delIndex.js

69

class/crearDB.js

@@ -1,2 +0,2 @@

const { check_path_object, get_path, readJSON } = require("../utils/utilidades.js"),
const { check_path_object, build_path, readJSON } = require("../utils/utilidades.js"),
{ establecer } = require("../methods/establecer.js"),

@@ -21,3 +21,5 @@ { obtener } = require("../methods/obtener.js"),

{ map } = require("../methods/map.js"),
{ some } = require("../methods/some.js"),
{ some } = require("../methods/some.js"),
{ setIndex } = require("../methods/setIndex.js"),
{ delIndex } = require("../methods/delIndex.js"),
fs = require("fs");

@@ -32,30 +34,23 @@

constructor(database_name, sub_directory = false) {
if(!database_name) throw new Error(`[ERROR] Necesitas colocar el nombre de la base de datos`)
if(typeof database_name != "string") throw new Error(`[ERROR] El nombre de la base de datos ${database_name} debe ser un string`)
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)
if(this.path_main_carpet == false) throw new Error(`[ERROR] Ocurrio un problema obteniendo la ruta de la base de datos, asegurate que tu proyecto tenga la carpeta node_modules`)
this.path_file_name = `${this.path_main_carpet}/${database_name}.json`
if(!fs.existsSync(this.path_file_name)) {
fs.writeFileSync(this.path_file_name, JSON.stringify({}, null, 2), { flag: 'wx' }, function(err) {
if(err) throw new Error(`[ERROR] No se pudo crear la base de datos ${database_name}, error: ${err}`)
});
}
(function(path_file_name, object_id) {
if(!global_object[object_id]) {
global_object[object_id] = readJSON(path_file_name)
}
}(this.path_file_name, this.object_id))
let settings = {nombre: "", carpeta: "mega_databases", sub: false}
if(typeof database_name == "object" && !(database_name instanceof Array)) settings = database_name
else{
settings.nombre = database_name
settings.sub = sub_directory
}
let parse_data = build_path(settings)
this.database_name = parse_data.nombre;
this.path_file_name = parse_data.path_json;
this.path_main_carpet = parse_data.path_carpet;
this.object_id = parse_data.object_id;
(function(path_file_name, object_id) {
if(!global_object[object_id]) {
global_object[object_id] = readJSON(path_file_name)
}
}(this.path_file_name, this.object_id))
}

@@ -101,3 +96,3 @@

if(typeof database_name != "string") throw new Error(`[ERROR] El nombre de la base de datos debe ser un string`)
if(!fs.existsSync(`${this.path_file_name}`)) return false
if(!fs.existsSync(path.join(this.path_main_carpet,`${database_name}.json`))) return false
return true

@@ -284,4 +279,20 @@ }

setIndex(clave, index, valor, split_object) {
if(!split_object) split_object = "."
if(typeof split_object != "string") throw new Error(`[ERROR] El signo que se usara para la clave debe ser un string.`)
check_path_object(clave, split_object)
return setIndex(clave, index, valor, split_object, global_object, this, true)
}
delIndex(clave, index, split_object) {
if(!split_object) split_object = "."
if(typeof split_object != "string") throw new Error(`[ERROR] El signo que se usara para la clave debe ser un string.`)
check_path_object(clave, split_object)
return delIndex(clave, index, split_object, global_object, this, true)
}
}
module.exports = crearDB

@@ -20,5 +20,6 @@ const { check_path_object } = require("../utils/utilidades.js"),

{ map } = require("../methods/map.js"),
{ some } = require("../methods/some.js");
{ some } = require("../methods/some.js"),
{ setIndex } = require("../methods/setIndex.js"),
{ delIndex } = require("../methods/delIndex.js");
let global_object = new Object();

@@ -248,5 +249,21 @@

setIndex(clave, index, valor, split_object) {
if(!split_object) split_object = "."
if(typeof split_object != "string") throw new Error(`[ERROR] El signo que se usara para la clave debe ser un string.`)
check_path_object(clave, split_object)
return setIndex(clave, index, valor, split_object, global_object, this, false)
}
delIndex(clave, index, split_object) {
if(!split_object) split_object = "."
if(typeof split_object != "string") throw new Error(`[ERROR] El signo que se usara para la clave debe ser un string.`)
check_path_object(clave, split_object)
return delIndex(clave, index, split_object, global_object, this, false)
}
}
module.exports = memoDB
{
"name": "megadb",
"version": "2.8.0",
"version": "3.0.0",
"description": "base de datos usando JSON",

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

@@ -87,31 +87,43 @@ const fs = require("fs"),

function get_path(sub_directory) {
let directorio = path.dirname(require.main.filename).split("/");
for(var x = 0; x < directorio.length; x++) {
if(fs.existsSync(`${directorio.join("/")}/node_modules`)) {
if(!fs.existsSync(`${directorio.join("/")}/mega_databases`)) {
mkdirp(`${directorio.join("/")}/mega_databases`, function(err) {
if(err) throw new Error(`[ERROR] No se pudo crear la carpeta mega_databases donde se almacenaran las base de datos, error: ${err}`)
console.log(`[CREANDO DIRECTORIO] Acaba de crearse la carpeta mega_databases, en esta carpeta ${sub_directory != false ? "se creara tu sub directorio" : "se almacenaran tus base de datos"}.`)
})
}
function build_path(object) {
if(typeof object != "object" || (object instanceof Array)) throw new Error("Parametros incorrectos, el constructor crearDB puede recibir un objeto o dos parametros indicando el nombre de la base de datos y el sub directorio.") //Poco probable que esta linea sea evaluada pero de igual forma..
let nombre = object.hasOwnProperty("nombre") && typeof object.nombre == "string" ? object.nombre.replace(/[^a-zA-Z0-9_]/g, '') : ""
let carpeta = object.hasOwnProperty("carpeta") && typeof object.carpeta == "string" ? object.carpeta.replace(/[^a-zA-Z0-9_]/g, '') : "mega_databases"
let sub_carpeta = object.hasOwnProperty("sub") && typeof object.sub == "string" ? object.sub.replace(/[^a-zA-Z0-9_]/g, '') : false
if(!nombre) throw new Error(`[ERROR] Necesitas colocar el nombre de la base de datos, debe ser un string y asegurate de no usar simbolos.`)
if(!carpeta) throw new Error("[ERROR] El nombre de la carpeta donde se guardaran las bases de datos debe ser un string y asegurate de no usar simbolos.")
if(!sub_carpeta && sub_carpeta !== false) throw new Error(`[ERROR] El nombre del sub directorio ${sub_carpeta} debe ser un string y asegurate de no usar simbolos.`)
if(sub_directory) {
if(!fs.existsSync(`${directorio.join("/")}/mega_databases/${sub_directory}`)) {
mkdirp(`${directorio.join("/")}/mega_databases/${sub_directory}`, function(err) {
if(err) throw new Error(`[ERROR] No se pudo crear el sub directorio ${sub_directory}, error: ${err}`)
console.log(`[CREANDO SUB DIRECTORIO] Acaba de crearse el sub directorio ${sub_directory}, en esta carpeta se almacenaran tus base de datos.`)
})
}
}
path_main_file = sub_directory != false ? `${directorio.join("/")}/mega_databases/${sub_directory}` : `${directorio.join("/")}/mega_databases`
return path_main_file
let root = path.join(path.dirname(require.main.filename), carpeta)
if(!fs.existsSync(root)) {
mkdirp(root, (err) => {
if(err) throw new Error(`[ERROR] No se pudo crear la carpeta ${carpeta} donde se almacenaran las base de datos, error: ${err}`)
console.log(`[CREANDO DIRECTORIO] Acaba de crearse la carpeta ${carpeta}, en esta carpeta ${sub_carpeta != false ? "se creara tu sub directorio" : "se almacenaran tus base de datos"}.`)
})
}
if(sub_carpeta) {
if(!fs.existsSync(`${root}/${sub_carpeta}`)) {
mkdirp(`${root}/${sub_carpeta}`, (err) => {
if(err) throw new Error(`[ERROR] No se pudo crear el sub directorio ${sub_carpeta}, error: ${err}`)
console.log(`[CREANDO SUB DIRECTORIO] Acaba de crearse el sub directorio ${sub_carpeta}, en esta carpeta se almacenaran tus base de datos.`)
})
}
directorio = directorio.slice(0, -1)
root = path.join(root, sub_carpeta)
}
return false
if(!fs.existsSync(`${root}/${nombre}.json`)) {
fs.writeFileSync(`${root}/${nombre}.json`, JSON.stringify({}, null, 2), { flag: 'wx' }, function(err) {
if(err) throw new Error(`[ERROR] No se pudo crear la base de datos ${database_name}, error: ${err}`)
})
}
return {
path_json: path.join(root,`${nombre}.json`),
path_carpet: root,
nombre: nombre,
object_id: sub_carpeta ? `${carpeta}/${sub_carpeta}/${nombre}` : `${carpeta}/${nombre}`
}
}
module.exports = {

@@ -124,3 +136,3 @@ is_float,

ErrorDesc,
get_path
build_path
}

Sorry, the diff of this file is too big to display

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