Skip to content

Formula to detect the grade level of text according to the (revised) Spache Readability Formula (1974)

License

Notifications You must be signed in to change notification settings

words/spache-formula

Repository files navigation

spache-formula

Build Coverage Downloads Size

Formula to detect the grade level of text according to the (revised) Spache readability formula.

Contents

What is this?

This package exposes an algorithm to detect ease of reading of English texts.

When should I use this?

You’re probably dealing with natural language, and know you need this, if you’re here!

This algorithm isn’t based on syllabbles compared to some other algorithms, which means it’s quicker to calculate.

See spache for a list of words which count as “known”.

Install

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

npm install spache-formula

In Deno with esm.sh:

import {spacheFormula} from 'https://esm.sh/spache-formula@2'

In browsers with esm.sh:

<script type="module">
  import {spacheFormula} from 'https://esm.sh/spache-formula@2?bundle'
</script>

Use

import {spacheFormula} from 'spache-formula'

spacheFormula({word: 30, sentence: 2, unfamiliarWord: 6}) // => 4.114

spacheFormula({word: 30, sentence: 2}) // => 2.474

spacheFormula() // => NaN

API

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

spacheFormula(counts)

Given the number of words (word), the number of sentences (sentence), and the number of unique unfamiliar words (unfamiliarWord) in a document, returns the grade level associated with the document.

counts

Counts from input document.

counts.sentence

Number of sentences (number, required).

counts.word

Number of words (number, required).

counts.unfamiliarWord

Number of unfamiliar words (number, default: 0).

Returns

Grade level associated with the document (number).

Types

This package is fully typed with TypeScript. It exports the additional type Counts.

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.

License

MIT © Titus Wormer