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

vlodia

v1.10.3

Published

A simple database & http request module for your node application's.

Downloads

126

Readme

Vlodia

A simple database & http request module for your node application's.

Installation

You can install the module via npm or yarn:

npm install vlodia
yarn add vlodia

Usage

Database


const { Database } = require('vlodia');

// Create a new Database instance (default file name: database.json)
const db = new Database();

// Writing data
db.set('key', 'value');

// Getting data
console.log(db.get('key')); // Output: 'value'

// Adding data
console.log(db.add('counter', 5)); // Output: 5

// Subtracting from data
console.log(db.subtract('counter', 2)); // Output: 3

// Pushing an element to an array
console.log(db.push('list', 'new-item')); // Output: ['new-item']

// Pulling an element from an array
console.log(db.pull('list', 'new-item')); // Output: []

// Deleting data
console.log(db.delete('key')); // Output: true

// Checking if a key exists
console.log(db.has('key')); // Output: false

// Getting all data
console.log(db.all()); // Output: {}

// Clearing the database
console.log(db.clear()); // Output: true

// Incrementing a numeric value
console.log(db.increment('counter')); // Output: 1 (if 'counter' didn't exist before)

// Unpushing an element from an array
console.log(db.unpush('list', 'item-to-remove')); // Output: true (if 'item-to-remove' existed in 'list')

// Using findOneAndUpdate
const updatedValue = db.findOneAndUpdate('key', (value) => {
    return value ? value.toUpperCase() : 'DEFAULT';
});
console.log(updatedValue); // Output: 'DEFAULT' (if 'key' didn't exist before)

// Checking if a key exists after operations
console.log(db.has('key')); // Output: true

// New Methods
// Increment a numeric value by a specific amount
console.log(db.increment('counter', 5)); // Output: 6 (if 'counter' was previously 1)

// Find and update a value with options
const updatedValueWithOptions = db.findOneAndUpdate('key', (value) => {
    return value ? value.toLowerCase() : 'default';
}, { write: false });
console.log(updatedValueWithOptions); // Output will depend on current value and options

YamlDatabase


const { YamlDatabase } = require('vlodia');

// Create a new Database instance (default file name: database.yml)
const db = new YamlDatabase();

// Writing data
db.set('key', 'value');

// Getting data
console.log(db.get('key')); // Output: 'value'

// Adding data
console.log(db.add('counter', 5)); // Output: 5

// Subtracting from data
console.log(db.subtract('counter', 2)); // Output: 3

// Pushing an element to an array
console.log(db.push('list', 'new-item')); // Output: ['new-item']

// Pulling an element from an array
console.log(db.pull('list', 'new-item')); // Output: []

// Deleting data
console.log(db.delete('key')); // Output: true

// Checking if a key exists
console.log(db.has('key')); // Output: false

// Getting all data
console.log(db.all()); // Output: {}

// Clearing the database
console.log(db.clear()); // Output: true

// Incrementing a numeric value
console.log(db.increment('counter')); // Output: 1 (if 'counter' didn't exist before)

// Unpushing an element from an array
console.log(db.unpush('list', 'item-to-remove')); // Output: true (if 'item-to-remove' existed in 'list')

// Using findOneAndUpdate
const updatedValue = db.findOneAndUpdate('key', (value) => {
    return value ? value.toUpperCase() : 'DEFAULT';
});
console.log(updatedValue); // Output: 'DEFAULT' (if 'key' didn't exist before)

// Checking if a key exists after operations
console.log(db.has('key')); // Output: true

// New Methods
// Increment a numeric value by a specific amount
console.log(db.increment('counter', 5)); // Output: 6 (if 'counter' was previously 1)

// Find and update a value with options
const updatedValueWithOptions = db.findOneAndUpdate('key', (value) => {
    return value ? value.toLowerCase() : 'default';
}, { write: false });
console.log(updatedValueWithOptions); // Output will depend on current value and options

HttpClient

const { HttpClient } = require('vlodia');

const client = new HttpClient();

async function exampleUsage() {
    try {
        // GET request example
        const getResponse = await client.get('https://jsonplaceholder.typicode.com/posts/1');
        console.log('GET Response:', getResponse);

        // POST request example
        const postData = {
            title: 'foo',
            body: 'bar',
            userId: 1,
        };
        const postResponse = await client.post('https://jsonplaceholder.typicode.com/posts', postData);
        console.log('POST Response:', postResponse);

        // PUT request example
        const putData = {
            id: 1,
            title: 'foo',
            body: 'bar',
            userId: 1,
        };
        const putResponse = await client.put('https://jsonplaceholder.typicode.com/posts/1', putData);
        console.log('PUT Response:', putResponse);

        // DELETE request example
        const deleteResponse = await client.delete('https://jsonplaceholder.typicode.com/posts/1');
        console.log('DELETE Response:', deleteResponse);

        // Fetch request example
        const fetchResponse = await client.fetch('https://jsonplaceholder.typicode.com/posts/1');
        console.log('Fetch Response:', fetchResponse);
    } catch (error) {
        console.error('Error occurred:', error);
    }
}

exampleUsage();

Notes

  • Replace https://jsonplaceholder.typicode.com/posts/1 with your actual API endpoints.
  • Ensure Node.s enviroment with support for http and https modules.

API Reference

HttpClient Class constructor() Creates an instance of HttpClient.

get(path, options)

Makes a GET request to the specified path.

  • path: The URL or path to make the request to.

  • options: Optional additional options for the request. post(path, data, options) Makes a POST request to the specified path.

  • path: The URL or path to make the request to.

  • data: Data to send in the request body (JSON format).

  • options: Optional additional options for the request.

  • put(path, data, options) Makes a PUT request to the specified path.

  • path: The URL or path to make the request to.

  • data: Data to send in the request body (JSON format).

  • options: Optional additional options for the request.

  • delete(path, options) Makes a DELETE request to the specified path.

  • path: The URL or path to make the request to.

  • options: Optional additional options for the request.

  • fetch(input, init)

    • Makes a fetch request to the specified input.

    • input: The URL or Request object to make the request to.

    • init: Optional additional options for the request (like method, headers, and body)

License

  • This project is licensed under the Apache-2.0 License - see the LICENSE file for details.