Skip to content

Commit

Permalink
add readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolguevara committed Jan 10, 2023
1 parent 02ea1ce commit 32ff255
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# envconfig

this library is based on
[envconfig](https://github.com/kelseyhightower/envconfig) for gloang

## marks

### types

```md
- `string
- `bool
- `number
- `date
```

### val

```md
- `required
- `max
- `min
```

### modifiers

```md
- `env
- `prefix
- `suffix
- `split_words
- `split_values
- `uppercase
- `lowercase
- `format
```

## Example

```typescript
const _envconfig = {
log: {
level: "`string`default:DEBUG",
},
server: {
hostname: "`string`default:0.0.0.0",
port: "`default:3003`number",
},
app: {
name: "`string`default:my-app",
description: "`string`default:my awesome app",
contact: "`string`default:~",
version: "`string`default:~",
},
db: {
type: "`string`default:memory",
createSchema: "`bool`split_words`default:true",
dropSchemaIfExists: "`bool`split_words`default:true",
shared: {
__prefix: "",
hostname: "`string",
port: "`number`default:-1",
user: "`string",
password: "`string",
database: "`string",
},
sqlite: {
path: "`string`default::memory:",
},
mysql: {
connectionLimit: "`number`split_words`default:4",
},
postgres: {
applicationName: "`string`split_words`default:deno-nostr",
connectionsAttemps: "`number`split_words`default:1",
hostType: "`string`split_words`default:tcp",
tlsEnforce: "`bool`split_words`default:false",
maxIndexKeys: "`string`default:32",
},
},
};

const e = parse({}, _envconfig);
/* {
log: { level: "DEBUG" },
server: { hostname: "0.0.0.0", port: 3003 },
app: {
name: "my-app",
description: "my awesome app",
contact: "~",
version: "~",
},
db: {
type: "memory",
createSchema: true,
dropSchemaIfExists: true,
shared: {
hostname: undefined,
port: -1,
user: undefined,
password: undefined,
database: undefined,
},
sqlite: { path: ":memory:" },
mysql: { connectionLimit: 4 },
postgres: {
applicationName: "my-app",
connectionsAttemps: 1,
hostType: "tcp",
tlsEnforce: false,
maxIndexKeys: "32",
},
},
} */
```
78 changes: 78 additions & 0 deletions src/envconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1451,4 +1451,82 @@ describe("complex marks", () => {

assertEquals(parsed.myapp.ignoredPrefix.sub, { p1: 1, p2: 2, p3: 3 });
});

it("should parse app config example", () => {
const _envconfig = {
log: {
level: "`string`default:DEBUG",
},
server: {
hostname: "`string`default:0.0.0.1",
port: "`default:3003`number",
},
app: {
name: "`string`default:my-app",
description: "`string`default:my awesome app",
contact: "`string`default:~",
version: "`string`default:~",
},
db: {
type: "`string`default:memory",
createSchema: "`bool`split_words`default:true",
dropSchemaIfExists: "`bool`split_words`default:true",
shared: {
__prefix: "",
hostname: "`string",
port: "`number`default:-1",
user: "`string",
password: "`string",
database: "`string",
},
sqlite: {
path: "`string`default::memory:",
},
mysql: {
connectionLimit: "`number`split_words`default:4",
},
postgres: {
applicationName: "`string`split_words`default:deno-nostr",
connectionsAttemps: "`number`split_words`default:1",
hostType: "`string`split_words`default:tcp",
tlsEnforce: "`bool`split_words`default:false",
maxIndexKeys: "`string`default:32",
},
},
};

const e = parse({}, _envconfig);

assertEquals(e, {
log: { level: "DEBUG" },
server: { hostname: "0.0.0.1", port: 3003 },
app: {
name: "my-app",
description: "my awesome app",
contact: "~",
version: "~",
},
db: {
type: "memory",
createSchema: true,
dropSchemaIfExists: true,
shared: {
hostname: undefined,
port: -1,
user: undefined,
password: undefined,
database: undefined,
},
sqlite: { path: ":memory:" },
mysql: { connectionLimit: 4 },
postgres: {
applicationName: "deno-nostr",
connectionsAttemps: 1,
hostType: "tcp",
tlsEnforce: false,
maxIndexKeys: "32",
},
},
});
});
});

0 comments on commit 32ff255

Please sign in to comment.