quote-quote
v1.4.0
Published
Convert straight quotes to curly quotes — also known as smart quotes.
Downloads
654
Maintainers
Readme
“QuoteQuote”
Convert boring, straight quotes (" and ') to beautiful, typographically correct curly quotes — also known as smart quotes.
Highlights
- 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.
Installing
Install with a package manager such as npm, pnpm or yarn.
npm install quote-quoteExample
ESM
import { convert } from 'quote-quote';
const text = `"That's a 'magic' shoe."`;
convert(text); // “That’s a ‘magic’ shoe.”CommonJS
const { convert } = require('quote-quote');
const text = `"That's a 'magic' shoe."`;
convert(text); // “That’s a ‘magic’ shoe.”Browser
Load quote-quote.min.js to expose the library globally as QuoteQuote. It can be loaded from a CDN such as jsDelivr or UNPKG.
<script src="https://cdn.jsdelivr.net/npm/quote-quote@1/dist/quote-quote.min.js"></script>
<script>
QuoteQuote.convert(`"That's a 'magic' shoe."`);
</script>Or load quote-quote.esm.min.js to use the library as an ES module, but without requiring a bundler.
<script type="module">
import { convert } from 'https://cdn.jsdelivr.net/npm/quote-quote@1/dist/quote-quote.esm.min.js';
convert(`"That's a 'magic' shoe."`);
</script>API Summary
| | |
| ------------------- | ---------------------------------------------------- |
| convert() | Convert straight quotes to curly quotes. |
| convertMarkdown() | Convert straight quotes to curly quotes in Markdown. |
API
convert(text[, options])
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 |
| Returns | String |
| Throws | TypeError – if text is not a String or options not an Object |
Example:
import { convert } from 'quote-quote';
const text = `"That's a 'magic' shoe."`;
convert(text); // “That’s a ‘magic’ shoe.”Example using options:
import { convert } from 'quote-quote';
const text = `"That's a 'magic' shoe..."`;
convert(text, { ellipsis: true }); // “That’s a ‘magic’ shoe…”convertMarkdown(text[, options])
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 |
| Returns | String |
| Throws | TypeError – if text is not a String or options not an Object |
Example:
import { convertMarkdown } from 'quote-quote';
const text = '"Hello `"world"`" they said.';
convertMarkdown(text); // “Hello `"world"`” they said.Example using options:
import { convertMarkdown } from 'quote-quote';
const text = '"Hello `"world"`" they said...';
convertMarkdown(text, { ellipsis: true }); // “Hello `"world"`” they said…Versioning
This project follows SemVer (Semantic Versioning).
Support
QuoteQuote ships ES2022 syntax. Supported environments:
- Chrome 85
- Firefox 78
- Edge 85
- Safari 16.4
- iOS 16.4
- Node.js 15
- Deno 1.2
