npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fluffydb

v0.0.7

Published

Database project in nodejs based on fs

Downloads

9

Readme

FluffyDB

FluffyDB is a json-based database that uses the nodejs (fs) file system, this database will be updated from time to time to fix errors, add functions, improve performance, among other things. Any questions consult Esponjosin

Install

npm install fluffydb --save

Usage

const FluffyDB = require('fluffydb');
const db = new FluffyDB({
    dir: __dirname, //This will be the base directory, here all the files created by fluffydb will be stored (Required)
    name: 'example', //This will be the name of the database (Required)
    subdir: '', //With this option you can separate the database into a sub folder to have more separate data (Optional)
    backup: true, // With this option you can enable or disable the option to make a backup from time to time of the database(Optional) (default: true)
    backupTime: 60000, //Here you can define how often the backup is made in case it is activated, the time must be in milliseconds (Optional) (default: 7.2e+6)
    logger: true //This option allows disabling the warning that the database is already ready (Optional) (default: true)
})

Changelogs

0.0.6

Fixed a error

0.0.5

All functions were created from 0 and the queue system was removed because it caused errors

Functions

All functions support . Ex: .set('marry.id', 'id') That will change the id parameter of the marry

add

Alias: sumas

The add function allows you to add a number to the specified id Ex:


/**
 * @param {string} [id]
 * @param {number} [toAdd]
 */

<FluffyDB>.add(id, Number)

/**
 * Expected Promise Output
 * {Object}
 */

all

Alias: datos

The add function allows you to add a number to the specified id Ex:


<FluffyDB>.all()

/**
 * Expected Promise Output
 * {Array}
 */

delete

Alias: eliminar

The delete function allows you to delete the specified id Ex:

/**
 * @param {string} [id]
 */

<FluffyDB>.delete(id)

/**
 * Expected Promise Output
 * {Boolean}
 */

filter

Alias: filtrar

The filter function allows you to filter an array in different ways, by index, by function or by value Ex:

/**
 * @param {string} [id]
 * @param {function/number/string} [f]
 * @param {boolean} [index]
 */

<FluffyDB>.filter(id, f, index)

/**
 * Expected Promise Output
 * {Object}
 */

get

Alias: obtener

The get function allows you to get the data of an id Ex:

/**
 * @param {string} [id]
 */

<FluffyDB>.get(id)

/**
 * Expected Promise Output
 * {Object}
 */

map

Alias: mapear

The map function allows you to map the data of an array Ex:

/**
 * @param {string} [id]
 * @param {function} [f]
 */

<FluffyDB>.map(id, f)

/**
 * Expected Promise Output
 * {Array}
 */

push

Alias: agregar

The push function allows you to add an item to a matrix Ex:

/**
 * @param {string} [id]
 * @param {any} [value]
 */

<FluffyDB>.push(id, value)

/**
 * Expected Promise Output
 * {Object}
 */

set

Alias: setear

The set function allows you to write a value to the specified id Ex:

/**
 * @param {string} [id]
 * @param {any} [value]
 */

<FluffyDB>.set(id, value)

/**
 * Expected Promise Output
 * {Object}
 */

some

Alias: algo

Some function lets you know if the id exists or not Ex:

/**
 * @param {string} [id]
 */

<FluffyDB>.get(id)

/**
 * Expected Promise Output
 * {Boolean}
 */

substract

Alias: restar

The substract function allows you to subtract a numeric value from the specified id Ex:

/**
 * @param {string} [id]
 * @param {number} [toRem]
 */

<FluffyDB>.substract(id, Number)

/**
 * Expected Promise Output
 * {Boolean}
 */

Example with discord.js

Requirements

discord.js
fluffydb

Code


const {Client} = require('discord.js'),
      bot = new Client(),
      FluffyDB = require('fluffydb'),
      db = {
          users: new FluffyDB({
              dir: __dirname,
              name: 'users',
              logger: false
          })
      };

bot.on('ready', () => {
    console.log(`Logged ${bot.user.tag}`)
})

bot.on('message', async message => {

    if(message.author.bot || message.channel.type == "DM"){
        return;
    }

    let guildData = new FluffyDB({ dir: __dirname, name: message.guild.id, subdir: 'guilds', logger: false })
    let membersData = new FluffyDB({ dir: __dirname, name: message.guild.id, subdir: 'members', logger: false })

    let memberData = await membersData.get(message.author.id).then(i => i).catch(e => false)
    
    if(!memberData) memberData = await membersData.set(message.author.id, { daily: null, money: 0 }).then(i => i).catch(e => false)
    
    let prefix = await guildData.get('prefix').then(i => i).catch(e => false) || '!'

    if(!message.content.toLowerCase().startsWith(prefix.toLowerCase())) return;

    let args = message.content.slice((typeof prefix === "string" ? prefix.length : 0)).trim().split(/ +/g);
    let command = args.shift().toLowerCase();

    if(command == 'setprefix') {
    
    	if(!message.member.permissions.has('ADMINISTRATOR')) return message.channel.send(':x: | You need to be an administrator to be able to change the prefix')
    
        if(!args[0]) return message.channel.send(`:x: | You need to enter the new prefix (${prefix}setprefix <prefix>)`)

        let status = await guildData.set('prefix', args[0]).then(i => true).catch(e => false)

        if(!status) return message.channel.send(':x: | An error occurred while trying to save the new prefix')

        return message.channel.send('The prefix was successfully updated')
        
    }

    if(command == 'daily') {

        if(!memberData) return message.channel.send(':x: | Your data could not be obtained')

        if(memberData.daily && memberData.daily - Date.now() > 0) return message.channel.send(':x: | You have to wait 24 hours to claim your daily reward again')

        let count = Math.floor(Math.random() * 99)+1

        await membersData.add(`${message.author.id}.money`, count).then(i => i).catch(e => false)
        await membersData.set(`${message.author.id}.daily`, Date.now() + 8.64e+7).then(i => i).catch(e => false)

        return message.channel.send(`Your daily reward was ${count} coins`)

    }

    if(command == 'bal') {

        if(!memberData) return message.channel.send(':x: | Your data could not be obtained')

        return message.channel.send(`You have ${memberData.money} coins`)

    }

    if(command == 'delmember') {
    
    	if(!message.member.permissions.has('ADMINISTRATOR')) return message.channel.send(":x: | You need to be an administrator to be able to delete a member's data")
    
        if(!message.mentions.members.first()) return message.channel.send(`:x: | You need to mention the member`)

	let mem = message.mentions.members.first()

        let status = await membersData.get(mem.user.id).then(i => true).catch(e => false)

        if(!status) return message.channel.send(':x: | The member does not have any data')
        
        membersData.delete(mem.user.id).then(i => true).catch(e => false)

        return message.channel.send(`Data for member ${mem.user.tag} was successfully removed`)
        
    }

})

bot.login('TOKEN')