From e2856d980d1e9335d5e62c7de25c1d22e6956584 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 20 Nov 2023 08:34:42 +0100 Subject: [PATCH] fix: add back CJS support, with a test --- package.json | 8 ++++++-- pnpm-lock.yaml | 24 ++++++++++++------------ src/e2e.test.cjs | 5 +++++ src/emojify.ts | 8 ++++---- src/replace.ts | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/e2e.test.cjs diff --git a/package.json b/package.json index 9b89c9c..38a6450 100644 --- a/package.json +++ b/package.json @@ -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" } @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39497b3..1aa128b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,11 +6,11 @@ settings: dependencies: '@sindresorhus/is': - specifier: ^6.0.0 - version: 6.0.0 + specifier: ^4.6.0 + version: 4.6.0 char-regex: - specifier: ^2.0.0 - version: 2.0.1 + specifier: ^1.0.2 + version: 1.0.2 emojilib: specifier: ^2.4.0 version: 2.4.0 @@ -1434,16 +1434,16 @@ packages: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true + /@sindresorhus/is@4.6.0: + resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==} + engines: {node: '>=10'} + dev: false + /@sindresorhus/is@5.3.0: resolution: {integrity: sha512-CX6t4SYQ37lzxicAqsBtxA3OseeoVrh9cSJ5PFYam0GksYlupRfy1A+Q4aYD3zvcfECLc0zO2u+ZnR2UYKvCrw==} engines: {node: '>=14.16'} dev: true - /@sindresorhus/is@6.0.0: - resolution: {integrity: sha512-iVkg+3V+GJfof7yAHOxHyoiEfgpRJhnddOY3EsTM/uqwcm6M/jDQwK1n1nnraMpTRT36CxS0RCtJohggaQ0jgQ==} - engines: {node: '>=16'} - dev: false - /@sindresorhus/merge-streams@1.0.0: resolution: {integrity: sha512-rUV5WyJrJLoloD4NDN1V1+LDMDWOa4OTsT4yYJwQNpTU6FWxkxHpL7eu4w+DmiH8x/EAM1otkPE1+LaspIbplw==} engines: {node: '>=18'} @@ -2313,9 +2313,9 @@ packages: engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true - /char-regex@2.0.1: - resolution: {integrity: sha512-oSvEeo6ZUD7NepqAat3RqoucZ5SeqLJgOvVIwkafu6IP3V0pO38s/ypdVUmDDK6qIIHNlYHJAKX9E7R7HoKElw==} - engines: {node: '>=12.20'} + /char-regex@1.0.2: + resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} + engines: {node: '>=10'} dev: false /character-entities-legacy@1.1.4: diff --git a/src/e2e.test.cjs b/src/e2e.test.cjs new file mode 100644 index 0000000..e35c73f --- /dev/null +++ b/src/e2e.test.cjs @@ -0,0 +1,5 @@ +const { strict: assert } = require('node:assert') + +const emoji = require('../lib/index.cjs') + +assert.equal(emoji.emojify(':wave:'), '👋') diff --git a/src/emojify.ts b/src/emojify.ts index d21107d..e1d41eb 100644 --- a/src/emojify.ts +++ b/src/emojify.ts @@ -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' @@ -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) diff --git a/src/replace.ts b/src/replace.ts index 663258b..5ea5966 100644 --- a/src/replace.ts +++ b/src/replace.ts @@ -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)