How to use the type-check.parsedTypeCheck function in type-check

To help you get started, we’ve selected a few type-check examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apifytech / actor-scraper / src / modules / utils.js View on Github external
export const checkParamOrThrow = (value, name, type, message) => {
    if (!message) message = `Parameter "${name}" of type ${type} must be provided`;

    const allowedTypes = parseType(type);

    const allowsBuffer = allowedTypes.filter(item => item.type === 'Buffer').length;
    const allowsPromise = allowedTypes.filter(item => item.type === 'Promise').length;

    if (allowsBuffer && Buffer.isBuffer(value)) return;
    if (allowsPromise && typeof value.then === 'function') return;

    // This will ignore Buffer type.
    if (!parsedTypeCheck(allowedTypes, value)) throw new Error(message);
};

type-check

type-check allows you to check the types of JavaScript values at runtime with a Haskell like type syntax.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis