1.2.0 • Published 1 year ago

life-config v1.2.0

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

life-config 🍃

Configuration on runtime.

Example

const lifeConfig = await LifeConfig.create(
  new FileSource<{ prefixLog: string }>("config.json"),
);

let logPrefix: string;

await lifeConfig.subscribe((state) => (logPrefix = state.logPrefix));

console.log(`${logPrefix} hello 1`); // => [log] hello 1
// echo '{ "logPrefix": "super-log" }' > config.json
console.log(`${logPrefix} hello 2`); // => [super-log] hello 2

Install

npm install life-config

Data Source

A data source describe how to load the new configurations describe it on source.ts.

The next sample subscribe changes on the source and connect it with nanostores.

// config.ts
import { atom } from "nanostores";

export const logLevel = atom("info");
lifeConfig.subscribe((state) => logLevel.set(state.logLevel));

File Source

A source to watch file and load on each change.

const lifeConfig = await LifeConfig.create(new FileSource("my-file.json"));

HTTP Source

A source to refresh the state if detect changes from a http resources.

const lifeConfig = await LifeConfig.create(
  new HTTPSource("http://localhost/config"),
);

Subscriptor Source

import { atom } from "nanostores";

const config = atom({ logLevel: "info" });

const lifeConfig = await LifeConfig.create(new SubscriptorSource(config));
1.2.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago