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

@mayajs/common

v0.7.1

Published

A Node.js framework for REST API server-side-applications.

Downloads

22

Readme

Installation

npm i @mayajs/common

Decorators

Validations

METHOD DECORATORS

This are functions that defines what function to be used in a route method inside a controller.

Usage

Before using a decorator you must first import it from @mayajs/common module.

import { Get, Post, Put, Patch, Delete } from "@mayajs/common";

You can use a method decorator like calling a normal function with the exception of adding an @ sign before the function name. The route path has a default value of "/".

@Get()
function(){
    // Do some GET stuff here
}

You can also provides additional parameters that includes the path and middlewares for that specific route.

@Get({ path: "/", middlewares: [] })
function(){
    // Route logic
}

Note: middlewares are OPTIONAL

You can also just provide a string denoting the name of the route.

@Get("/")
function(){
    // Route logic
}

You can also just provide an array of middleware and its path will have a default value of "/" as the route name.

@Get([middlewares])
function(){
    // Route logic
}

GET

This is a decorator function is for creating a GET METHOD ROUTE. GET request is used to retreive a resource.

import { Get } from "@mayajs/common";

POST

This is a decorator function is for creating a POST METHOD ROUTE. POST requests are used to send data to the API sever to create a resource.

import { Post } from "@mayajs/common";

PUT

This is a decorator function is for creating a PUT METHOD ROUTE. PUT requests are used to replace a resource.

import { Put } from "@mayajs/common";

PATCH

This is a decorator function is for creating a PATCH METHOD ROUTE. PATCH is similar to POST and PUT but used only to apply partial modifications to a resource.

import { Patch } from "@mayajs/common";

DELETE

This is a decorator function is for creating a DELETE METHOD ROUTE. DELETE request is used to delete the resource at the specified URL.

import { Delete } from "@mayajs/common";

VALIDATIONS

Check

This is a function used for validating fields for BODY and PARAMS of a request.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("age") // Name of the fields to be checked. `defaults` to check the `body` of the request.
     .isNumber() // Checks if the field is a number
     .minLength(5) // Checks if the field has a minimum length of 5
     .maxLength(10) // Checks if the field has a maximum length of 10
     .notEmpty() // Checks if the field is not empty
     .required(), // Checks if the field is present or not undefined
] })
function(){}

isNumber

This is a validation function that is used along with Check. This function checks if the field is a number and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("age").isNumber(),
] })
function(){}

isBoolean

This is a validation function that is used along with Check. This function checks if the field is a boolean and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("islogin").isBoolean(),
] })
function(){}

isString

This is a validation function that is used along with Check. This function checks if the field is a string and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").isString(),
] })
function(){}

isAddress

This is a validation function that is used along with Check. This function checks if the field is a valid address and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("address").isAddress(),
] })
function(){}

isRegExp

This is a validation function that is used along with Check. This function accepts a RegExp and checks if the field will match the regex. If the test fails it will send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").isRegExp(/^[A-Za-z0-9.,\s]*$/),
] })
function(){}

minLength

This is a validation function that is used along with Check. This function accepts an argument which is a number and checks if the field length is greater than or equal to the parameter. If the field length is not greater than or equal to the parameter it will send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").minLength(5),
] })
function(){}

maxLength

This is a validation function that is used along with Check. This function accepts an argument which is a number and checks if the field length is less than or equal to the parameter. If the field length is not less than or equal to the parameter it will send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").maxLength(10),
] })
function(){}

isDate

This is a validation function that is used along with Check. This function checks if the field is a valid date and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("date").isDate(),
] })
function(){}

isEmail

This is a validation function that is used along with Check. This function checks if the field is a valid email and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("email").isEmail(),
] })
function(){}

isPassword

This is a validation function that is used along with Check. This function checks if the field is a valid password and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").isPassword(),
] })
function(){}

notEmpty

This is a validation function that is used along with Check. This function checks if the field is not empty and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("password").notEmpty(),
] })
function(){}

required

This is a validation function that is used along with Check. This function checks if the field is not undefined and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("user").required(),
] })
function(){}

isArray

This is a validation function that is used along with Check. This function checks if the field is an array and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("user").isArray(),
] })
function(){}

includes

This is a validation function that is used along with Check. This function accepts an array of values and checks if the field or fields items values is included on the array and send a validation error response if its not.

Import

import { Check } from "@mayajs/common";

Usage

@Post({ path: "/", middlewares: [
     Check("user").includes<string>(["cats", "dogs"]),
] })
function(){}