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

simple-functions

v1.0.5

Published

A multi-purpose NPM package with a lot of features

Downloads

15

Readme

Simple-Functions

A multi-purpose NPM package with a lot of features

npm install simple-functions

To use database:
npm i better-sqlite3 (OR) promise-mysql
Depending on which you plan to use.

To Use Calculator Functions:

import Simple from 'simple-functions'

const SimpleCalc = new Simple.SimpleCalc();

// Adds the numbers provided
SimpleCalc.addNums([1,2,4,3]) // -> 13
// Subtracts the 2 numbers (num1 - num2)
SimpleCalc.subNums(5,2) // -> 3
// Multiplies the numbers provided
SimpleCalc.multiNums([5,3,4,2]) // -> 120
// Divides the 2 numbers (num1 / num2)
SimpleCalc.divideNums(6,2) // -> 3
// Divides the 2 numbers and returns the remainder (num1 / num2)
SimpleCalc.remainder(10,5) // -> 0
// Generates a random number between min and max
SimpleCalc.randomNumber(10,100) // -> any number between 10 and 100

// The addNums and multiNums can 
// both be used with an array of numbers.

To Use Array Functions:

import Simple from 'simple-functions'

const SimpleArray = new Simple.SimpleArray([1,2,3,"String4","String3"])

// Returns the array passed in the constructor
SimpleArray.getArray() // -> [1,2,3,"String4","String3"]
// Returns a boolean based on if the specified filter exists within the array
SimpleArray.isInArray(3) // -> true
// Returns the index of where the filter is in the array
SimpleArray.whereInArray(2) // -> 1
// Filters your array and returns a new one with values that fit inside of the filter provided
SimpleArray.filterArray('String') // -> ["String4", "String3"]

To Use Database Functions (w/ sqlite):

import Simple from 'simple-functions'

const SimpleDB = new Simple.SimpleDB();
// To specify path: const SimpleDB = new Simple.SimpleDB({ filePath: "source/to/path/test.sqlite" })

// Anonymous Async function so we can use 'await'
(async () => {
    // Setting an object in the database:
    await SimpleDB.set("userInfo", { difficulty: "Easy" });
    // -> { difficulty: 'Easy' }

    // Getting an object from the database:
    await SimpleDB.get("userInfo");
    // -> { difficulty: 'Easy' }

    // Getting an object property from the database:
    await SimpleDB.set("userInfo.difficulty");
    // -> 'Easy'

    // Setting an object in the database:
    await SimpleDB.set("userInfo", { difficulty: "Easy" });
    // -> { difficulty: 'Easy' }

    // Pushing an element to an array (that doesn't exist yet) in an object:
    await SimpleDB.push("userInfo.items", "Sword");
    // -> { difficulty: 'Easy', items: ['Sword'] }

    // Adding to a number (that doesn't exist yet) in an object:
    await SimpleDB.add("userInfo.balance", 500);
    // -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }

    // Repeating previous examples:
    await SimpleDB.push("userInfo.items", "Watch");
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
    await SimpleDB.add("userInfo.balance", 500);
    // -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }

    // Fetching individual properties
    await SimpleDB.get("userInfo.balance"); // -> 1000
    await SimpleDB.get("userInfo.items"); // ['Sword', 'Watch']
})();

To Use Database Functions (w/ MySQL)

import { SimpleDB, MySQLDriver } from 'simple-functions'

(async () => {
    const mysqlDriver = new MySQLDriver({
        host: "localhost",
        user: "me",
        password: "secret",
        database: "my_db",
    });

    await mysqlDriver.connect(); // Connect to the database **THIS IS REQUIRED**

    const db = new SimpleDB({ driver: mysqlDriver });
    // Now you can do everything that was in the other part

    await db.set("userInfo", { difficulty: "Easy" });
    // -> { difficulty: 'Easy' }
})();

If you have any suggestions, make either a pull request or issue request stating the idea you have for the package. Try to keep the ideas simple and general.

Github Link : https://github.com/retscipE/simple-functions