0.0.8 • Published 3 years ago

@aibulat/json v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

JSON read file with types

If you are reading a json file, you might want to have a good intellisense help from the IDE, availability of types. That would make work easier compared to dealing with a plain Object. Here is the example, how you can achieve this.

Having user.json:

{
  "name": "Aibulat",
  "email": "aibulat@example.com",
  "position": "NodeJS Developer"
}
import { readJson } from "@aibulat/json";

interface User {
  name: string;
  email: string;
  position: string;
}

const data = await readJson<User>("user.json");

console.log(data.name);
console.log(data.email);
console.log(data.position);

Function Signature:

function readJson<T>(path: string): Promise<T>;
0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago