npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

text-part

v1.1.4

Published

Parse blobs of text into sections, lines, and identifiers.

Downloads

2

Readme

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)

| 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. |

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

| Param | Type | Description | | --- | --- | --- | | text | string | The 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

| Param | Type | Description | | --- | --- | --- | | sections | Array.<(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

| 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: {} } ] |

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

| 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. |

textPart.addIdentifier(identifier, data, config)

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. |