Transform blobs of text:
One
Two
Three Elephants walking.
Four tigers sleeping.
Into array structures using RegExp
identifiers:
[
{
"type": "section",
"title": "Example"
"lines": [
[ "One" ], [ "Two" ],
[ "Three ", { "type": "identifier", text: "Elephants", extra: "data"}, " walking."],
[ "Four tigers sleeping." ]
],
"extra": "data"
}
]
- Install:
npm install text-part --save
- Example: example.js
Kind: global class
Param | Type | Description |
---|---|---|
name | string |
The name to describe all text types which are processed by the TextPart instance. |
sections | Array.<(string|object)> |
An array of section identifiers. (RegExp/string) |
identifiers | Array.<(string|object)> |
An array of identifiers. (RegExp/string) |
config | Object |
Configuration options to define how TextPart transforms. |
Transform a file data string into an array of parts. The top level array represents the lines. The arrays, called parts, within each line represent parts within the line. Some parts are simple strings, others represent things such as identifiers.
Kind: instance method of TextPart
Param | Type | Description |
---|---|---|
text | string |
The text to transform into parts. |
Clear all added identifiers.
Kind: instance method of TextPart
Load an array of section identifiers.
Kind: instance method of TextPart
Param | Type | Description |
---|---|---|
sections | Array.<(RegExp|string)> |
An array of strings or RegExp to use as identifiers. |
Load an array of identifiers.
Kind: instance method of TextPart
Param | Type | Description |
---|---|---|
identifiers | Array.<(string|object)> |
An array of objects or strings to be loaded as identifiers. [ 'identifier1', { regex: 'identifier2', data: {} }, { regex: ['identifier3','identifier4'], data: {} } ] |
Add a section identifier. This is regex which will split the text blob when found.
Kind: instance method of TextPart
Param | Type | Description |
---|---|---|
identifier | RegExp | String |
The RegExp to use for identification. |
data | object |
Data to associate with the identifier and anything the identifier creates. |
config | object |
The config options to use. |
Kind: instance method of TextPart
Param | Type | Description |
---|---|---|
identifier | RegExp | String |
The RegExp to use for identification. |
data | object |
Data to associate with the identifier and anything the identifier creates. |
config | object |
The config options to use. |