Skip to content

LaCocoRoco/ymlts

Repository files navigation

YAML to Typescript Generator

npm GitHub GitHub last commit

Command Line Interface to generate Typescript from YAML File. Combines and simplifies quicktype and js-yaml package.

General

Typing file extension for source and target files are optional.

Install & Usage Local

Install:  npm i -D ymlts

Usage  :  npx ymlts source [target] [flags]

Install & Usage Global

Install:  npm i -g ymlts

Usage  :  ymlts source [target] [flags]

Help

  usage : ymlts source [target] [flags]

  source: source file or folder to .yaml or .yml
  target: target file or folder to .d.ts or .ts file
  flags : -t  generate .ts instead of .d.ts
          -o  make all properties optional
          -m  merge all files into one
          -s  silent mode
          -h  show help message

CLI - Example File

  Example Environment
  cwd:    /source
  files:  /file.yaml
  usage:  ymlts file

  source: /source/file.yaml
  target: /source/file.d.ts
  usage:  ymlts /usr/file -t

  source: /usr/file.yaml
  target: /usr/file.ts
  usage:  ymlts file target

  source: /source/file.yaml
  target: /source/target.d.ts
  usage:  ymlts resource/file /usr/target

  source: /source/resource/file.yaml
  target: /usr/target.d.ts

CLI - Example Folder

  Example Environment
  cwd:    /source
  files:  /file.yaml
          /subfolder/file.yaml
  usage:  ymlts source

  source: /source/file.yaml
          /source/subfolder/file.yaml         
  target: /source/file.d.ts
          /source/subfolder/file.d.ts
  usage:  ymlts /usr

  source: /usr/file.yaml
          /usr/subfolder/file.yaml         
  target: /usr/file.d.ts
          /usr/subfolder/file.d.ts
  usage:  ymlts source target -t

  source: /source/file.yaml
          /source/subfolder/file.yaml         
  target: /target/file.ts
          /target/subfolder/file.ts
  usage:  ymlts source target/file -m

  source: /source/file.yaml
          /source/subfolder/file.yaml         
  target: /target/file.d.ts

Example - Input & Output

// source.yaml

description:
  title: Average Temperature
  units: Degrees Fahrenheit
data:
  temp:
    value: 50.00
    anomaly: 1.00
// target.ts

export interface Target {
    description: Description;
    data:        Data;
}

export interface Data {
    temp: Temp;
}

export interface Temp {
    value:   number;
    anomaly: number;
}

export interface Description {
    title:      string;
    units:      string;
}
// target.d.ts

interface Target {
    description: Description;
    data:        Data;
}

interface Data {
    temp: Temp;
}

interface Temp {
    value:   number;
    anomaly: number;
}

interface Description {
    title:      string;
    units:      string;
}

Issues

Quicktype merges matching types.

// source.yaml

description:
  title: Description Title
  name: Descritpion Name
book:
  title: Book Title
  name: Book Name
// target.d.ts

interface Source {
    description: Book;
    book:        Book;
}

interface Book {
    title: string;
    name:  string;
}

About

YAML to Typescript Generator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published