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.
npm i valdie
or
yarn add valdie
using deno
import valdie from 'https://cdn.skypack.dev/valdie'
import { isEmail } from "valdie"
console.log(isEmail("[email protected]")) // true
let { message,success } = isEmail("[email protected]")
console.log(isInteger(34)) // true
import { isDistinct } from "valdie"
console.log(isDistinct(["true", "false", "yes", "no"])); // true
let { message,success } = isDistinct([1, 2, 3, 4, 5]);
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")
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();
The project is under MIT Licence 2021