Convert straight quotes to curly quotes — also known as smart quotes.
npm install quote-quoteConvert boring, straight quotes (" and ') to beautiful, typographically correct curly quotes — also known as _smart quotes_.
- Converts straight single/double quotes to curly quotes.
- Converts straight quotes used as primes to prime symbols.
- Handles contractions, possessives and abbreviated years.
- Lightweight, zero dependencies, modern, and tree-shakeable.
Install with a package manager such as npm, pnpm or yarn.
``sh`
npm install quote-quote
`js
import { convert } from 'quote-quote';
const text = "That's a 'magic' shoe.";
convert(text); // “That’s a ‘magic’ shoe.”
`
`js
const { convert } = require('quote-quote');
const text = "That's a 'magic' shoe.";
convert(text); // “That’s a ‘magic’ shoe.”
`
| | |
| ------------------- | ---------------------------------------------------- |
| convert() | Convert straight quotes to curly quotes. |convertMarkdown()
| | Convert straight quotes to curly quotes in Markdown. |
Convert straight quotes to curly quotes.
| | |
| -------------------- | ---------------------------------------------------------------------- |
| text | String – the text that may contain straight quotes |options
| [] | Object – optional options |options.ellipsis
| [] | Boolean – whether to also convert "..." to an ellipsis |String
| Returns | |TypeError
| Throws | – if text is not a String or options not an Object |
Example:
`js
import { convert } from 'quote-quote';
const text = "That's a 'magic' shoe.";
convert(text); // “That’s a ‘magic’ shoe.”
`
Example using options:
`js
import { convert } from 'quote-quote';
const text = "That's a 'magic' shoe...";
convert(text, { ellipsis: true }); // “That’s a ‘magic’ shoe…”
`
Convert straight quotes to curly quotes in text formatted as Markdown. This means that quotes inside code are not converted.
| | |
| -------------------- | ---------------------------------------------------------------------- |
| text | String – the text that may contain straight quotes |options
| [] | Object – optional options |options.ellipsis
| [] | Boolean – whether to also convert "..." to an ellipsis |String
| Returns | |TypeError
| Throws | – if text is not a String or options not an Object |
Example:
`js
import { convertMarkdown } from 'quote-quote';
const text = '"Hello "world"" they said.';
convertMarkdown(text); // “Hello "world"” they said.`
Example using options:
`js
import { convertMarkdown } from 'quote-quote';
const text = '"Hello "world"" they said...';
convertMarkdown(text, { ellipsis: true }); // “Hello "world"” they said…``
This project follows SemVer (Semantic Versioning).