json-to-typed
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

json-to-typed

Exposes the TypedJsonFile class that allows you to read and write JSON files with type safety using the to-typed package.

async function run() {
	const file = await new TypedJsonFile('./settings.json', Convert.to({
		port: 3000,
		host: 'localhost'
	}));

	const data = await file.read();
	console.log(`Current address is http://${data.host}:${data.port}`);

	await file.write({ 
		port: data.port + 1,
		host: data.host
	});
}

It also includes a cli utility that generates a TypedJsonFile class for for each JSON file in a directory.

npx json-to-typed gen ./settings.json ./src/settings.ts

Requires ES modules.

Package Sidebar

Install

npm i json-to-typed

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

12.2 kB

Total Files

8

Last publish

Collaborators

  • jsoldi