words / syllable

Count syllables in an English word
https://words.github.io/syllable/
MIT License
227 stars 23 forks source link
count language natural syllable syllables

syllable

Build Coverage Downloads Size

Count syllables in an English word.

Contents

What is this?

This package estimates how many syllables are in an English word.

When should I use this?

Use this when you want to do fun things with natural language, like rhyming, detecting reading ease, etc.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install syllable

In Deno with esm.sh:

import {syllable} from 'https://esm.sh/syllable@5'

In browsers with esm.sh:

<script type="module">
  import {syllable} from 'https://esm.sh/syllable@5?bundle'
</script>

Use

import {syllable} from 'syllable'

syllable('syllable') // 3
syllable('unicorn') // 3
syllable('hi') // 1
syllable('hihi') // 2
syllable('mmmmmmmmmmmmmmmm') // 1
syllable('wine') // 1
syllable('bottle') // 2
syllable('wine-bottle') // 3
syllable('Åland') // 2

API

This package exports the identifier syllable. There is no default export.

syllable(value)

Get the number of syllables in value.

value

Value to check (string, required).

Returns

Syllables in value (number).

CLI

Usage: syllable [options] <words...>

Count syllables in English words

Options:

  -h, --help           output usage information
  -v, --version        output version number

Usage:

# output syllables
$ syllable syllable unicorn
# 6

# output syllables from stdin
$ echo "syllable unicorn banana" | syllable
# 9

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Related

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

Notice

Based on the syllable functionality found in Text-Statistics (PHP), in turn inspired by Lingua::EN::Syllable (Perl).

Support for word-breaks, non-ASCII characters, and many fixes added later.

License

MIT © Titus Wormer