Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
function-composer
Advanced tools
Compose functions with multiple type signatures.
Features:
Supported environments: node.js, Chrome, Firefox, Safari, Opera, IE9+.
Install via npm:
npm install function-composer
Example usage:
var compose = require('function-composer');
// compose a new function
var fn = compose({
'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 function-composer
anyway.
compose(signatures: Object.<string, function>) : function
compose(name: string, signatures: Object.<string, function>) : function
compose.tests: Object
A map with type checking tests. Add custom types like:
function Person(...) {
...
}
compose.tests['Person'] = function (x) {
return x instanceof Person;
};
compose.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:
compose.conversions.push({
from: 'boolean',
to: 'number',
convert: function (x) {
return +x;
});
'*, boolean'
'string, ...'
'number?, array'
number | string, number'
'"linear" | "cubic"'
.'{name: string, age: number}'
'Object.<string, Person>'
'Array.<Person>'
To generate the minified version of the library, run:
npm run minify
2014-10-23, version 0.2.0
FAQs
Compose functions with multiple type signatures
The npm package function-composer receives a total of 7 weekly downloads. As such, function-composer popularity was classified as not popular.
We found that function-composer 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.