JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8825
  • Score
    100M100P100Q152435F
  • License MIT

Fastest JavaScript implementation of the porter2 stemmer

Package Exports

  • porter2
  • porter2/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (porter2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

porter2   npm CI

Fast JavaScript implementation of the porter2 English stemming algorithm.

$ npm install porter2

Usage

The package is simple: it has no dependencies and exports a single function named stem.

Import using CommonJS:

const { stem } = require('porter2')

Or, import using EcmaScript Modules (through interoperability with CommonJS):

import { stem } from 'porter2'

Use the stemmer:

const word = stem('animadversion')
console.log(word) //=> animadvers

This stemmer expects a lowercase English word.

The code is compatible with ES5. TypeScript type declarations are included.

Benchmarks

On my machine, the 29.4k test suite executes in 5.25ms (5.6M/s throughput) in a hot loop (~31ms for the first run).

Here is a comparison with some other libraries (you probably should take it with a little grain of salt):

library throughput (node) throughput (bun)
porter2 1.0.3 5621 kops/s 6780 kops/s
stemr 1.0.0 840 kops/s 920 kops/s
wink-porter2-stemmer [^1] 2.0.1 340 kops/s 420 kops/s

Here are libraries that implement the older porter version 1 (note the behavior is not identical):

library throughput (node) throughput (bun)
porter-stemmer-js [^2] 1.1.2 3280 kops/s 3373 kops/s
stemmer [^3] 2.0.1 2100 kops/s 1549 kops/s
@stdlib/nlp-porter-stemmer 0.2.2 1712 kops/s 1604 kops/s
porter-stemmer 0.9.1 951 kops/s 1264 kops/s

The benchmark code is in bench/run.mjs. This was tested with Node.js v22.14.0 and bun v1.2.10 on Zen 3 (4.5 GHz boosted).

[^1]: wink-porter2-stemmer is 99.97% porter2 compliant (fails on ' cases only)

[^2]: That one has similar goals and, surprisingly, was published just 3 days before this package! (And after the author started working on porter2.js.)

[^3]: ESM only