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

informa-db.js

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

informa-db.js

The concept is to interact with storage units (such as Dbs or JSON files) by defining variables. ## How to install it: `npm i informa-db.js` ## How to use it: Here's a code example on how to use it: ```js const Db = require('informa-db.js'); // Require th

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

Informa-Db.js

Concept

The concept is to interact with storage units (such as Dbs or JSON files) by defining variables.

How to install it:

npm i informa-db.js

How to use it:

Here's a code example on how to use it:

const Db = require('informa-db.js'); // Require the package

(async ()=>{
  const players = await new Db("players.json"); // Uses data.json to store data
  // I implemented these functions but they're boring:
  if (!players.exist(process.env.PLAYER))
    players.add(process.env.PLAYER,{
      inventory: Array(20),
      equipment: Array(5),
      temporaryData: {
        hp: 20,
        xp: 0
      }
    });
  // Instead, use this more elegant way of doing it:
  if(!players.value[process.env.PLAYER])
    players[process.env.PLAYER]={
      inventory: Array(20),
      equipment: Array(5),
      temporaryData: {
        hp: 20,
        xp: 0
      }
    };
})()

Before you ask, those all work.

Docs

new Db( path, defaultString, isMongo, db, collection )

path

Path to file or URI to mongodb server. Will throw an error if none provided

defaultString

Default string to write on file if it doesn't exist. Defaults to '{}' Will be ignored if this.isMongo is truthy (See isMongo)

isMongo

Boolean indicating whether the provided path is a file or a mongodb server Defaults to true if the path starts with "mongodb", false otherwise.

db

Database name, defaulting to "infodbs"

collection

Collection name, defaulting to "db"

Db function and properties

Db.readOnlyValue

File/collection content

Db.value<Proxy>

Proxy to this.readOnlyValue

Db.saveOnChange

If is true, runs this.update() everytime a change is made (this.add(), this.addOverwrite(), this.remove() and changing this.value )

Db.exist(index<Number, String>)

Checks if this.readOnlyValue[index] exists

Db.add(index<Number, String>, value)<Boolean, Any>

Defines this.readOnlyValue[index] to value. If this.readOnlyValue[index] already exists, will ignore and return false.

Db.addOverwrite(index<Number, String>, value)

Defines this.readOnlyValue[index] to value.

Db.remove(index<Number, String>)

Splices out/deletes this.readOnlyValue[index]

Db.update()

Updates the file/db to this.readOnlyValue

FAQs

Package last updated on 29 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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