@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 Parameter | Description |
|---|---|
Res extends EnvData | The expected return type of the deserialized object |
Parameters β
| Parameter | Type | Description |
|---|---|---|
input | string | The 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 Parameter | Description |
|---|---|
I extends EnvData | The type of the object to serialize |
Parameters β
| Parameter | Type | Description |
|---|---|---|
input | I | The 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 )