new Segment(name)
- Description:
- A Segment is a collection of Fields.
- Source:
Example
const segment = new Segment("ST");
Parameters:
Name |
Type |
Description |
name |
String
|
The name of the Segment, or the segment identifier. |
Methods
(static) addField(field) → {Segment}
- Description:
- Adds a Field to the Segment.
- Source:
Example
segment.addField(new Field("ST"));
console.log(segment.fields);
// [
// {
// content: "ST",
// },
// ]
Parameters:
Name |
Type |
Description |
field |
Field
|
The Field to add. |
Returns:
-
Type
-
Segment
(static) getFields() → {Array.<Field>}
- Description:
- Returns the Fields in the Segment.
- Source:
Example
const fields = segment.getFields();
console.log(fields);
// [
// {
// content: "ST",
// },
// {
// content: "997",
// },
// {
// content: "0001",
// },
// ]
Returns:
-
Type
-
Array.<Field>
(static) removeField(field) → {Segment}
- Description:
- Removes a Field from the Segment.
- Source:
Example
segment.removeField(segment.fields[0]);
console.log(segment.fields);
// []
Parameters:
Name |
Type |
Description |
field |
Field
|
The Field to remove. |
Returns:
-
Type
-
Segment
(static) toJSON() → {Object}
- Description:
- Returns a JSON representation of the Segment.
- Source:
Example
const json = segment.toJSON();
console.log(json);
// {
// name: "ST",
// fields: [
// {
// content: "ST",
// },
// {
// content: "997",
// },
// {
// content: "0001",
// },
// ],
// }
Returns:
-
Type
-
Object
(static) trimFields() → {Segment}
- Description:
- Removes whitespace from each Field in the Segment.
- Source:
Example
segment.trimFields();
console.log(segment.fields[0].content);
// "ST"
console.log(segment.fields[1].content);
// "997"
Returns:
-
Type
-
Segment