Git Product home page Git Product logo

valdie's Introduction

Valdie

CI npm NPM Downloads

A TypeScript and JavaScript Validation Library that works

  • ๐ŸŽ‰ It doesn't have any dependancy
  • ๐Ÿ’ช Simple api
  • ๐Ÿ“ฆ It works with TypeScript

You probably never knew you needed it but here you go.

Getting started

npm i valdie

or

yarn add valdie

using deno

import valdie from 'https://cdn.skypack.dev/valdie'

Documentation

  1. isEmail
  2. isInteger
  3. isString
  4. isURL
  5. isDistinct
  6. isIPv4
  7. isUuid

They are two ways of consuming our api

import { isEmail } from "valdie"

console.log(isEmail("[email protected]")) // true
let { message,success } = isEmail("[email protected]")

isInteger

console.log(isInteger(34)) // true

isDistinct

import { isDistinct } from "valdie"

console.log(isDistinct(["true", "false", "yes", "no"]));  // true
let { message,success } = isDistinct([1, 2, 3, 4, 5]);

isIPv4

Version 4 IP addresses (IPv4) validator

import { isIPv4 } from "valdie"

// sample
console.log( isIPv4('192.168.0.3') ) // { success : true }
console.log( isIPv4('rrtr3345') )  // { message : "rrtr3345 is not a valid IPv4" , success : false } 

// usage 
const myIp : string = "192.168.1.1"
const  { message , success } =  isIPv4(myIp)

if(success) 
    console.log("myIp is an IPv4 address")
else 
    console.log("It's not an IPv4 address")

isUuid

import { isUuid } from "valdie"

// sample

console.log(isUuid('34483ae5-8a6b-4965-9384-cd0ce0191e84')) // { success : true }
console.log( isUuid('helloworld') )  // { message : "helloworld is not a valid uuid" , success : false } 

// usage 

function generateRandomUuid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16 | 0,
            v = c === 'x' ? r : (r & 0x3 | 0x8); // 
        return v.toString(16);
    });
}
const  { message , success } =  isUuid(generateRandomUuid())

if(success) 
    console.log("this is a valid uuid")
else 
    console.log("It's not a valid uuid")

// or 
import valdie from "valdie"

const result = valdie('String to test').isString().isUuid();

Maintainers

Licence

The project is under MIT Licence 2021

valdie's People

Contributors

veritem avatar claranceliberi avatar dependabot[bot] avatar patrickniyogitare28 avatar ntwari-egide avatar irumvanselme avatar renovate-bot avatar divinrkz avatar fadhili-josue avatar pacifiquem avatar cyebukayire avatar regisrex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.