How to use the is2.num function in is2

To help you get started, we’ve selected a few is2 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 stdarg / config-js / index.js View on Github external
var isValid = ('undefined'!==typeof currVal && null!==currVal);

    // invalid value found and no default value, then we throw an error
    if (!isValid && typeof defaultValue === 'undefined' && !fromEnv) {
        debug('Var statuses ','!isValid',!isValid,'typeof defaultValue',
              typeof defaultValue, '!fromEnv',!fromEnv);
        throw new Error('No config value found for: '+propertyName);
    }

    // either return found value or default
    if (!fromEnv) {
        debug('Propery '+envPropName+' gotten from config file: ',(isValid ? currVal : defaultValue));
        return isValid ? currVal : defaultValue;
    } else {
        debug('Attempting to coercion checks.');
        if (is.num(currVal)) {
            debug('Coercing env '+envPropName+' to a numeric.');
            return Number(envStr);
        } else if (is.array(currVal)) {
            debug('Coercing env '+envPropName+' to an array.');
            if (/^\[(.)*\]$/.match(envStr)) {
                envStr = envStr.substr(1);  // remove '['
                envStr = envStr.substring(0, envStr.length-1);
                var elems = envStr.split(',');
                for (var i=0; i

is2

A type checking library where each exported function returns either true or false and does not throw. Also added tests.

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis