Skip to content

Commit

Permalink
fix: add back CJS support, with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Nov 20, 2023
1 parent 6714e21 commit e2856d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"type": "module",
"exports": {
".": {
"types": {
"import": "./lib/index.d.ts",
"require": "./lib/index.d.cts"
},
"import": "./lib/index.js",
"require": "./lib/index.cjs"
}
Expand Down Expand Up @@ -58,8 +62,8 @@
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"@sindresorhus/is": "^6.0.0",
"char-regex": "^2.0.0",
"@sindresorhus/is": "^4.6.0",
"char-regex": "^1.0.2",
"emojilib": "^2.4.0",
"skin-tone": "^2.0.0"
},
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/e2e.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { strict: assert } = require('node:assert')

const emoji = require('../lib/index.cjs')

Check failure on line 3 in src/e2e.test.cjs

View workflow job for this annotation

GitHub Actions / lint

"../lib/index.cjs" is not found

assert.equal(emoji.emojify(':wave:'), '👋')
8 changes: 4 additions & 4 deletions src/emojify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, default as is } from '@sindresorhus/is'
import is from '@sindresorhus/is'

import { findByName } from './findByName.js'
import { asFunction, normalizeName } from './utils.js'
Expand All @@ -21,9 +21,9 @@ export const emojify = (
const fallbackFunction =
fallback === undefined ? fallback : asFunction(fallback)

assert.string(input)
assert.any([is.undefined, is.function], fallbackFunction)
assert.function(format)
is.assert.string(input)
is.assert.any([is.default.undefined, is.default.function_], fallbackFunction)
is.assert.function_(format)

return input.replace(/:[\w\-+]+:/g, part => {
const found = findByName(part)
Expand Down
2 changes: 1 addition & 1 deletion src/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const replace = (
const replace = asFunction(replacement)

assert.string(input)
assert.function(replace)
assert.function_(replace)
assert.boolean(preserveSpaces)

const characters = input.match(charRegexMatcher)
Expand Down

0 comments on commit e2856d9

Please sign in to comment.