Skip to content

LLM Resources

@structium/env - API documentation ​

Functions ​

deserialize() ​

ts
function deserialize<Res>(input: string): Promise<Res>

Deserialize an environment variable file content string into an object.

Type Parameters ​

Type ParameterDescription
Res extends EnvDataThe expected return type of the deserialized object

Parameters ​

ParameterTypeDescription
inputstringThe environment variable file content

Returns ​

Promise<Res>

  • A promise that resolves to the deserialized object

Throws ​

If the input string is not valid

Example ​

ts
const envContent = `
  NAME=Alice
  AGE=30
  CITY=New York
  COSTUMER=true
`

const obj = await deserialize( envContent )
console.log( obj )

serialize() ​

ts
function serialize<I>(input: I): Promise<string>

Serialize an object into an environment variable file content string.

Type Parameters ​

Type ParameterDescription
I extends EnvDataThe type of the object to serialize

Parameters ​

ParameterTypeDescription
inputIThe object containing environment variables

Returns ​

Promise<string>

  • A promise that resolves to the serialized .env string

Example ​

ts
const obj = {
NAME: 'Bob',
AGE: 25,
APP_URL: 'http://localhost:3000',
MESSAGE: 'Hello, World!\nThis is a multiline message.',
DEBUG_MODE: true // Los booleanos se convertirΓ‘n a 'true' o 'false'
}

const envString = await serialize( obj )
console.log( envString )