# Module: Component

A component is a template for nodes. They represent the structure of the component.

A component consists of a `componentId` and is an atomic or a compound node. It must have a valid semver version and a list of ports (each component must have at least one port).

    {
      componentId: 'componentIdentifier',
      version: "1.0.0",
      atomic: true,
      ports: [{port: 'in', kind: 'input', type: 'Number'},{port: 'out', kind: 'output', type: 'Number'}]
    }

Accessible via `require('@buggyorg/graphtools').Component`

Source:
  - component.js, line 1

### Methods

#### (static) createNode(reference, comp) → {Node}

Create a node from a component.

##### Parameters:

Name | Type | Description
--- | --- | ---
`reference` | Reference | The reference to the component.
`comp` | Component | The component that is the basis for the new node.

Source:
  - component.js, line 169

##### Returns:

A node with the given name representing the component.

Type
  Node

#### (static) id() → {string}

Returns the unique identifier of a node

Source:
  - component.js, line 39

##### Throws:

If the node value is invalid.

Type
  Error

##### Returns:

The unique identifier of the node

Type
  string

#### (static) inputPorts(comp) → {Array.<Port>}

Gets all input ports of the component.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp` | Component | The component.

Source:
  - component.js, line 90

##### Returns:

A possibly empty list of input ports.

Type
  Array.<Port>

#### (static) isValid(comp) → {boolean}

Checks whether a component is in a valid format, i.e. if it has an id field and at least one port.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp` | Component | The component to test.

Source:
  - component.js, line 132

##### Returns:

True if the component is valid, false otherwise.

Type
  boolean

#### (static) outputPorts(comp) → {Array.<Port>}

Gets all output ports of the comp.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp` | Component | The node.

Source:
  - component.js, line 77

##### Returns:

A possibly empty list of output ports.

Type
  Array.<Port>

#### (static) ports(comp) → {Array.<Port>}

Gets all ports of the component.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp` | Component | The component.

Source:
  - component.js, line 68

##### Returns:

A list of ports.

Type
  Array.<Port>

#### (inner) equal(comp1, comp2) → {boolean}

Tests whether two components are the same component. This tests only if their component IDs are the same not if both components contain the same information.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp1` | Component | One of the components to test.
`comp2` | Component | The other one.

Source:
  - component.js, line 50

##### Returns:

True if they have the same id, false otherwise.

Type
  boolean

#### (inner) hasPort(name, comp) → {Port}

Checks whether the component has the specific port.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the port.
`comp` | Component | The component which has the port.

Source:
  - component.js, line 115

##### Returns:

True if the port has a port with the given name, false otherwise.

Type
  Port

#### (inner) port(comp, name) → {Port}

Returns the port data for a given port.

##### Parameters:

Name | Type | Description
--- | --- | ---
`comp` | Component | The component which has the port.
`name` | String | The name of the port.

Source:
  - component.js, line 98

##### Throws:

If no port with the given name exists in this component an error is thrown.

Type
  Error

##### Returns:

The port data.

Type
  Port