0.0.8 • Published 4 years ago

vizo-json-to-class v0.0.8

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

FSE

firestore-schema-exporter

oclif Version Downloads/week License

Usage

$ npm install -g vizo-json-to-class
$ json-to-class COMMAND
running command...
$ json-to-class (-v|--version|version)
vizo-json-to-class/0.0.4 win32-x64 node-v14.17.2
$ json-to-class --help [COMMAND]
USAGE
  $ json-to-class COMMAND
...

Options

  -f, --force
  -h, --help         show CLI help
  -v, --version      show CLI version
  --format=TS|JS     Format of the class
  --input=input      Path of a Json file that you want to convert to a class
  --logger=0|1|2     Level of logger
  --name=name        Class Name
  --output=output    Path of the File you want to output to the class
  --outputClass=0|1  if you want to create a file and show the class as output enter 1 , if you just want to create a file enter 0

Example

If we run the command with the above input:

{
  "name": "achinoam",
  "age": 20,
  "student": true,
  "language": [
    {
      "language1": [
        { "name": "English" },
        { "Level_of_knowledge": "Very good!" }
      ]
    },
    {
      "language2": [{ "name": "Hebrow" }, { "Level_of_knowledge": "Perfect!" }]
    }
  ]
}

We will get:

export class user {
    constructor(
    public name: string,
    public age: number,
    public student: boolean,
    public language: Array<{ [key: string]: Array<{ [key: string]: string }> }>)
    {}

    static fromFirestore(snap: any) {
         if (snap && snap.data.call) {
            return this.fromMap({ ...snap.data(), id: snap.id });
        }
    }

    static fromMap(map: any) {
        if (!map) return null;
        return new user( map.name, map.age, map.student, map.language,);
    }

    toMap() {
        return {
            name: this.name ?? null, age: this.age ?? null, student: this.student ?? null, language: this.language ?? null,
        }
    }
}
0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago