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).
Get it from NPM:
npm install interface-to-object
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);
[
{
"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"
}
]
}
]
{
"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
]
}
]
}
}