aproba
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Aproba is an incredibly lightweight function argument validator built for JavaScript. It is designed to help developers maintain strict type control over function arguments in their JavaScript code, which can significantly improve code quality and reduce runtime errors. Additionally, aproba is suitable for use in the browser due to having no dependencies, allowing for improved stack trace visibility.
Using aproba in your JavaScript project is relatively easy. First, you would need to install the npm package using the command npm install aproba
. Then, you can simply require aproba
in your JavaScript file and begin using the validate
function to enforce strict type control over the arguments passed to your functions.
Here's an example of how you can use aproba:
var validate = require("aproba")
function myfunc(a, b, c) {
// `a` must be a string, `b` a number, `c` a function
validate('SNF', arguments) // [a,b,c] is also valid
}
myfunc('test', 23, function () {}) // ok
myfunc(123, 23, function () {}) // type error
myfunc('test', 23) // missing arg error
myfunc('test', 23, function () {}, true) // too many args error
In the above example, validate('SNF', arguments)
will ensure that the first argument is a string (S), the second one is a number (N), and the third one is a function (F).
For the complete details and documentation on the various type checks and usage examples, visit the aproba project on GitHub at https://github.com/iarna/aproba. The README of the GitHub project page acts as the package's documentation, and it contains an extensive array of information regarding the use of Aproba. It covers topic areas such as error identification, handling optional arguments, and more. However, it's important to note that aproba is not designed to validate user data, but rather to assert the interface of your functions. For greater validation, you may need to consider other packages or custom validation functions.