
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
neat-contract
Advanced tools
yet another one contract library, data flow focused
If contract is satisfied, returns value, otherwise, throwing TypeError
exception.
Well suited for promises as well.
npm install --save neat-contract
import contract from 'neat-contract';
contract('input', String, 'unicorns'); // 'unicorns'
contract('input', String, 2); // new TypeError('`input` should be an `String`, but got `Number`: 2')
// several types
contract('input', [String, Array], 'unicorns'); // 'unicorns'
contract('input', [String, Array], ['unicorns']); // ['unicorns']
contract('input', [String, Array], 2); // new TypeError('`input` should be an `String|Array`, but got `Number`: 2')
// curried
contract('input', String)('unicorns'); // 'unicorns'
contract('input', String)(2); // new TypeError('`input` should be an `String`, but got `Number`: 2')
// contracting array
contract(input, Array, ['unicorns', 'cats']); // ['unicorns', 'cats']
contract(input, Array, 2); // new TypeError('`input` should be an `Array`, but got `Number`: 2')
['unicorns', 'cats'].forEach(contract('input[item]', String)); // ['unicorns', 'cats']
['unicorns', 2].forEach(contract('input[item]', String)); // new TypeError('`input[item]` should be an `String`, but got `Number`: 2')
import R from 'ramda';
import contract from 'neat-contract';
// sync data flow
const prefixEslintPlugin = R.pipe(
contract('pluginName', String), // contracting
R.concat('eslint-plugin-')
);
prefixEslintPlugin('import'); // 'eslint-plugin-import'
prefixEslintPlugin(true); // new TypeError('`pluginName` should be an `String`, but got `Boolean`: true')
prefixEslintPlugin(/reg/); // new TypeError('`pluginName` should be an `String`, but got `RegExp`: /reg/')
import R from 'ramda';
import contract from 'neat-contract';
// helpers
const toPromise = Promise.resolve.bind(Promise);
const _log = console.log.bind(console);
const _throw = err => { throw err; };
// async data flow
const prefixEslintPluginAsync = R.pipeP(toPromise,
contract('pluginName', String), // contracting
R.concat('eslint-plugin-')
);
prefixEslintPluginAsync('import').then(_log); // 'eslint-plugin-import'
prefixEslintPluginAsync(true).catch(_throw); // new TypeError('`pluginName` should be an `String`, but got `Boolean`: true')
prefixEslintPluginAsync(/reg/).catch(_throw); // new TypeError('`pluginName` should be an `String`, but got `RegExp`: /reg/')
import R from 'ramda';
import contract from 'neat-contract';
// contracting array
const prefixArrayOfEslintPlugins = R.pipe(
R.pipe( // contracting in 2 steps
contract('plugins', Array), // array itself
R.map(contract('plugins[item]', String)) // each item of array
),
R.map(R.concat('eslint-plugin-'))
);
prefixArrayOfEslintPlugins(['import', 'export']); // ['eslint-plugin-import', 'eslint-plugin-export']
prefixArrayOfEslintPlugins(2); // throw new TypeError('`plugins` should be an `Array`, but got `Number`: 2')
prefixArrayOfEslintPlugins(['unicorns', 2]); // throw new TypeError('`plugins[item]` should be an `String`, but got `Number`: 2')
Contracting arrays in asynchronous functions goes, the same way as in async example from above.
// contract :: String -> Constructor -> a -> a|throw new TypeError
Required
Type: String
Parameter name.
Required
Type: Constructor
Example: String
, Number
or Function
Parameter Constructor for type check
Required
Type: any
Actual parameter itself to type check with Constructor
.
MIT © Vladimir Starkov
FAQs
yet another one contract library, data flow focused
The npm package neat-contract receives a total of 3 weekly downloads. As such, neat-contract popularity was classified as not popular.
We found that neat-contract demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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 researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.