interface-to-object
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Interface To Object

Small package to get an "interface" object inflated (recursively extending the interface to extend) and populated (recursively extending the interface's parameters as an object).

Installation

Get it from NPM:

npm install interface-to-object

Usage

import {getInterfacesAsObject} from 'interface-to-object';

You can then use this function to get the "interface" as an object (input and output below).

const output = getInterfacesAsObject(input);

Example

Input

[
  {
    "name": "SimpleInterface1",
    "type": "string",
    "values": [
      "valueA",
      "valueB",
      "valueC"
    ]
  },
  {
    "name": "SimpleInterface2",
    "type": "number",
    "values": [
      1,
      2,
      3
    ]
  },
  {
    "name": "SimpleInterface3",
    "type": "boolean",
    "default": true
  },
  {
    "name": "ComplexeInterface1",
    "parameters": [
      {
        "name": "param1",
        "interface": "SimpleInterface1"
      },
      {
        "name": "param2",
        "interface": "SimpleInterface2"
      },
      {
        "name": "param3",
        "interface": "SimpleInterface3"
      }
    ]
  },
  {
    "name": "ComplexeInterface2",
    "parameters": [
      {
        "name": "param1",
        "type": "string",
        "values": [
          "hello",
          "world"
        ],
        "default": "hello",
        "required": true
      },
      {
        "name": "param2",
        "interface": "SimpleInterface1"
      },
      {
        "name": "param3",
        "interface": "SimpleInterface2"
      }
    ]
  },
  {
    "name": "ComplexeInterface3",
    "extends": {
      "name": "ComplexeInterface2",
      "required": true
    },
    "parameters": [
      {
        "name": "param1",
        "interface": "SimpleInterface2"
      }
    ]
  },
  {
    "name": "ComplexeInterface4",
    "extends": {
      "name": "ComplexeInterface3",
      "required": true
    },
    "parameters": [
      {
        "name": "param1",
        "interface": "ComplexeInterface1"
      }
    ]
  }
]

Output

{
  "SimpleInterface1": {
    "name": "SimpleInterface1",
    "type": "string",
    "values": [
      "valueA",
      "valueB",
      "valueC"
    ]
  },
  "SimpleInterface2": {
    "name": "SimpleInterface2",
    "type": "number",
    "values": [
      1,
      2,
      3
    ]
  },
  "SimpleInterface3": {
    "name": "SimpleInterface3",
    "type": "boolean",
    "default": true
  },
  "ComplexeInterface1": {
    "name": "ComplexeInterface1",
    "type": "string",
    "parameters": [
      {
        "name": "param1",
        "required": false,
        "type": "string",
        "values": [
          "valueA",
          "valueB",
          "valueC"
        ]
      },
      {
        "name": "param2",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      },
      {
        "name": "param3",
        "required": false,
        "type": "string"
      }
    ]
  },
  "ComplexeInterface2": {
    "name": "ComplexeInterface2",
    "type": "string",
    "parameters": [
      {
        "name": "param1",
        "required": true,
        "type": "string",
        "values": [
          "hello",
          "world"
        ],
        "default": "hello"
      },
      {
        "name": "param2",
        "required": false,
        "type": "string",
        "values": [
          "valueA",
          "valueB",
          "valueC"
        ]
      },
      {
        "name": "param3",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      }
    ]
  },
  "ComplexeInterface3": {
    "name": "ComplexeInterface3",
    "type": "string",
    "parameters": [
      {
        "name": "param1",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      },
      {
        "name": "param1",
        "required": true,
        "type": "string",
        "values": [
          "hello",
          "world"
        ],
        "default": "hello"
      },
      {
        "name": "param2",
        "required": false,
        "type": "string",
        "values": [
          "valueA",
          "valueB",
          "valueC"
        ]
      },
      {
        "name": "param3",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      }
    ]
  },
  "ComplexeInterface4": {
    "name": "ComplexeInterface4",
    "type": "string",
    "parameters": [
      {
        "name": "param1",
        "required": false,
        "type": "string",
        "values": [
          {
            "name": "param1",
            "required": false,
            "type": "string",
            "values": [
              "valueA",
              "valueB",
              "valueC"
            ]
          },
          {
            "name": "param2",
            "required": false,
            "type": "string",
            "values": [
              1,
              2,
              3
            ]
          },
          {
            "name": "param3",
            "required": false,
            "type": "string"
          }
        ]
      },
      {
        "name": "param1",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      },
      {
        "name": "param1",
        "required": true,
        "type": "string",
        "values": [
          "hello",
          "world"
        ],
        "default": "hello"
      },
      {
        "name": "param2",
        "required": false,
        "type": "string",
        "values": [
          "valueA",
          "valueB",
          "valueC"
        ]
      },
      {
        "name": "param3",
        "required": false,
        "type": "string",
        "values": [
          1,
          2,
          3
        ]
      }
    ]
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i interface-to-object

Weekly Downloads

0

Version

1.3.1

License

ISC

Unpacked Size

48.1 kB

Total Files

45

Last publish

Collaborators

  • mrwormsy