2.0.36 • Published 8 months ago

common-coding-tools v2.0.36

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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": "vitaliy.nechay@example.com",
        },
        {
            "gender": "male",
            "name": { "title": "Mr", "first": "Ceyhun", "last": "Tekelioğlu"  },
            "email": "ceyhun.tekelioglu@example.com",
        },
        {
            "gender": "male",
            "name": { "title": "Mr", "first": "Pelle", "last": "Vestnes"
            },
            "email": "pelle.vestnes@example.com",
        },
        {
            "gender": "male",
            "name": { "title": "Mr","first": "Stanislaw", "last": "Aanestad"
            },
            "email": "stanislaw.aanestad@example.com",
        },
        {
            "gender": "female",
            "name": { "title": "Mrs",  "first": "Esperanza",  "last": "Colón"},
            "email": "esperanza.colon@example.com",
        }
    ]

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

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( "vipin@vipin.in" )) //true

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

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

console.log( isUrl("vipin@vipin.in")) //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
2.0.35

8 months ago

2.0.36

8 months ago

2.0.33

8 months ago

2.0.34

8 months ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

2.0.28

1 year ago

2.0.29

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.31

1 year ago

2.0.9

1 year ago

2.0.32

1 year ago

2.0.8

1 year ago

1.0.22

1 year ago

2.0.30

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

2.0.1

1 year ago

1.0.24

1 year ago

2.0.0

1 year ago

1.0.23

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

2.0.15

1 year ago

2.0.16

1 year ago

2.0.13

1 year ago

2.0.14

1 year ago

2.0.11

1 year ago

2.0.12

1 year ago

2.0.10

1 year ago

2.0.19

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

2.0.26

1 year ago

2.0.27

1 year ago

2.0.24

1 year ago

2.0.25

1 year ago

2.0.22

1 year ago

2.0.23

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago