Skip to content

al-imam/nested-object-validate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to nested-object-validate 👋

Version Documentation

object validation package for my personal use!

Install

npm install

how to use it

import { validate, isString } from "nested-object-validate";

/*
  validate function takes 3 argument
  1. argument takes object
  2. argument take validators arrays
*/

/*
  basic validation only check is property is exist
  - validate({ name: 54 }, ["name"])
*/

validate({ name: 54 }, ["name"]);
/*
  basic validation pass, but it that all you want name should be string
  you have more access to validate property
*/

/*
  there is array support where second index is callback
  callback called with property value do what ever you want to value
  return true if pass return false is failed test
  - validate(object, [["name", callback], "age"])
*/

validate({ name: 54 }, [["name", (name) => typeof name === "string"]]);
/*
  test failed because name is number here
  but what if the name is object of first and last?

  - validate({name: {first: "", last: ""}}, ["name"])

  recursion is solution but validate function return static 
  so i made a wrapper of validation
  call in callback second argument
*/

validate({ name: { first: "al", last: "imam" } }, [
  ["name", (name, v) => v(name, [isString("first"), isString("last")])],
]);
/*
  test pass you can ensure first and last exist
  you should know that callback function is instance of validate function
  just formate return value and return true or false
*/

Author

👤 al-imam

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

About

i solve my personal problem, i had issue with validating request body then i build this to help with that!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published