Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
annotate.js
allows you to attach certain metadata to your functions. For
instance you could document invariants of your function this way. In
addition you can attach an optional description you can access later on.
This metadata can be used by tools such as suite.js in order to generate tests. In addition you can access the metadata via REPL.
The usage is quite simple as the following example illustrates:
// let's define some function to annotate
function add(a, b) {
return a + b;
}
// type checkers from is-js (https://npmjs.org/package/is-js)
var addNumbers = annotate('addNumbers', 'Adds numbers')
.on(is.number, is.number, add);
var addStrings = annotate('addStrings', 'Adds strings')
.on(is.string, is.string, add);
// you can assert invariants too
var addPositive = annotate('addPositive', 'Adds positive')
.on(isPositive, isPositive, add)
.satisfies(isPositive); // postcondition
// it is possible to chain guards
var fib = annotate('fib', 'Calculates Fibonacci numbers')
.on(0, 0).on(1, 1)
.on(is.number, function(n) {
return fib(n - 1) + fib(n - 2);
});
// invariants may depend on each other
var clamp = annotate('clamp', 'Clamps given number between given bounds')
.on(is.number, is.number, function(a, args) {
return is.number(a) && args[1] <= a;
}, function(a, min, max) {
return Math.max(Math.min(a, max), min);
});
// furthermore it is possible to pass a variable amount of args
var min = annotate('min', 'Returns minimum of the given numbers')
.on([is.number], Math.min);
function isPositive(a) {
return a >= 0;
}
The annotate
function will create a new function that contains the metadata as
properties _name
, _doc
, _preconditions
and _postconditions
. In case
some pre- or postcondition doesn't pass it won't return and gives a warning
instead.
annotate.js
and suite.js
annotate.js
is available under MIT. See LICENSE for more details.
FAQs
Asserts your function invariants
The npm package annotate receives a total of 1,763 weekly downloads. As such, annotate popularity was classified as popular.
We found that annotate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.