1.1.4 • Published 7 years ago

text-part v1.1.4

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

TextPart

Synopsis

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"
  }
]

Usage:

  • Install: npm install text-part --save
  • Example: example.js

Kind: global class

new TextPart(name, sections, identifiers, config)

ParamTypeDescription
namestringThe name to describe all text types which are processed by the TextPart instance.
sectionsArray.<(string|object)>An array of section identifiers. (RegExp/string)
identifiersArray.<(string|object)>An array of identifiers. (RegExp/string)
configObjectConfiguration options to define how TextPart transforms.

textPart.transform(text) ⇒ Array.<(object|Array.<(string|object)>)>

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

ParamTypeDescription
textstringThe text to transform into parts.

textPart.clearRules()

Clear all added identifiers.

Kind: instance method of TextPart

textPart.loadSections(sections)

Load an array of section identifiers.

Kind: instance method of TextPart

ParamTypeDescription
sectionsArray.<(RegExp|string)>An array of strings or RegExp to use as identifiers.

textPart.loadIdentifiers(identifiers)

Load an array of identifiers.

Kind: instance method of TextPart

ParamTypeDescription
identifiersArray.<(string|object)>An array of objects or strings to be loaded as identifiers. [ 'identifier1', { regex: 'identifier2', data: {} }, { regex: 'identifier3','identifier4', data: {} } ]

textPart.addSectionIdentifier(identifier, data, config)

Add a section identifier. This is regex which will split the text blob when found.

Kind: instance method of TextPart

ParamTypeDescription
identifierRegExp | StringThe RegExp to use for identification.
dataobjectData to associate with the identifier and anything the identifier creates.
configobjectThe config options to use.

textPart.addIdentifier(identifier, data, config)

Kind: instance method of TextPart

ParamTypeDescription
identifierRegExp | StringThe RegExp to use for identification.
dataobjectData to associate with the identifier and anything the identifier creates.
configobjectThe config options to use.
1.1.4

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago