dotenv-caster
    Preparing search index...

    Class DotEnvCaster

    The DotEnvCaster class is a utility for casting environment variables to specific types.

    Yuki Osada r.rstudio.c@gmail.com

    Index

    Constructors

    • Creates the instance of DotEnvCaster.

      Returns DotEnvCaster

      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

    Methods

    • Casts a bigint | undefined constant to a bigint.

      Parameters

      • constant: string

        The constant to be cast.

      Returns bigint

      • The casted bigint.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> bigint
      const bigIntSample: bigint = dotenvCaster.castBigInt(process.env.BIGINT_SAMPLE);
    • Casts a boolean | undefined constant to a boolean.

      Parameters

      • constant: string

        The constant to be cast.

      Returns boolean

      • The casted boolean.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> boolean
      const booleanSample: boolean = dotenvCaster.castBoolean(process.env.BOOLEAN_SAMPLE);
    • Casts a null | undefined constant to a null.

      Parameters

      • constant: string

        The constant to be cast.

      Returns null

      • The casted null.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> null
      const nullSample: null = dotenvCaster.castNull(process.env.NULL_SAMPLE);
    • Casts a number | undefined constant to a number.

      Parameters

      • constant: string

        The constant to be cast.

      Returns number

      • The casted number.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> number
      const numberSample: number = dotenvCaster.castNumber(process.env.NUMBER_SAMPLE);
    • Casts a string | undefined constant to a string.

      Parameters

      • constant: string

        The constant to be cast.

      Returns string

      • The casted string.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> string
      const stringSample: string = dotenvCaster.castString(process.env.STRING_SAMPLE);
    • Casts a symbol | undefined constant to a symbol.

      Parameters

      • constant: string

        The constant to be cast.

      Returns symbol

      • The casted symbol.
      • If the constant is undefined, the error is thrown.
      import * as dotenv from 'dotenv';
      // Import dotenv-caster
      import { DotEnvCaster } from 'dotenv-caster';

      dotenv.config();

      // Create an instance
      const dotenvCaster = new DotEnvCaster();

      // string | undefined -> symbol
      const symbolSample: symbol = dotenvCaster.castSymbol(process.env.SYMBOL_SAMPLE);