Package Exports
- json-to-typed
- json-to-typed/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-to-typed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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.