Installations
npm install aproba
Releases
Unable to fetch releases
Developer
iarna
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
9.11.0
NPM Version
6.1.0-next.0
Statistics
132 Stars
45 Commits
15 Forks
7 Watching
2 Branches
6 Contributors
Updated on 16 Jun 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,543,848,292
Last day
-2.2%
4,028,569
Compared to previous day
Last week
2.6%
21,843,996
Compared to previous week
Last month
14.9%
89,034,812
Compared to previous month
Last year
-17.4%
1,013,422,611
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
aproba
A ridiculously light-weight function argument validator
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
Valid types are:
type | description |
---|---|
* | matches any type |
A | Array.isArray OR an arguments object |
S | typeof == string |
N | typeof == number |
F | typeof == function |
O | typeof == object and not type A and not type E |
B | typeof == boolean |
E | instanceof Error OR null (special: see below) |
Z | == null |
Validation failures throw one of three exception types, distinguished by a
code
property of EMISSINGARG
, EINVALIDTYPE
or ETOOMANYARGS
.
If you pass in an invalid type then it will throw with a code of
EUNKNOWNTYPE
.
If an error argument is found and is not null then the remaining
arguments are optional. That is, if you say ESO
then that's like using a
non-magical E
in: E|ESO|ZSO
.
But I have optional arguments?!
You can provide more than one signature by separating them with pipes |
.
If any signature matches the arguments then they'll be considered valid.
So for example, say you wanted to write a signature for
fs.createWriteStream
. The docs for it describe it thusly:
fs.createWriteStream(path[, options])
This would be a signature of SO|S
. That is, a string and and object, or
just a string.
Now, if you read the full fs
docs, you'll see that actually path can ALSO
be a buffer. And options can be a string, that is:
path <String> | <Buffer>
options <String> | <Object>
To reproduce this you have to fully enumerate all of the possible
combinations and that implies a signature of SO|SS|OO|OS|S|O
. The
awkwardness is a feature: It reminds you of the complexity you're adding to
your API when you do this sort of thing.
Browser support
This has no dependencies and should work in browsers, though you'll have noisier stack traces.
Why this exists
I wanted a very simple argument validator. It needed to do two things:
-
Be more concise and easier to use than assertions
-
Not encourage an infinite bikeshed of DSLs
This is why types are specified by a single character and there's no such thing as an optional argument.
This is not intended to validate user data. This is specifically about asserting the interface of your functions.
If you need greater validation, I encourage you to write them by hand or look elsewhere.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
49 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More