5.1.3 • Published 7 months ago

richtypo-rules-common v5.1.3

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

Richtypo common typography rules

A convenience package to create Richtypo typography rules for different languages.

It includes definitions, rules and rule factories.

Definitions

Use definitions to improve readability of your rules:

import { definitions } from 'richtypo-common-rules';
const { space, nbsp } = definitions;
export const numberSigns = text =>
  text.replace(new RegExp(`№${space}`, 'g'), `№${nbsp}`);
Definition nameDescription
dashhyphen (-) or em dash (—)
hairspacenarrow non-breaking space (\u202f).
letterany European or Cyrillic letter
letterOrQuoteany European or Cyrillic letter with quotes
nbspnon-breaking space
notInTagnegative lookbehind to make sure we're not running rules inside an HTML tag. It’s usually added to the beginning of RegExp in most rules
openingQuoteany opening quote
punctuationpunctuation symbols
quoteany quotes
semicolona semicolon
shortWorda word of one or two letters
spaceany space (except \n)
tagmatches any HTML tag
upperLetterany uppercase European or Cyrillic letter

Rules

Rules are available as named exports:

import { abbrs } from 'richtypo-common-rules';
Rule nameDescriptionInputOutput
abbrswrap abbreviations in <abbr> tagsONU<abbr>ONU</abbr>
ampswrap an ampersand (&) in <span class="amp"> tagsCie & SonsCie <span class="amp">&</span> Sons
dashesreplace the hyphen character with a em dash and add non-breaking spaces when it makes sense.- Hello—&nbsp;Hello²
degreeSignsadd a hair space between numbers and degree symbol34 ° or 34°34&#x202f;°
ellipsesreplace three consecutive dots with an ellipsisoh...oh…
numberUnitsinsert non-breaking space between numbers and the following word100 km100&nbsp;km²
orphansadd a non-breaking space to avoid orphansWe go to the mallWe go to the&nbsp;mall²
shortWordsadd a non-breaking space after short wordsWe go to the mallWe&nbsp;go&nbsp;to&nbsp;the mall²

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

Rule factories

Use factory rules to customize some common rules, like quotes, for your language. For example, quotes in English are written as “” while in French they are written as «».

import { quotesFactory } from 'richtypo-rules-common';
export const quotes = quotesFactory({
  openingQuote: '«',
  closingQuote: '»'
});
RuleArgumentsDescription
numberOrdinalsFactory{ ordinal }format 1st, 2nd, 3rd etc. into 1st, 2nd, 3rd. ordinal should be a regex array of strings such as '(st | nd | rd | th)'.
numberSeparatorsFactory{ decimalsSeparator, thousandsSeparator }format numbers with thousands separator
quotesFactory{ openingQuote, closingQuote }replace dumb quotes with typography quotes
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.1.17

8 months ago

4.1.18

8 months ago

4.1.16

1 year ago

4.1.15

1 year ago

4.1.12

1 year ago

4.1.13

1 year ago

4.1.14

1 year ago

4.1.11

2 years ago

4.1.9

2 years ago

4.1.10

2 years ago

4.1.8

2 years ago

4.1.7

2 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.6

3 years ago

4.1.5

3 years ago

4.1.2

3 years ago

4.1.0

4 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