How to use boolean - 10 common examples

To help you get started, we’ve selected a few boolean 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 LearningLocker / learninglocker / lib / connections / nodemailer.js View on Github external
import boolean from 'boolean';
import defaultTo from 'lodash/defaultTo';
import logger from 'lib/logger';
import nodemailer from 'nodemailer';

const smtpConfig = {
  host: process.env.SMTP_HOST,
  port: process.env.SMTP_PORT,
  secure: boolean(defaultTo(process.env.SMTP_SECURED, false)),
  ignoreTLS: boolean(defaultTo(process.env.SMTP_IGNORE_TLS, false)),
  requireTLS: boolean(defaultTo(process.env.SMTP_REQUIRE_TLS, false))
};

// Placed like this since the boolean set default can be hard to read in an if condition.
const sendAuthRequest = boolean(defaultTo(process.env.SMTP_AUTH_REQUEST, true));

// Do not want the auth object in the smtpConfig object if sendAuthRequest is false, default is true.
if (sendAuthRequest) {
  Object.assign(smtpConfig, {
    auth: {
      user: process.env.SMTP_USER,
      pass: process.env.SMTP_PASS
    }
  });
}

let mailer; //eslint-disable-line

if (process.env.TESTING) {
  mailer = {
    sendMail: (opts) => {
github gajus / slonik / src / config.js View on Github external
// @flow

/* eslint-disable no-process-env */

import boolean from 'boolean';

export const SLONIK_LOG_STACK_TRACE = boolean(process.env.SLONIK_LOG_STACK_TRACE);
export const SLONIK_LOG_VALUES = boolean(process.env.SLONIK_LOG_VALUES);
github gajus / roarr / src / config.js View on Github external
// @flow

/* eslint-disable no-process-env */

import parseBoolean from 'boolean';

const ROARR_BUFFER_SIZE = process.env.ROARR_BUFFER_SIZE === undefined ? 0 : parseInt(process.env.ROARR_BUFFER_SIZE, 10);
const ROARR_LOG = parseBoolean(process.env.ROARR_LOG) === true;
const ROARR_STREAM = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase();

if (ROARR_STREAM !== 'STDOUT' && ROARR_STREAM !== 'STDERR') {
  throw new Error('Unexpected ROARR_STREAM value.');
}

if (isNaN(ROARR_BUFFER_SIZE)) {
  throw new TypeError('Unexpected ROARR_BUFFER_SIZE value.');
}

export {
  ROARR_BUFFER_SIZE,
  ROARR_LOG,
  ROARR_STREAM
};
github LearningLocker / learninglocker / lib / connections / nodemailer.js View on Github external
import boolean from 'boolean';
import defaultTo from 'lodash/defaultTo';
import logger from 'lib/logger';
import nodemailer from 'nodemailer';

const smtpConfig = {
  host: process.env.SMTP_HOST,
  port: process.env.SMTP_PORT,
  secure: boolean(defaultTo(process.env.SMTP_SECURED, false)),
  ignoreTLS: boolean(defaultTo(process.env.SMTP_IGNORE_TLS, false)),
  requireTLS: boolean(defaultTo(process.env.SMTP_REQUIRE_TLS, false))
};

// Placed like this since the boolean set default can be hard to read in an if condition.
const sendAuthRequest = boolean(defaultTo(process.env.SMTP_AUTH_REQUEST, true));

// Do not want the auth object in the smtpConfig object if sendAuthRequest is false, default is true.
if (sendAuthRequest) {
  Object.assign(smtpConfig, {
    auth: {
      user: process.env.SMTP_USER,
      pass: process.env.SMTP_PASS
    }
  });
}
github gajus / roarr / src / log.js View on Github external
import environmentIsNode from 'detect-node';
import {
  createLogger,
  createMockLogger,
  createRoarrInititialGlobalState,
} from './factories';

const globalThis = createGlobalThis();

globalThis.ROARR = createRoarrInititialGlobalState(globalThis.ROARR || {});

let logFactory = createLogger;

if (environmentIsNode) {
  // eslint-disable-next-line no-process-env
  const enabled = boolean(process.env.ROARR_LOG || '');

  if (!enabled) {
    logFactory = createMockLogger;
  }
}

export type {
  LoggerType,
  MessageType,
  TranslateMessageFunctionType,
} from './types';

export default logFactory((message) => {
  if (globalThis.ROARR.write) {
    // Stringify message as soon as it is received to prevent
    // properties of the context from being modified by reference.
github forwardemail / free-email-forwarding / index.js View on Github external
Array.isArray(this.dnsbl.domains) &&
      Array.isArray(this.dnsbl.removals) &&
      this.dnsbl.domains.length !== this.dnsbl.removals.length
    )
      throw new Error('DNSBL_DOMAINS length must be equal to DNSBL_REMOVALS');

    if (this.config.ssl) {
      this.config.ssl.minVersion = 'TLSv1';
      this.config.ssl.ciphers = tls
        .getCiphers()
        .map(cipher => cipher.toUpperCase())
        .join(':');
      this.config.ssl.secureOptions =
        crypto.constants.SSL_OP_NO_SSLv3 | crypto.constants.SSL_OP_NO_SSLv2;
      delete this.config.ssl.allowHTTP1;
      if (boolean(process.env.IS_NOT_SECURE)) this.config.ssl.secure = false;
      else this.config.ssl.secure = true;
    }

    this.config.smtp = {
      ...this.config.smtp,
      ...this.config.ssl
    };

    // set up DKIM instance for signing messages
    this.dkim = new DKIM(this.config.dkim);

    // initialize redis
    const client = new Redis(
      this.config.redis,
      logger,
      this.config.redisMonitor
github ladjs / lad / template / routes / web / auth.js View on Github external
.get(
    '/:provider/ok',
    policies.ensureLoggedOut,
    web.auth.catchError,
    (ctx, next) => {
      const redirect = ctx.session.returnTo
        ? ctx.session.returnTo
        : `/${ctx.locale}${config.passportCallbackOptions.successReturnToOrRedirect}`;
      return passport.authenticate(ctx.params.provider, {
        ...config.passportCallbackOptions,
        successReturnToOrRedirect: redirect
      })(ctx, next);
    }
  );

if (boolean(process.env.AUTH_GOOGLE_ENABLED)) {
  router.get(
    '/google/consent',
    policies.ensureLoggedOut,
    web.auth.catchError,
    passport.authenticate('google', {
      accessType: 'offline',
      prompt: 'consent', // See google strategy in passport helper
      scope: [
        'https://www.googleapis.com/auth/userinfo.email',
        'https://www.googleapis.com/auth/userinfo.profile'
      ]
    })
  );
}

module.exports = router;
github gajus / global-agent / src / factories / createGlobalProxyAgent.js View on Github external
const createConfiguration = (configurationInput: ProxyAgentConfigurationInputType): ProxyAgentConfigurationType => {
  // eslint-disable-next-line no-process-env
  const environment = process.env;

  const defaultConfiguration = {
    environmentVariableNamespace: typeof environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE === 'string' ? environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE : 'GLOBAL_AGENT_',
    forceGlobalAgent: typeof environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT === 'string' ? parseBoolean(environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT) : true,
    socketConnectionTimeout: typeof environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT === 'string' ? parseInt(environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT, 10) : defaultConfigurationInput.socketConnectionTimeout,
  };

  // $FlowFixMe
  return {
    ...defaultConfiguration,
    ...omitUndefined(configurationInput),
  };
};
github niftylettuce / frisbee / src / index.js View on Github external
this.opts.baseURI ? ` from ${this.opts.baseURI}` : ''
          }`
        )
    });

    if (opts.arrayFormat) {
      this.opts.parse.arrayFormat = 'indices';
      delete opts.arrayFormat;
    }

    if (Array.isArray(opts.preventBodyOnMethods))
      this.opts.preventBodyOnMethods = this.opts.preventBodyOnMethods.map(
        method => method.toUpperCase().trim()
      );

    this.opts.raw = boolean(this.opts.raw);

    if (this.opts.auth) this.auth(this.opts.auth);

    METHODS.forEach(method => {
      this[method.toLowerCase()] = this._setup(method.toLowerCase());
    });

    // alias for `this.del` -> `this.delete`
    this.del = this._setup('delete');

    // interceptor should be initialized after methods setup
    this.interceptor = new Interceptor(this, this.opts.interceptableMethods);

    // bind scope to method
    this.setOptions = this.setOptions.bind(this);
    this.auth = this.auth.bind(this);
github cabinjs / axe / src / index.js View on Github external
endpoint,
        headers: {},
        timeout: 5000,
        retry: 3,
        showStack: process.env.SHOW_STACK
          ? boolean(process.env.SHOW_STACK)
          : true,
        showMeta: process.env.SHOW_META ? boolean(process.env.SHOW_META) : true,
        silent: false,
        logger: console,
        name: false,
        level: 'info',
        levels: ['info', 'warn', 'error', 'fatal'],
        capture: process.browser ? false : env === 'production',
        callback: false,
        appInfo: process.env.APP_INFO ? boolean(process.env.APP_INFO) : true
      },
      config
    );

    this.appInfo = this.config.appInfo
      ? isFunction(parseAppInfo)
        ? parseAppInfo()
        : false
      : false;

    this.log = this.log.bind(this);

    // inherit methods from parent logger
    const methods = Object.keys(this.config.logger).filter(
      key => !omittedLoggerKeys.includes(key)
    );

boolean

boolean converts lots of things to boolean.

MIT
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis

Popular boolean functions