2.0.0 ā€¢ Published 11 months ago

nested-object-validate v2.0.0

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

object validation package for my personal use!

šŸ  Homepage

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!

2.0.0

11 months ago

1.0.0

12 months ago

0.0.0

12 months ago