DEV Community

Asim786521
Asim786521

Posted on

Top 5 javascript libraries you should know

Nodejs is an asynchronous event-driven javascript runtime is used to build a large web application and it supports many businesses and startups to develop more things and earn revenues.

Express is a leading Framework used to create and develop the application. there are lots of packages in Express to perform different operation and function that helps programmers very much.

npm is the package manager of Node js. It was created in 2009 as an open-source project that helps JavaScript developers easily share packaged modules of code. there are lots of packages that are used in the Express as per user-requirement.

1.Joi

Image1

The package much have absolutely necessary package if you are implementing anything which requires a lot of data input from the user. This is the most powerful schema description language and data validator for JavaScript.

Installation

npm install joi
Enter fullscreen mode Exit fullscreen mode

Example

const Joi = require('joi');

const schema = Joi.object({
    username: Joi.string()
        .alphanum()
        .min(3)
        .max(30)
        .required(),

    password: Joi.string()
        .pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),

    repeat_password: Joi.ref('password'),

    access_token: [
        Joi.string(),
        Joi.number()
    ],

    birth_year: Joi.number()
        .integer()
        .min(1900)
        .max(2013),

    email: Joi.string()
        .email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } })
})
    .with('username', 'birth_year')
    .xor('password', 'access_token')
    .with('password', 'repeat_password');


schema.validate({ username: 'abc', birth_year: 1994 });
// -> { value: { username: 'abc', birth_year: 1994 } }

schema.validate({});
// -> { value: {}, error: '"username" is required' }

// Also -

try {
    const value = await schema.validateAsync({ username: 'abc', birth_year: 1994 });
}
catch (err) { }
Enter fullscreen mode Exit fullscreen mode

2.Tiny-invarient

If you have ever used typescript then you known that lots of time the typescript will complain when we pass the value then it show undefined or Null value and also undefined error.when you use invarient then it helps to remain the variable exist.It contains lots of conditions and also assertive statements but also use typescript.

An invariant function takes a value, and if the value is falsy then the invariant function will throw. If the value is truthy, then the function will not throw.

Installation

npm i tiny-invariant

`import invariant from 'tiny-invariant';

invariant(truthyValue, 'This should not throw!');

invariant(falsyValue, 'This will throw!');
// Error('Invariant violation: This will throw!');

`
Enter fullscreen mode Exit fullscreen mode

3.ZXCVBN

zxcvbn is from dropbox and used to allow you to add a good password.zxcvbn is a password strength estimator inspired by password crackers. Through pattern matching and conservative estimation, it recognizes and weighs 30k common passwords, common names and surnames according to US census data, popular English words from Wikipedia and US television and movies, and other common patterns like dates, repeats (aaa), sequences (abcd), keyboard patterns (qwertyuiop), and l33t speak.

cd /path/to/project/root
bower install zxcvbn
Enter fullscreen mode Exit fullscreen mode

4.NanoID

A tiny unique string ID generator for JavaScript.it have a lots of nano ids that go down in the URL structure. This package will generate a tiny secure URL friendly identifier.there are lots of Functions in the package and it has more speed in terms of safety in terms of URL.Early use uuid as as a generator and now shifted to nano id generator.

Installation

npm i nanoid

5.Canvas

node-canvas is a Cairo-backed Canvas implementation for Node.js.you have basically customize a lot of confident effects and if you need to show a appreciation,happiness and milestone this might to be a great package to plug in.

Installation

npm i canvas

Top comments (0)