dotenv-caster
    Preparing search index...

    dotenv-caster

    dotenv-caster

    Test Docs NPM Version GitHub Release NPM Type Definitions Download NPM NPM Downloads All Time GitHub License Vitest Typedoc RenovateBot

    dotenv-caster is a tiny package that converts string | undefined to certain primitive types.

    Warning

    A critical bug has been discovered in this package in versions 2.2.0 and below.

    Please ensure that you are using the latest version (at least v2.2.1 or newer) when using this package.

    Important

    Be sure to use the latest version.

    https://myxogastria0808.github.io/dotenv-caster/

    https://myxogastria0808.github.io/dotenv-caster/coverage/

    https://myxogastria0808.github.io/dotenv-caster/html/

    Warning

    The accuracy of the contents of generated deepwiki has not been verified by me.

    I recommend that you look at the documentation at typedoc.

    https://deepwiki.com/Myxogastria0808/dotenv-caster/

    This is an example of use if the following is written in .env.

    STRING_SAMPLE=Hello
    NUMBER_SAMPLE=0
    BIGINT_SAMPLE=1234567890123456789012345678901234567890
    SYMBOL_SAMPLE=SYMBOL
    BOOLEAN_SAMPLE=true
    NULL_SAMPLE=null
    
    

    The following is an example of use. dotenv-caster is intended for use in projects that use dotenv.

    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);
    // string | undefined -> number
    const numberSample: number = dotenvCaster.castNumber(process.env.NUMBER_SAMPLE);
    // string | undefined -> bigint
    const bigIntSample: bigint = dotenvCaster.castBigInt(process.env.BIGINT_SAMPLE);
    // string | undefined -> symbol
    const symbolSample: symbol = dotenvCaster.castSymbol(process.env.SYMBOL_SAMPLE);
    // string | undefined -> boolean
    const booleanSample: boolean = dotenvCaster.castBoolean(process.env.BOOLEAN_SAMPLE);
    // string | undefined -> null
    const nullSample: null = dotenvCaster.castNull(process.env.NULL_SAMPLE);

    When using dotenv-caster, first import dotenv-caster and create an instance as follows.

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

    // Create an instance
    const dotenvCaster = new DotEnvCaster();
    // string | undefined -> string
    const stringSample: string = dotenvCaster.castString(process.env.STRING_SAMPLE);
    // string | undefined -> number
    const numberSample: number = dotenvCaster.castNumber(process.env.NUMBER_SAMPLE);
    // string | undefined -> bigint
    const bigIntSample: bigint = dotenvCaster.castBigInt(process.env.BIGINT_SAMPLE);
    // string | undefined -> symbol
    const symbolSample: symbol = dotenvCaster.castSymbol(process.env.SYMBOL_SAMPLE);
    // string | undefined -> boolean
    const booleanSample: boolean = dotenvCaster.castBoolean(process.env.BOOLEAN_SAMPLE);
    // string | undefined -> null
    const nullSample: null = dotenvCaster.castNull(process.env.NULL_SAMPLE);