Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 20, 2021
1 parent 496938c commit c270596
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 68 deletions.
16 changes: 6 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'

var visit = require('unist-util-visit')
var toString = require('nlcst-to-string')

module.exports = smartypants
import visit from 'unist-util-visit'
import toString from 'nlcst-to-string'

var punctuation = 'PunctuationNode'
var symbol = 'SymbolNode'
Expand Down Expand Up @@ -41,13 +37,13 @@ var educators = {}
// Expose educators.
educators.dashes = {
true: dashes,
oldschool: oldschool,
inverted: inverted
oldschool,
inverted
}

educators.backticks = {
true: backticks,
all: all
all
}

educators.ellipses = {
Expand All @@ -59,7 +55,7 @@ educators.quotes = {
}

// Attacher.
function smartypants(options) {
export default function retextSmartypants(options) {
var methods = []
var quotes
var ellipses
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
Expand All @@ -37,10 +40,10 @@
"remark-preset-wooorm": "^7.0.0",
"retext": "^7.0.0",
"tape": "^5.0.0",
"xo": "^0.32.0"
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . --write && xo --fix",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
"test": "npm run format && npm run test-coverage"
Expand All @@ -55,7 +58,10 @@
},
"xo": {
"prettier": true,
"esnext": false
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
116 changes: 61 additions & 55 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
'use strict'

var test = require('tape')
var retext = require('retext')
var smartypants = require('.')
import test from 'tape'
import retext from 'retext'
import smartypants from './index.js'

test('Curly quotes', function (t) {
var processor = retext().use(smartypants)

t.test('should throw when not given `true`, `false`, or omitted', function (
st
) {
st.throws(function () {
retext().use(smartypants, {quotes: 1}).freeze()
}, /1/)
t.test(
'should throw when not given `true`, `false`, or omitted',
function (st) {
st.throws(function () {
retext().use(smartypants, {quotes: 1}).freeze()
}, /1/)

st.end()
})
st.end()
}
)

t.test('should not throw when not omitted', function (st) {
st.doesNotThrow(function () {
Expand Down Expand Up @@ -213,27 +212,29 @@ test('Curly quotes', function (t) {
}
)

t.test('should curl final double quotes when followed by a comma', function (
st
) {
st.equal(
processor.processSync('"Alfred", bertrand.').toString(),
'“Alfred”, bertrand.'
)
t.test(
'should curl final double quotes when followed by a comma',
function (st) {
st.equal(
processor.processSync('"Alfred", bertrand.').toString(),
'“Alfred”, bertrand.'
)

st.end()
})
st.end()
}
)

t.test('should curl final single quotes when followed by a comma', function (
st
) {
st.equal(
processor.processSync("'Alfred', bertrand.").toString(),
'‘Alfred’, bertrand.'
)
t.test(
'should curl final single quotes when followed by a comma',
function (st) {
st.equal(
processor.processSync("'Alfred', bertrand.").toString(),
'‘Alfred’, bertrand.'
)

st.end()
})
st.end()
}
)

t.test('should curl apostrophes when followed `s`', function (st) {
st.equal(
Expand All @@ -244,13 +245,14 @@ test('Curly quotes', function (t) {
st.end()
})

t.test('should curl apostrophes when followed by a decade (`80s`)', function (
st
) {
st.equal(processor.processSync("In the '90s.").toString(), 'In the ’90s.')
t.test(
'should curl apostrophes when followed by a decade (`80s`)',
function (st) {
st.equal(processor.processSync("In the '90s.").toString(), 'In the ’90s.')

st.end()
})
st.end()
}
)

t.test(
'should curl final double quotes when followed by a full stop',
Expand Down Expand Up @@ -362,7 +364,9 @@ test('Backticks', function (t) {
'should throw when not given `true`, `false`, `all`, or omitted',
function (st) {
st.throws(function () {
retext().use(smartypants, {backticks: Infinity}).freeze()
retext()
.use(smartypants, {backticks: Number.POSITIVE_INFINITY})
.freeze()
}, /Infinity/)

st.end()
Expand Down Expand Up @@ -486,15 +490,16 @@ test('Backticks', function (t) {
test('Ellipses', function (t) {
var processor = retext().use(smartypants)

t.test('should throw when not given `true`, `false`, or omitted', function (
st
) {
st.throws(function () {
retext().use(smartypants, {ellipses: Math}).freeze()
}, /\[object Math]/)
t.test(
'should throw when not given `true`, `false`, or omitted',
function (st) {
st.throws(function () {
retext().use(smartypants, {ellipses: Math}).freeze()
}, /\[object Math]/)

st.end()
})
st.end()
}
)

t.test('should not throw when not omitted', function (st) {
st.doesNotThrow(function () {
Expand Down Expand Up @@ -579,16 +584,17 @@ test('Ellipses', function (t) {
}
)

t.test('should replace three padded final full stops with spaces', function (
st
) {
st.equal(
processor.processSync('Alfred Bertrand . . .').toString(),
'Alfred Bertrand \u2026'
)
t.test(
'should replace three padded final full stops with spaces',
function (st) {
st.equal(
processor.processSync('Alfred Bertrand . . .').toString(),
'Alfred Bertrand \u2026'
)

st.end()
})
st.end()
}
)

t.test('should replace three full stops with spaces', function (st) {
st.equal(
Expand Down

0 comments on commit c270596

Please sign in to comment.