2.0.9 • Published 1 year ago

dotenv-caster v2.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

dotenv-caster

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

!IMPORTANT Be sure to use the latest version.

How to Use

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

STRING_SAMPLE=Hello
NUMBER_SAMPLE=0
BIGINT_SAMPLE=123456789
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 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);

examples showing the use

dotenv-caster-sample

Detail

Create an instance

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

//string | undefined -> string
const stringSample: string = dotenvCaster.castString(process.env.STRING_SAMPLE);

string | undefined → number

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

string | undefined → bigint

//string | undefined -> bigint
const bigIntSample: bigint = dotenvCaster.castBigInt(process.env.BIGINT_SAMPLE);

string | undefined → symbol

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

string | undefined → boolean

//string | undefined -> boolean
const booleanSample: boolean = dotenvCaster.castBoolean(process.env.BOOLEAN_SAMPLE);

string | undefined → null

//string | undefined -> null
const nullSample: null = dotenvCaster.castNull(process.env.NULL_SAMPLE);
2.0.7

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.1

1 year ago