npm.io
2.0.0 • Published 3d ago

fullwidth-quotes

Licence
MIT
Version
2.0.0
Deps
1
Size
35 kB
Vulns
0
Weekly
0

fullwidth-quotes

npm GitHub License: MIT

According to the given locale and Unicode Standardized Variation Sequence (SVS), convert CJK quotation marks to fullwidth, and convert Mongolian quotation marks to Sibe form.

  • In Unicode 16.0, it supports fullwidth quotation marks with variation selectors.
  • In Unicode 17.0, it supports Sibe form quotation marks with variation selectors.
Character Unicode Name
“︀ U+201C U+FE00 Halfwidth Left Double Quotation Mark
”︀ U+201D U+FE00 Halfwidth Right Double Quotation Mark
‘︀ U+2018 U+FE00 Halfwidth Left Single Quotation Mark
’︀ U+2019 U+FE00 Halfwidth Right Single Quotation Mark
“︁ U+201C U+FE01 Fullwidth Left Double Quotation Mark
”︁ U+201D U+FE01 Fullwidth Right Double Quotation Mark
‘︁ U+2018 U+FE01 Fullwidth Left Single Quotation Mark
’︁ U+2019 U+FE01 Fullwidth Right Single Quotation Mark
“︂ U+201C U+FE02 Sibe Form Left Double Quotation Mark
”︂ U+201D U+FE02 Sibe Form Right Double Quotation Mark
‘︂ U+2018 U+FE02 Sibe Form Left Single Quotation Mark
’︂ U+2019 U+FE02 Sibe Form Right Single Quotation Mark

This library will help you to add variant selectors for quotation marks automatically.

It only effects on smart quotation marks (curly quotation marks) and will not have any effects on dumb quotation marks (straight quotation marks).

This requires font support, otherwise you won't be able to see the difference among them. However, you can use Yozora Sans if you cannot find a suitable font.

Why use it?

It is hard to input Unicode Variant Selectors directly on the keyboard, and currently (2026) there are almost no input methods that support these variation sequences. Just like other English programmers like to use -> to replace and use `` to replace , through simplified input operations and automatic conversion to standard Unicode characters by using post production automation tools. This library aims to provide people with a modern input experience while safeguarding the legitimacy of text.

What is Sibe Form?

Sibe (aka Xibe or Xibo) script is a vertical writing system still in use, which was improved on the basis of Manchu script in 1947, and Manchu script originated from Mongolian script in the 13th century. All the three share the same glyph structure, stroke rules, and writing direction, so Sibe script and Mongolian script are visually highly similar, but not directly derived. This library automatically optimizes punctuation and symbol input in Sibe text by recognizing Mongolian characters in this writing system, improving writing standardization.

The characteristic of Sibe quotation marks is that when writing text vertically, the quotation marks will remain upright instead of turning sideways like other halfwidth characters, and will remain centered horizontally and vertically within the line.

Installation

# npm
npm install fullwidth-quotes

# yarn
yarn add fullwidth-quotes

# pnpm
pnpm add fullwidth-quotes

Usage

import { enableSvsQuotes } from "fullwidth-quotes";
enableSvsQuotes("“Hello world!”"); // Add U+FE00 after the `“` and `”` characters.
enableSvsQuotes("“Hello world!”", { locale: "zh-CN" }); // Convert only Chinese and Japanese to fullwidth quotes.
enableSvsQuotes("“Hello world!”", { force: "fullwidth" }); // Always convert all quotation marks in the string to fullwidth, regardless of the context characters.
enableSvsQuotes("“Hello world!”", { ambiguousForHalfwidth: true }); // The halfwidth quotation marks will be replaced with the ambiguous plain quotation mark characters.

import { LEFT_DOUBLE_QUOTE_FULLWIDTH, RIGHT_DOUBLE_QUOTE_FULLWIDTH } from "fullwidth-quotes/chars";
// You can also directly get the samples of these characters.

API

enableSvsQuotes

According to Unicode Standardized Variation Sequence (SVS), convert CJK quotation marks to fullwidth, and convert Mongolian quotation marks to Sibe form.

If the quotation marks enclose the context of Chinese or Japanese (excluding Korean), switch them to to fullwidth form. If no Chinese or Japanese are present but Mongolian letters are detected, switch to Sibe form. In all other cases, use halfwidth form.

Options / Overloaded Type Definition
function enableSvsQuotes(
	str: string,
	options?: {
		locale?: Intl.UnicodeBCP47LocaleIdentifier | Intl.Locale;
		ambiguousForHalfwidth?: boolean;
	},
): string;
locale

If locale option is provided, the return behavior of the function will be changed:

  • If the script of the locale is "Hani", "Hans", "Hant", or "Jpan", then switch the quotation marks to fullwidth.
  • If the script of the locale is "Mong" or the language of the locale is "sjo", "xb", "mnc", or "mn", then switch the quotation marks to Sibe form.
  • Otherwise, switch the quotation marks to halfwidth.

Cannot use it with force option together.

ambiguousForHalfwidth

If the return quotes are expected to be halfwidth, the ambiguous plain quote characters will be returned instead.

Default: false


function enableSvsQuotes(
	str: string,
	options?: {
		force?: QuoteType;
		includesExplicit?: boolean;
	},
): string;

type QuoteType = "halfwidth" | "fullwidth" | "sibe" | "ambiguous";
force

Force the quotation marks type to be the expected form, regardless of the context.

  • "fullwidth": Always convert all quotation marks in the string to fullwidth.
  • "halfwidth": Always convert all quotation marks in the string to halfwidth.
  • "sibe": Always convert all quotation marks in the string to Sibe form.
  • "ambiguous": Remove the variation selectors from all quotation marks to restore them to ambiguous pure characters. Same as disableSvsQuotes().

Cannot use it with locale option together.

includesExplicit

If a quotation mark already contains any variation selector, should it be ignored and replaced?

In the parameters, you can decide whether to ignore and replace any variation selector if a quotation mark already contain it.

Default: false


disableSvsQuotes

Remove the variation selectors from all quotation marks to restore them to ambiguous pure characters.

getQuoteTypeForEnclosedContent

Determine whether a string should be enclosed in fullwidth, halfwidth, or Sibe form brackets or quotation marks.

Determine rules:

  1. Query whether the first or the last character of a string is a full width character, and return "fullwidth" if so.
  2. Query whether the first or the last character of a string is a Mongolian letter, and return "sibe" if so.
  3. If there are ambiguous characters, query the second or the penultimate character, and so on.
  4. If the entire string contains ambiguous characters, return "halfwidth".
  5. Otherwise, return "halfwidth".
getQuoteTypeOfChar

Check if a character is fullwidth, halfwidth, Sibe form, or ambiguous.

But treat hangul as halfwidth due to korean uses halfwidth punctuation marks, and treat empty string as ambiguous, treat a quotation mark without any variation selectors as ambiguous.

East Asian Width Returns
fullwidth fullwidth
halfwidth halfwidth
wide fullwidth
narrow halfwidth
neutral halfwidth
ambiguous ambiguous
Special Returns
Quote without VS ambiguous
Quote + VS1 halfwidth
Quote + VS2 fullwidth
Quote + VS3 sibe
Hangul halfwidth
Mongolian sibe
Empty String ambiguous
toUnicodeStringSequence

Convert a string to Unicode sequence that won't divide the variation selectors or something else into single characters.

It will return an array where each element is a valid Unicode Variation Sequences.

License

fullwidth-quotes is available under the MIT License. See the LICENSE file for more info.

Keywords