Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

n-gram

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

n-gram

Get n-grams from text

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
101K
increased by15.22%
Maintainers
2
Weekly downloads
 
Created
Source

n-gram

Build Coverage Downloads Size

Get n-grams.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install n-gram

Use

import {bigram, trigram, nGram} = require('n-gram')

bigram('n-gram') // ['n-', '-g', 'gr', 'ra', 'am']
nGram(2)('n-gram') // ['n-', '-g', 'gr', 'ra', 'am']

trigram('n-gram') // ['n-g', '-gr', 'gra', 'ram']

nGram(6)('n-gram') // ['n-gram']
nGram(7)('n-gram') // []

// Anything with a `.length` and `.slice` works: arrays too.
bigram(['alpha', 'bravo', 'charlie']) // [['alpha', 'bravo'], ['bravo', 'charlie']]

API

This package exports the following identifiers: ngram, bigram, and trigram. There is no default export.

nGram(n)

Create a function that converts a given value to n-grams.

Want padding? Use something like the following: nGram(2)(' ' + value + ' ');

bigram(value)

Shortcut for nGram(2).

trigram(value)

Shortcut for nGram(3).

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 25 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc