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

common-coding-tools

v2.0.36

Published

A common code module for use in multiple npm packages

Downloads

85

Readme

common-coding-tools

While working with JavaScript and JavaScript Framework, many hooks have to be made which are common,
so they are all present here in the same library, so use them and avoid time and code repetition.

Getting Started

npm install common-coding-tools

Usage

We have divided the first common-coding-tools into 4 pages based on their different categories so that it is easy to use.

Here is an example of how to use the search function:

import { search } from "common-coding-tools/array"

const arr = [
        {
            "gender": "male",
            "name": { "title": "Mr",  "first": "Vitaliy", "last": "Nechay" },
            "email": "[email protected]",
        },
        {
            "gender": "male",
            "name": { "title": "Mr", "first": "Ceyhun", "last": "Tekelioğlu"  },
            "email": "[email protected]",
        },
        {
            "gender": "male",
            "name": { "title": "Mr", "first": "Pelle", "last": "Vestnes"
            },
            "email": "[email protected]",
        },
        {
            "gender": "male",
            "name": { "title": "Mr","first": "Stanislaw", "last": "Aanestad"
            },
            "email": "[email protected]",
        },
        {
            "gender": "female",
            "name": { "title": "Mrs",  "first": "Esperanza",  "last": "Colón"},
            "email": "[email protected]",
        }
    ]

const results = search(arr, "vitly");
//  Output: [{
//    "gender": "male",
//    "name": {
//      "title": "Mr",
//      "first": "Vitaliy",
//      "last": "Nechay"
//    },
//    "email": "[email protected]"
//  }] 

more example for "common-coding-tools/array" Click here



Here is an example of how to use the upperCase and lowerCase function:

import {
lowerCase,
upperCase,
} from "common-coding-tools/string"

console.log(upperCase().all("vipin"))  // "VIPIN"
console.log(upperCase().firstCharacter("vipin"))  // "Vipin"

console.log(lowerCase().all("VIPIN"))  // "vipin"
console.log(lowerCase().firstCharacter("VIPIN"))  // "vIPIN"




Here is an example of how to use the
type isString isNumber isObject isBoolean isEmail and isUrl
functions:

import {
isString,
isNumber,
isObject,
isArray,
isBoolean,
isEmail,
isUrl,
type
} from "common-coding-tools/types"

const type1 = type({ name: "vipin" }) //output: "object"

const type2 = type([ "vipin", "paneru" ]) //output: "array"

const type3 = type(204) //output: "number"

const type4 = type(true) //output: "boolean"

console.log( isString( "vipin" )) //true
console.log( isString( 402 ))   //false

console.log( isEmail( "vipin" )) //false
console.log( isEmail( "[email protected]" )) //true

console.log( isObject({ name: "vipin", email: "[email protected]" })) //true
console.log( isObject([ "vipin", "[email protected]" ]))   //false

console.log( isArray({ name: "vipin", email: "[email protected]" })) //false
console.log( isArray([ "vipin", "[email protected]" ]))   //true

console.log( isUrl("[email protected]")) //false
console.log( isUrl("https://paneruvipin.com"))   //true




Here is an example of how to use the validation function:

import { validation, schema } from "common-coding-tools/validation"

const signupValidator={
       name: "string | required",
       email: "string | required | email | trim",
       password: "string | minLength: 8 | maxLength: 16",
       age: "number | range: 20-100",
       role: `defaultValue : ${schema( "user" )}`,
       created_at: `defaultValue : ${schema( new Date() )}`,
       updated_at: `defaultValue : ${schema( new Date() )}`,
}

router.post("/signup", (req,res,next)=>{
const data= validation(req.body, signupvalidator)

if(data?.errors){
const errors=data.errors
// use errors
}else{
const validatedData=data.data
// use validatedData
// write your code here
}
})

more example for "common-coding-tools/validation" Click here


Here is an example of hashing:


import {
makeHash,
verifyHash
} from "common-coding-tools/hashing"

const password="1234567"
const hashedPassword = makeHash( password , 4) // second argument any number 
// output: 7101818432503545
// For more security of encryption use `.env` Secret number for 2nd argument

const  confirm_pass1 = "1234567"
const  confirm_pass2 = "12345678"
const  verifyPassword = verifyHash(confirm_pass1, hashedPassword, 4)  // third args is same as makHash 2nd args
// output : true
const verifyPassword = verifyHash(confirm_pass2, hashedPassword, 4)  
// output : false




Here is an example of how to use the randomString randomNumber function:

import {
randomString,
randomNumber,
randomData
} from "common-coding-tools/random"


randomString(6) // 6 is length
// output like this: "AdSRR4"  any 6 length string

randomNumber(40,0) // first argument is highestNumber and second is
// output like this: 23   -->. any number between 40 and 0