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

universalfunction

v1.1.7

Published

The Universalfunction library exported as Node.js modules. Installation

Downloads

20

Readme

The Universalfunction library exported as Node.js modules.

Installation Using npm:

$ npm i  universalfunction

// Load the full build.

var universalfunction = require('universalfunction');

//Documentation

//Sending notification to users //installation

$ npm install fcm-node

//Usage

const FCM = require('fcm-node');
const serverKey = 'YOURSERVERKEYHERE'; //put your server key here
const fcm = new FCM(serverKey);

const message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
    to: 'registration_token', 
    collapse_key: 'your_collapse_key',
    
    notification: {
        title: 'Title of your push notification', 
        body: 'Body of your push notification' 
    },
    
    data: {  //you can send only notification or only data(or include both)
        my_key: 'my value',
        my_another_key: 'my another value'
    }
};

fcm.send(message, function(err, response){
    if (err) {
        console.log("Something has gone wrong!");
    } else {
        console.log("Successfully sent with response: ", response);
    }
});

//Authentication with passport

//Installation

$ npm i passport

//load passport

const passport = require('passport')

isAuthenticated()  //checks whether user authenticated or not

//usage

checkAuthenticate=(req,res,next)=> {
    if(req.isAuthenticated()){
        return next()
    }else{
        return res.send('login first')
    }
}//If user is authenticated(logged in) then passes to the next else returns back to login page

// for generating randon bytes with crypto

//Installation

$ npm i crypto

//load crypto

const crypto = require('crypto');


crypto.randomBytes(Number,callback)//creates the random bytes

//usage

tokenGenrator= (done)=>{
    crypto.randomBytes(2,(err,buf)=>{
    let token = buf.toString('hex');
    done(err,token)
})
}  //4a22
//Number=2 and this then this number is converted into hexadecimal string

//Sending mail to the user with nodemailer //installation

$ npm i nodemailer

//load nodemailer

const nodemailer = require("nodemailer")

//usage

const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.com:[email protected]');

// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"" <[email protected]>', // sender address
    to: '[email protected], [email protected]', // list of receivers
    subject: 'Hello ', // Subject line
    text: 'Hello world ', // plaintext body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

//Database Queries

//Get Users from DB

getData = (criteria, projection, options, callback) =>{
    Model.find(criteria, projection, options, callback);
};

//Insert User in DB

create = (objToSave, callback)=> {
    new Models(objToSave).save(callback)
};

//Update User in DB

//For updating one entry
findAndUpdate = (criteria, dataToSet, options, callback)=> {
    Model.findOneAndUpdate(criteria, dataToSet, options, callback);
};

//for Updating multiple enteries
updateMultiple = (criteria, dataToSet, options, callback) =>{
    Model.update(criteria, dataToSet, options, callback);
};

// Populate from db

getPopulate = (criteria, project, options,populateArray, callback)=> {
    Model.find(criteria, project, options).populate(populateArray).exec(function (err, docs) {
        if (err) {
            return callback(err, docs);
        }else{
            callback(null, docs);
        }
    });
};

// delete entry from db

// for deleting the single entry
deleteData=(criteria,callback)=>{
    Model.deleteOne(criteria,callback)
}

// for deleting the multiple entries
deleteData=(criteria,callback)=>{
    Model.deleteMany(criteria,callback)
}