Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
fjl-error-throwing
Advanced tools
Error throwing helpers for quickly throwing errors when a value doesn't match a type.
Error throwing helpers. In particular for when a type doesn't match an expected type (or one of one or more expected types).
errorIfNotType
and errorIfNotTypes
(and their variants (
uncurried versions (same function names though with trailing '$'
character))).
See inline 'readme' docs below or go to the jsdocs page: https://functional-jslib.github.io/fjl-error-throwing/
npm install fjl-error-throwing
Note: For un-curried versions of the methods below access them with a trailing '$' character;
Example errorIfNotType$(...)
etc..
Note: For more extensive docs see jsdocs located at './jsdocs' (in the repo (currently))
errorIfNotType<Type, contextName, valueName, value, messageSuffix=null> {Undefined}
-Curried. Throws an error when your `value` doesn't match given `type`.
errorIfNotTypes<Types, contextName, valueName, value> : {Undefined}
-Curried. Throws an error when your `value` doesn't match one of the given `types` passed in.
getErrorIfNotTypeThrower<messageTmplFunction, typeChecker = defaultTypeChecker> : errorIfNotType
- Gives an errorIfNotType
function (curried version) that uses the passed message template function to generate the error message string.
getErrorIfNotTypesThrower<messageTmplFunction, typeChecker = defaultTypeChecker> : errorIfNotTypes
- Gives an errorIfNotTypes
function (curried version) that uses the passed message template function to generate the error message string.
More extensive docs can be found in './jsdocs' folder. Docs will go up somewhere later. @todo
TemplateContext {Object<value, valueName, expectedTypeName, foundTypeName, messageSuffix>}
Type {String|Function} - Constructor name or constructor itself.
TypesArray {Array<Type>}
TypeChecker {Function<Type, Any>}
ErrorMessageCall {Function<TemplateContext>}
ErrorIfNotType {Function<Type, contextName, valueName, value>:Undefined}
ErrorIfNotTypes {Function<TypesArray, contextName, valueName, value>:Undefined}
@todo add more extensive usage examples
import {
getErrorIfNotTypeThrower, // For passing your own error string renderer
getErrorIfNotTypesThrower, // For passing your own error string renderer
errorIfNotType,
errorIfNotTypes
} from 'fjl-errorThrowing';
const errorIfNotFunction = errorIfNotType(Function); // curried so makes for useful usage
function someFunc (fn) {
errorIfNotFunction('someFunc', 'fn', fn); // Will throw well detailed error when `value` is not a function
// Do something here ...
}
someFunc(_ => 1 + 1); // No error here
someFunc(99); // Error here type doesn't match expected type.
npm install
npm test
(after npm install
).GNU v2, v3
FAQs
Error throwing helpers for quickly throwing errors when a value doesn't match a type.
The npm package fjl-error-throwing receives a total of 10 weekly downloads. As such, fjl-error-throwing popularity was classified as not popular.
We found that fjl-error-throwing 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
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.