
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
typed-function
Advanced tools
Type checking for JavaScript functions.
Features:
Supported environments: node.js, Chrome, Firefox, Safari, Opera, IE9+.
Install via npm:
npm install typed-function
Example usage:
var typed = require('typed-function');
// create a typed function
var fn = typed({
'number': function (a) {
return 'a is a number';
},
'number, boolean': function (a, b) {
return 'a is a number, b is a boolean';
},
'number, number': function (a, b) {
return 'a is a number, b is a number';
}
});
// use the function
console.log(fn(2, true)); // outputs 'a is a number, b is a boolean'
console.log(fn(2)); // outputs 'a is a number'
// calling the function with a non-supported type signature will throw an error
try {
fn('hello world');
}
catch (err) {
console.log(err.toString()); // outputs: 'TypeError: Wrong function signature'
}
Type checking input arguments adds some overhead to a function. For very small
functions this overhead can be larger than the function execution itself is,
but for any non-trivial function the overhead is typically small to neglectable.
You need to keep in mind though that you probably would have to do the type
checking done by typed-function anyway.
A function is constructed as:
typed(signatures: Object.<string, function>) : function
typed(name: string, signatures: Object.<string, function>) : function
typed.types: Object
A map with the object types as key and a type checking test as value.
Custom types can be added like:
function Person(...) {
...
}
typed.types['Person'] = function (x) {
return x instanceof Person;
};
typed.conversions: Array
An Array with built-in conversions. Empty by default. Can be used for example
to defined conversions from boolean to number. For example:
typed.conversions.push({
from: 'boolean',
to: 'number',
convert: function (x) {
return +x;
});
typed-function has the following built-in types:
nullbooleannumberstringfunctionArrayDateRegExpObject* (anytype)The functions generated with typed({...}) have:
toString() function which returns well readable code, giving insight in
what the function exactly does.signatures, which holds a map with the (normalized)
signatures as key and the original sub-functions as value.'*, boolean''string, ...''number?, array'number | string, number''"linear" | "cubic"'.'{name: string, age: number}''Object.<string, Person>''Array.<Person>'To test the library, run:
npm test
To generate the minified version of the library, run:
npm run minify
io-ts is a runtime type system for IO decoding/encoding in TypeScript. It allows you to define types and validate data at runtime. Compared to typed-function, io-ts is more focused on data validation and transformation rather than function overloading.
Runtypes provides a way to define and validate types at runtime in TypeScript. It offers a similar type-checking functionality but is more geared towards defining and validating data structures rather than function signatures.
ts-runtime is a TypeScript transformer that adds runtime type checks to your TypeScript code. It provides a more integrated approach to type checking in TypeScript, whereas typed-function is a standalone library for JavaScript.
FAQs
Type checking for JavaScript functions
The npm package typed-function receives a total of 542,192 weekly downloads. As such, typed-function popularity was classified as popular.
We found that typed-function demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.