How to use envalid - 10 common examples

To help you get started, we’ve selected a few envalid 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 tibdex / autorebase / src / tests-utils.ts View on Github external
const createTestContext = async (
  applicationFunction: (app: Application) => void,
): Promise => {
  const env = envalid.cleanEnv(
    // eslint-disable-next-line no-process-env
    process.env,
    {
      TEST_APP_ID: envalid.num({
        desc:
          "The ID of the GitHub App used during tests." +
          " It must have at least the same permissions than the Autorebase GitHub App.",
      }),
      TEST_APP_PRIVATE_KEY: envalid.makeValidator(str => {
        const privateKeyFromEnv = isBase64(str)
          ? Buffer.from(str, "base64").toString("utf8")
          : str;
        if (
          /-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/m.test(
            privateKeyFromEnv,
          )
github tibdex / autorebase / src / tests-utils.ts View on Github external
const createTestContext = async (
  applicationFunction: (app: Application) => void,
): Promise => {
  const env = envalid.cleanEnv(
    // eslint-disable-next-line no-process-env
    process.env,
    {
      TEST_APP_ID: envalid.num({
        desc:
          "The ID of the GitHub App used during tests." +
          " It must have at least the same permissions than the Autorebase GitHub App.",
      }),
      TEST_APP_PRIVATE_KEY: envalid.makeValidator(str => {
        const privateKeyFromEnv = isBase64(str)
          ? Buffer.from(str, "base64").toString("utf8")
          : str;
        if (
          /-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/m.test(
            privateKeyFromEnv,
          )
        ) {
          return privateKeyFromEnv;
        }
        throw new Error("invalid GitHub App RSA private key");
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
import {
  bool,
  cleanEnv,
  email,
  host,
  json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
import {
  bool,
  cleanEnv,
  email,
  host,
  json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
cleanEnv,
  email,
  host,
  json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
email,
  host,
  json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
host,
  json,
  port,
  num,
  str,
  url,
  type ValidatorSpec
} from 'envalid'

const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()

const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
  NODE_ENV: str()
})

// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()