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

owi-validator

v1.1.0

Published

**owi-validator** is a beginner friendly light weight validation library built with javascript. <br> [![Build Status](https://travis-ci.org/cleave3/owi_validator.svg?branch=master)](https://travis-ci.org/cleave3/owi_validator) [![Coverage Status](https://

Downloads

246

Readme

owi-validator

owi-validator is a beginner friendly light weight validation library built with javascript. Build Status Coverage Status Github All Releases GitHub forks GitHub stars GitHub issues

Getting Started

  npm install owi-validator

Features

owi-validator can be used vanilla Js projects, nodeJs and other javascript Applications.

- max()
- min()
- equal()
- number()
- string()
- boolean()
- email()
- telephone()
- url()
- date()
- card()
- length()
- regex()
- array()
- optional()
- required()
- error()

USAGE

Basic usage

//using ES5
const { owi, validate } = require("owi-validator");

//OR

//using ES6
import { owi, validate } from "owi-validator";

const category = "category1";
const price = 2000;
const productName = "product1";
const quantity = 1;
const description = "desc";
const visibility = "public";

const schema = {
  productName: owi(productName)
    .string()
    .min(2)
    .error('product name must be atleast 2 characters long')
    .required()
    .exec(),
    category: owi(category).string().error('category is required').required().exec(),
      price: owi(price).number().error('price must be a number').required().exec(),
      quantity: owi(quantity).number().error('quantity must be a number').optional().exec(),
      description: owi(description).string().error('description is required').required().exec(),
      visibility: owi(visibility)
        .regex(/^(public|private)$/)
        .error('visibilty must be either public or private')
        .required()
        .exec(),
}

const check = validate(schema);

//const {isValid, errors } = check;
// isvalid: boolean ( true || false )
// errors: Array - validation errors if any

if(check.isValid) {
  //validation successfull
  // do success action
} else {
  // Errors found
  console.log(check.errors); // Array of validation errors
}

using as middleware in NodeJs


//Application Entry Point index.js

const express = require("express");
const router = require("./route");

const app = express();

const PORT = process.env.PORT || 3000;

app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(router);

app.listen(PORT, () => console.log(`App is running at port ${PORT}`));

//Validation Class validator.js
const { owi, validate } = require("owi-validator");

class Validate {
  static validatedata({ body: { name, email, password } }, res, next) {

    const check = validate({
      name: owi(name).string().min(2).required().error("Name must be atleast 2 characters long").exec(),
      email: owi(email).email().required().error("Please enter a valid email").exec(),
      password: owi(password).string().min(6).max(10).exec(),
    });

    return check.isValid ? 
      next() : 
      return res.status(code).json({ status, code, errors: check.errors });
  }
}

module.exports = Validate;


//Router router.js file
const { Router } = require("express");
const TestController = require("../controller/dummy");
const Validate = require("../validator");

const router = Router();

const { validatedata } = Validate;
const { postData } = TestController;

router.get("/", (req, res) => res.send("owi-validator is live"));
router.post("/data", validatedata, postData);

module.exports = router;

Contributors