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

kemo-easy-life

v1.1.3

Published

A demo package for make easy api with validation greeting(ITI)

Downloads

23

Readme

Project Title

This package helps to easy create your own api with validation

Installation

Install my-project with npm

npm i kemo-easy-life

Using cli

To use cli commands for kemo-easy-life run this command:

npm i -g kemo-easy-life
//then
kemo-easy-life help //for more commands information

by using cli commands you can create sections very easy like this:

kemo-easy-life create users
//or
kel create users

This will auto generate users sections files with some ready code like below:

App Screenshot


And to create multiple sections once you can separate the section name chain with "-" like below:

kel create product-cart

This will create products and carts section sequentially.

Usage/Examples

Quick start, You can easily start running server with this by using run().

const kemo = require("kemo-easy-life")

// this will start run the server at http://127.0.0.1:7000
kemo.run() 

To change the port or the message after running:

const kemo = require("kemo-easy-life")

// this will start run the server at http://127.0.0.1:3000
kemo.run({port = 3000, message: "Hello world"}) 

Creating routes

Its easy to make routes like example blow:

const kemo = require("kemo-easy-life")

    kemo.route({
        method: kemo.routeMethods.GET, // default get
        path: "/", // required
        execute : (req , res)=>{
            res.send("Hello World!")
        } // This output will be "Hello World!"
    })

kemo.run() 

Creating routeGroup

To create group of routes use the example below:

const kemo = require("kemo-easy-life")

kemo.routeGroup({
    groupPath: "/api/users",
    routes: [
        {
            execute: (req, res) => {
                res.send(`Hello from "api/users/"`)
            }
        },
        {
            path: "/create",
            method: kemo.routeMethods.POST,
            execute: (req, res) => {
                res.send(`Hello from "api/users/create"`)
            }
        },
    ]
})

kemo.run()

Add middlewares

You can add any number of middlewares in middleware array like below.

const kemo = require("kemo-easy-life")

const mdws = [
    (req, res, next) => {
        if (true) {
            console.log('Hello from first middleware');
            next()
        }
    },
    (req, res, next) => {
        if (true) {
            console.log('Hello from second middleware');
            next()
        }
    },
]

kemo.route({
    method: kemo.routeMethods.GET,
    path: "/",
    middlewares: mdws,
    execute: (req, res) => {
        res.send("Hello World!")
    }
})


kemo.run()

routeGroup middlewares

You can add middlewares for the whole group or to specific one .

const kemo = require("kemo-easy-life")

const mdwsForGroup = [
    (req, res, next) => {
        if (true) {
            console.log('Hello from group middleware');
            next()
        }
    }
]

const mdwsForRoute = [
    (req, res, next) => {
        if (true) {
            console.log('Hello from route middleware');
            next()
        }
    }
]

kemo.routeGroup({
    groupPath: "/api/users",
    middlewares: mdwsForGroup,
    routes: [
        {
            middlewares: mdwsForRoute,
            execute: (req, res) => {
                res.send(`Hello from "api/users/"`)
            }
        },
    ]
})

kemo.run()

Add Validation

const kemo = require("kemo-easy-life")

const validation = {
    user_name: [
        kemo.validate.required,
        kemo.validate.alpha
    ],
    email: [
        kemo.validate.required,
        kemo.validate.email
    ],
    password: [
        kemo.validate.required,
        kemo.validate.alphaNum,
        kemo.validate.confirmed
    ],
    password_confirmation: [
        kemo.validate.requiredWithAll(["password"])
    ],
}

kemo.route({
    method: kemo.routeMethods.GET,
    path: "/",
    validate: validation,
    execute: (req, res) => {
        res.send("Hello World!")
    }
})

kemo.run()

Validation keywords

//# main validation words
    required,
    isTrue,
    alpha,
    alphaDash,
    alphaNum,
    array,
    boolean,
    confirmed,
    date,
    isFalse,
    email,
    json,
    integer,
    nullable,
    numeric,
    object,
    requiredAndNullable,
    string,
    url,
    validateOnlyIfExist,

//# main validation functions
    isTrueIf({ anotherFiled :"username" ,anotherFiledValue :"kareem" }),
    dateAfter("2021-12-11"),
    dateAfterOrEqual("2021-12-11"), 
    dateBefore("2021-12-11"),  
    dateBeforeOrEqual("2021-12-11"), 
    between({ min, max }), 
    dateEquals("2021-12-11"), 
    isFalseIf({ anotherFiled :"username" ,anotherFiledValue :"kareem" }),
    differentThanField(field), 
    endsWith([]), 
    greaterThan(field), 
    greaterThanOrEqual(field), 
    in([]), 
    lessThan(field),
    lessThanOrEqual(field), 
    max(value),
    min(value),
    notIn([]),
    regex(data),
    notRegex(data),
    requiredIf (data),
    requiredWith([]),
    requiredWithAll([]),
    requiredWithout([]),
    requiredWithoutAll([]),
    same(field),
    size(value),