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 🙏

© 2025 – Pkg Stats / Ryan Hefner

paraseg

v2.1.0

Published

Like `Intl.Segmenter`, but for paragraphs instead of graphemes/words/sentences

Downloads

7

Readme

paraseg

Build status Package status Downloads License

Like Intl.Segmenter, but for paragraphs instead of graphemes/words/sentences.

How do I install it?

If you're using npm:

npm i paraseg --save

Or if you just want the git repo:

git clone [email protected]:philbooth/paraseg.git

How do I use it?

import * as assert from 'node:assert';
import { ParagraphSegmenter } from 'paraseg';

const text = `The quick brown fox
jumps over the lazy dog.

How now brown cow?`;

const segmenter = new ParagraphSegmenter();
const paragraphs = [];

for (const paragraph of segmenter.segment(text)) {
  paragraphs.push(paragraph);
}

assert.equal(paragraphs.length, 2);
assert.equal(paragraphs[0].segment, 'The quick brown fox jumps\nover the lazy dog.\n\n');
assert.equal(paragraphs[1].segment, 'How now brown cow?');

Does it work with both Unix and Windows line endings?

Yes.

How do I specify custom paragraph separators?

Pass the separators option to the constructor. separators is an array of substring candidates to be matched as segmentation points.

import * as assert from 'node:assert';
import { ParagraphSegmenter } from 'paraseg';

const text = `The quick brown fox jumps over the lazy dog.
How now brown cow?`;

const segmenter = new ParagraphSegmenter({
  separators: ['\n'],
});
const paragraphs = [];

for (const paragraph of segmenter.segment(text)) {
  paragraphs.push(paragraph);
}

assert.equal(paragraphs.length, 2);
assert.equal(paragraphs[0].segment, 'The quick brown fox jumps over the lazy dog.\n');
assert.equal(paragraphs[1].segment, 'How now brown cow?');

How do I trim leading and trailing spaces from segmented paragraphs?

Pass the trim option to the constructor. trim is a boolean, set it to true if you want to remove spaces from the start and end of each paragraph.

import * as assert from 'node:assert';
import { ParagraphSegmenter } from 'paraseg';

const text = `  The quick brown fox
  jumps over the lazy dog.

  How now brown cow?  `;

const segmenter = new ParagraphSegmenter({ trim: true });
const paragraphs = [];

for (const paragraph of segmenter.segment(text)) {
  paragraphs.push(paragraph);
}

assert.equal(paragraphs.length, 2);
assert.equal(paragraphs[0].segment, 'The quick brown fox\n  jumps over the lazy dog.');
assert.equal(paragraphs[1].segment, 'How now brown cow?');

Can I save memory by only returning offset and length data for each segment?

Yes, pass the slim: true option to the constructor.

import * as assert from 'node:assert';
import { ParagraphSegmenter } from 'paraseg';

const text = `The quick brown fox
jumps over the lazy dog.

How now brown cow?`;

const segmenter = new ParagraphSegmenter({ slim: true });
const paragraphs = [];

for (const paragraph of segmenter.segment(text)) {
  paragraphs.push(paragraph);
}

assert.equal(paragraphs.length, 2);

assert.equal(Object.keys(paragraphs[0]).includes('segment'), false);
assert.equal(Object.keys(paragraphs[1]).includes('segment'), false);

assert.equal(paragraphs[0].offset, 0);
assert.equal(paragraphs[1].offset, text.indexOf('How now brown cow?'));

assert.equal(paragraphs[0].length, paragraphs[1].offset);
assert.equal(paragraphs[1].length, text.length - paragraphs[0].length);

Note that slim: true is mutually exclusive with the trim option.

Is there a change log?

Yes.

How do I set up the dev environment?

To compile TypeScript:

make build

To lint the code:

make lint

To run the tests:

make test

What versions of Node does it support?

Node versions 20 or greater are supported.

What license is it released under?

MIT.