{"id":44878306,"url":"https://github.com/aycangulez/fn-arg-validator","last_synced_at":"2026-02-17T15:08:46.610Z","repository":{"id":209268335,"uuid":"723127735","full_name":"aycangulez/fn-arg-validator","owner":"aycangulez","description":"A lightweight JavaScript library to validate function arguments.","archived":false,"fork":false,"pushed_at":"2024-04-02T11:19:20.000Z","size":60,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-31T09:46:16.078Z","etag":null,"topics":["defensive-programming","validation","validation-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aycangulez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-11-24T18:59:47.000Z","updated_at":"2024-01-23T07:43:30.000Z","dependencies_parsed_at":"2023-12-16T12:04:19.039Z","dependency_job_id":"a4260aff-745b-486d-92b8-7fe0f9740ad7","html_url":"https://github.com/aycangulez/fn-arg-validator","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"fc948c09110f641d98f5738f36ef0d79d1445539"},"previous_names":["aycangulez/fn-arg-validator"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/aycangulez/fn-arg-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aycangulez%2Ffn-arg-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aycangulez%2Ffn-arg-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aycangulez%2Ffn-arg-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aycangulez%2Ffn-arg-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aycangulez","download_url":"https://codeload.github.com/aycangulez/fn-arg-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aycangulez%2Ffn-arg-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29548206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T14:33:00.708Z","status":"ssl_error","status_checked_at":"2026-02-17T14:32:58.657Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defensive-programming","validation","validation-library"],"created_at":"2026-02-17T15:08:44.324Z","updated_at":"2026-02-17T15:08:46.603Z","avatar_url":"https://github.com/aycangulez.png","language":"JavaScript","readme":"fn-arg-validator is a lightweight JavaScript library for validating function arguments.\n\n## Installation\n\n### Node.js\n\n```bash\nnpm install --save fn-arg-validator\n```\n\n### Browsers\n\nInstall as above and use the `fn-arg-validator.js` file found in the node_modules directory. You will also need to include lodash if you aren't already using it in your application.\n\n```html\n\u003cscript src=\"./node_modules/fn-arg-validator/fn-arg-validator.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/lodash/lodash.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nFirst, a quick example:\n\n```js\nconst is = require('fn-arg-validator');\n\nfunction createUser(firstName, lastName, birthDate) {\n    is.valid(is.string, is.string, is.date, arguments);\n    // ...\n}\n\ncreateUser('Thomas', 'Anderson', '1971-09-13');\n// [WARN] 1971-09-13 failed date check \n}\n```\n\n**is.valid()** uses a functional style interface where you pass type check functions (built-in or your own) for each function argument, and as the final argument, you simply pass the *arguments* object to avoid writing the function parameters again. \n\nThe *arguments* object isn't available for arrow functions, so you need to type the parameter names in an array like *[firstName, lastName, birthDate]* for those.\n\nThe above code will normally log a warning and continue to run, but you may choose to check the return value of **is.valid** to stop the execution of the rest of the code. The decision depends on how you want to handle type errors. Sometimes, a warning is enough, and sometimes you need to be strict and throw an error.\n\n### Boundary Checks and Maybe Types\nIn addition to strict type checks, it's possible to do things like string length checks, and use maybe types that also accept undefined/null values:\n\n```js\nfunction createUser(firstName, lastName, birthDate) {\n    is.valid(is.stringBetween(1, 20), is.stringLTE(20), is.maybeDate, arguments);\n    // ...\n}\n```\n\n### Object Property and Type Checks\n\n**is.objectWithProps** can be used to check if an object has the specified properties and those properties have the correct types.\n\n```js\nconst userObjectProps = { id: is.number, firstName: is.string, lastName: is.string, birthDate: is.date };\n\nfunction updateUser(user) {\n    if (!is.valid(is.objectWithProps(userObjectProps), arguments)) {\n        throw new Error('Invalid user object');\n    }\n    // ...\n}\n\nupdateUser({ id: 1, firstName: 'Thomas', lastName: 'Anderson', birthDate: '1971-09-13' });\n/*\n[WARN] {\"id\":1,\"firstName\":\"Thomas\",\"lastName\":\"Anderson\",\"birthDate\":\"1971-09-13\"} failed objectWithProps check\n\nError: Invalid user object\n...\n*/\n```\n\n**Note:** You can have one-level of nested object property checks as shown below:\n\n```js\nis.valid(\n    is.objectWithProps({\n        a: is.number,\n        b: is.objectWithProps({ c: is.string, d: is.number }),\n    }),\n    arguments\n);\n```\n\n## Built-in Type Check Functions\n\n### Strict Type Checks\n\n* **is.array:** Returns true if the argument is an array.\n* **is.boolean:** Returns true if the argument is a boolean.\n* **is.buffer:** Returns true if the argument is a buffer.\n* **is.date:** Returns true if the argument is a Date object.\n* **is.func:** Returns true if the argument is a function.\n* **is.number:** Returns true if the argument is a number.\n* **is.object:** Returns true if the argument is an object.\n* **is.string:** Returns true if the argument is a string.\n\n### Maybes\n* **is.maybeArray:** Returns true if the argument is an array or undefined/null.\n* **is.maybeBoolean:** Returns true if the argument is a boolean or undefined/null.\n* **is.maybeBuffer:** Returns true if the argument is a buffer or undefined/null.\n* **is.maybeDate:** Returns true if the argument is a Date object or undefined/null.\n* **is.maybeFunc:** Returns true if the argument is a function or undefined/null.\n* **is.maybeNumber:** Returns true if the argument is a number or undefined/null.\n* **is.maybeObject:** Returns true if the argument is an object or undefined/null.\n* **is.maybeString:** Returns true if the argument is string or undefined/null.\n\n### Boundary Checks\n* **is.numberGT(n):** Returns true if the argument is a number and greater than *n*.\n* **is.numberGTE(n):** Returns true if the argument is a number and greater than or equal to *n*.\n* **is.numberLT(n):** Returns true if the argument is a number and less than *n*.\n* **is.numberLTE(n):** Returns true if the argument is a number and less than or equal to *n*.\n* **is.numberBetween(n1, n2):** Returns true if the argument is a number and between *n1* and *n2* (inclusive).\n* **is.stringGT(n):** Returns true if the argument is a string and its length is greater than *n*.\n* **is.stringGTE(n):** Returns true if the argument is a string and its length is greater than or equal to *n*.\n* **is.stringLT(n):** Returns true if the argument is a string and its length is less than *n*.\n* **is.stringLTE(n):** Returns true if the argument is a string and its length is less than or equal to *n*.\n* **is.stringBetween(n1, n2):** Returns true if the argument is a string and its length is between *n1* and *n2* (inclusive).\n\n### Mixed Types\n* **is.oneOf** returns true if an argument's type is one of the passed types. For example, **is.oneOf(is.number, is.array)** returns true for *1* and *[1]*, but not *'1'*.\n\n### Object Property and Type Checks\n* **is.objectWithProps(props):** Returns true if the argument is an object and the property-type pairs match the argument's properties and their types.\n\n### Catch-all\n* **is.any:** Returns true for everything. Great for skipping validation for certain arguments.\n\n## Passing your Own Type Check Functions\nThe beauty of a functional style interface is that you aren’t limited to the built-in validation functions, you can simply pass your own. The only requirement is to give your functions names since is.valid uses function names for logging purposes.\n\n## Throwing Exceptions\nfn-arg-validator can be configured to throw exceptions on failed checks when **is.config.throw** is set to *true*.\n\n## Log Configuration\nBy default, fn-arg-validator uses the *console* object for logging. However, this can be configured by assigning a different logger to **is.config.log**.\n\nThe log level can be set by changing the value of **is.config.logLevel**. The default log level is *'WARN'*, which only logs failed checks. If you would like to see successful validations, you need to set the log level to *'DEBUG'* or higher. To disable all logging, set the log level to *'OFF'*.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faycangulez%2Ffn-arg-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faycangulez%2Ffn-arg-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faycangulez%2Ffn-arg-validator/lists"}