Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

wooorm/retext-syllable

Repository files navigation

retext-syllable Build Status Coverage Status

Count syllables with retext.

Installation

npm:

npm install retext-syllable

retext-syllable is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var retext = require('retext');
var inspect = require('unist-util-inspect');
var syllable = require('retext-syllable');

retext().use(syllable).use(function () {
    return function (cst) {
        console.log(inspect(cst));
    };
}).process('A yellow fresh banana.');

Yields:

RootNode[1] [data={"syllableCount":7}]
└─ ParagraphNode[1] [data={"syllableCount":7}]
   └─ SentenceNode[8] [data={"syllableCount":7}]
      ├─ WordNode[1] [data={"syllableCount":1}]
      │  └─ TextNode: 'A'
      ├─ WhiteSpaceNode: ' '
      ├─ WordNode[1] [data={"syllableCount":2}]
      │  └─ TextNode: 'yellow'
      ├─ WhiteSpaceNode: ' '
      ├─ WordNode[1] [data={"syllableCount":1}]
      │  └─ TextNode: 'fresh'
      ├─ WhiteSpaceNode: ' '
      ├─ WordNode[1] [data={"syllableCount":3}]
      │  └─ TextNode: 'banana'
      └─ PunctuationNode: '.'

API

None, retext-syllable automatically detects the syllables of each WordNode (using wooorm/syllable), and stores the count in node.data.syllableCount.

All parents (such as sentences, paragraphs, root) also receive a syllableCount property (parent.data.syllableCount).

License

MIT © Titus Wormer

About

Count syllables with Retext

Resources

License

Stars

Watchers

Forks

Packages

No packages published