richtypo-rules-en
TypeScript icon, indicating that this package has built-in type declarations

5.1.3 • Public • Published

Richtypo English Rule Package

Converts this:

The quick brown FOX - weighting 47 kg - jumps over "the lazy dog" on
sunny morning...

to this:

The quick brown <abbr>FOX</abbr>&#x202f;=&#x202f;weighting
47&nbsp;kg&#x202f;=&#x202f; jumps over “the lazy dog”
on&nbsp;sunny&nbsp;morning…

Note: &#x202f; is and HTML entity for a hair space.

Installation

npm install --save richtypo richtypo-rules-en

Basic usage

import richtypo from 'richtypo';
import rules from 'richtypo-rules-en';

const text =
  'The quick brown FOX - weighting 47 kg -' +
  'jumps over "the lazy dog" on sunny morning...';

richtypo(rules, text);

// -> The quick brown <abbr>FOX</abbr>&#x202f;=&#x202f;weighting 47&nbsp;kg&#x202f;=&#x202f;
//    jumps over “the lazy dog” on&nbsp;sunny&nbsp;morning…

The default export of richtypo-rules-en contains recommended rules (marked with ¹ in a table below), but you can import each rule separately:

import richtypo from 'richtypo';
import { quotes, numberSeparators } from 'richtypo-rules-en';
richtypo([quotes, numberSeparators], 'Text "in quotes" - 123456.78');
// -> Text “in quotes” - 123,456.78

See more examples in Richtypo docs.

The rules

| Rule | Description | Input | Output | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | abbrs¹ | wrap abbreviations in <abbr> tag | FOX | <abbr>FOX</abbr> | | amps | wrap ampersands (&) in <span class="amp"> tag | Dog & Cat | Dog <span class="amp">&</span> Cat | | dashes¹ | transform a dash between two words to an em dash (—), add a non-breaking space before an em dash | dog - friend | dog&nbsp;— friend² | | degreeSigns¹ | add a non-breaking space between a number and a degree sign (°) | 13 °C | 13&#x202f;°C | | ellipses¹ | transform three dots (...) to an ellipsis (…) | ... | | | hyphenatedWords¹ | wrap words with a hyphen in <nobr> tag | to-day | <nobr>to-day</nobr> | | numberUnits¹ | add a non-breaking space between a number and its unit | 2 kg | 2&nbsp;kg² | | numbers | adds thousands separators to large numbers and put ordinals within <sup> tags | 10000.123, 1st 2nd 3rd | 10,000.123, 1<sup>st</sup> 2<sup>nd</sup> 3<sup>rd</sup> | | orphans¹ | add a non-breaking space in front of the last word in a paragraph (line) | their worst dreams | their worst&nbsp;dreams² | | quotes¹ | transform dumb quotes (") to typography quotes («») | text "in quotes" | text «in quotes» | | shortWords¹ | add a non-breaking space after short words | my dogs | my&nbsp;dogs² |

¹ Recommended rules (see code examples above)

² &nbsp; is actually rendered as a symbol (\xA0), not an HTML entity. We use &nbsp; only in the docs for readability.

Readme

Keywords

none

Package Sidebar

Install

npm i richtypo-rules-en

Weekly Downloads

73

Version

5.1.3

License

MIT

Unpacked Size

8.16 kB

Total Files

5

Last publish

Collaborators

  • sapegin