5.1.3 • Published 7 months ago

richtypo-rules-en v5.1.3

Weekly downloads
13
License
MIT
Repository
-
Last release
7 months ago

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

RuleDescriptionInputOutput
abbrs¹wrap abbreviations in <abbr> tagFOX<abbr>FOX</abbr>
ampswrap ampersands (&) in <span class="amp"> tagDog & CatDog <span class="amp">&</span> Cat
dashes¹transform a dash between two words to an em dash (—), add a non-breaking space before an em dashdog - frienddog&nbsp;— friend²
degreeSigns¹add a non-breaking space between a number and a degree sign (°)13 °C13&#x202f;°C
ellipses¹transform three dots (...) to an ellipsis (…)...
hyphenatedWords¹wrap words with a hyphen in <nobr> tagto-day<nobr>to-day</nobr>
numberUnits¹add a non-breaking space between a number and its unit2 kg2&nbsp;kg²
numbersadds thousands separators to large numbers and put ordinals within <sup> tags10000.123, 1st 2nd 3rd10,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 dreamstheir worst&nbsp;dreams²quotes¹transform dumb quotes (") to typography quotes («»)text "in quotes"text «in quotes»
shortWords¹add a non-breaking space after short wordsmy dogsmy&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.

5.1.3

7 months ago

5.1.2

7 months ago

5.1.1

7 months ago

5.1.0

7 months ago

5.0.1

7 months ago

5.0.0

7 months ago

4.0.25

8 months ago

4.0.24

8 months ago

4.0.23

1 year ago

4.0.22

1 year ago

4.0.19

1 year ago

4.0.21

1 year ago

4.0.20

1 year ago

4.0.18

2 years ago

4.0.16

2 years ago

4.0.17

2 years ago

4.0.15

2 years ago

4.0.14

2 years ago

4.0.10

3 years ago

4.0.12

3 years ago

4.0.11

3 years ago

4.0.13

3 years ago

4.0.9

3 years ago

4.0.7

4 years ago

4.0.5

4 years ago

4.0.6

4 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

1.0.0-beta.0

5 years ago