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<TestContext> => {
  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<TestContext> => {
  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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = 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<boolean> = bool()
const numberValidatorSpec: ValidatorSpec<number> = num()
const stringValidatorSpec: ValidatorSpec<string> = str()
const jsonValidatorSpec: ValidatorSpec<any> = json()
const urlValidatorSpec: ValidatorSpec<string> = url()
const emailValidatorSpec: ValidatorSpec<string> = email()
const hostValidatorSpec: ValidatorSpec<string> = host()
const portValidatorSpec: ValidatorSpec<number> = 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<number> = bool()

envalid

Validation for your environment variables

MIT
Latest version published 8 months ago

Package Health Score

76 / 100
Full package analysis

Popular JavaScript code snippets

Find secure code to use in your application or website