From b3d123c1e4af5cb53b15d9c541034e874eee660b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:34:31 +0100 Subject: [PATCH 1/9] Update dev-dependencies --- .github/workflows/main.yml | 2 +- package.json | 10 ++-- readme.md | 114 ++++++++++++++++++------------------- script/build-data.js | 2 +- script/build-support.js | 18 ++---- test.js | 2 +- 6 files changed, 71 insertions(+), 77 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe284ad..69924a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/erbium + - lts/fermium - node diff --git a/package.json b/package.json index b54b602..699e590 100644 --- a/package.json +++ b/package.json @@ -42,17 +42,17 @@ "alphanum-sort": "^1.0.0", "c8": "^7.0.0", "gemoji": "^7.0.0", - "mdast-zone": "^4.0.0", + "mdast-zone": "^5.0.0", "plain-text-data-to-json": "^2.0.0", "prettier": "^2.0.0", - "remark-cli": "^9.0.0", - "remark-preset-wooorm": "^8.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", - "unist-builder": "^2.0.0", - "xo": "^0.38.0" + "unist-builder": "^3.0.0", + "xo": "^0.52.0" }, "scripts": { "prepack": "npm run build && npm run format", diff --git a/readme.md b/readme.md index 0a36741..800f8b8 100644 --- a/readme.md +++ b/readme.md @@ -73,122 +73,122 @@ not be available on the users computer. | Emoji | Name(s) | Polarity | | - | - | - | | ๐Ÿ‘ฟ | imp | -4 | -| ๐Ÿ–• | middle_finger; fu | -4 | -| ๐Ÿ˜พ | pouting_cat | -4 | +| ๐Ÿ–• | middle\_finger; fu | -4 | +| ๐Ÿ˜พ | pouting\_cat | -4 | | ๐Ÿ˜ก | rage; pout | -4 | | ๐Ÿ˜  | angry | -3 | | ๐Ÿ˜ง | anguished | -3 | -| ๐Ÿ’” | broken_heart | -3 | +| ๐Ÿ’” | broken\_heart | -3 | | ๐Ÿ’ฉ | hankey; poop; shit | -3 | | ๐Ÿ˜ฑ | scream | -3 | -| ๐Ÿ™€ | scream_cat | -3 | -| ๐Ÿ˜ˆ | smiling_imp | -3 | +| ๐Ÿ™€ | scream\_cat | -3 | +| ๐Ÿ˜ˆ | smiling\_imp | -3 | | ๐Ÿ˜ญ | sob | -3 | | ๐Ÿ˜Ÿ | worried | -3 | | ๐Ÿ‘Ž | -1; thumbsdown | -2 | -| ๐Ÿ˜ฐ | cold_sweat | -2 | +| ๐Ÿ˜ฐ | cold\_sweat | -2 | | ๐Ÿ˜– | confounded | -2 | | ๐Ÿ˜• | confused | -2 | | ๐Ÿ˜ข | cry | -2 | -| ๐Ÿ˜ฟ | crying_cat_face | -2 | +| ๐Ÿ˜ฟ | crying\_cat\_face | -2 | | ๐Ÿ˜ž | disappointed | -2 | -| ๐Ÿค• | face_with_head_bandage | -2 | +| ๐Ÿค• | face\_with\_head\_bandage | -2 | | ๐Ÿ˜จ | fearful | -2 | | ๐Ÿ˜ณ | flushed | -2 | -| โ˜น๏ธ | frowning_face | -2 | +| โ˜น๏ธ | frowning\_face | -2 | | ๐Ÿ˜ฌ | grimacing | -2 | -| ๐Ÿคฅ | lying_face | -2 | -| ๐Ÿคข | nauseated_face | -2 | -| ๐Ÿ˜ฎ | open_mouth | -2 | +| ๐Ÿคฅ | lying\_face | -2 | +| ๐Ÿคข | nauseated\_face | -2 | +| ๐Ÿ˜ฎ | open\_mouth | -2 | | ๐Ÿ˜ฃ | persevere | -2 | | ๐Ÿ’€ | skull | -2 | -| โ˜ ๏ธ | skull_and_crossbones | -2 | -| ๐Ÿคง | sneezing_face | -2 | -| ๐Ÿ˜ซ | tired_face | -2 | +| โ˜ ๏ธ | skull\_and\_crossbones | -2 | +| ๐Ÿคง | sneezing\_face | -2 | +| ๐Ÿ˜ซ | tired\_face | -2 | | ๐Ÿ˜’ | unamused | -2 | | ๐Ÿ˜ฉ | weary | -2 | -| ๐Ÿ˜ฅ | disappointed_relieved | -1 | -| ๐Ÿ˜ต | dizzy_face | -1 | -| ๐Ÿค’ | face_with_thermometer | -1 | -| ๐Ÿ‘Š | fist_oncoming; facepunch; punch | -1 | +| ๐Ÿ˜ฅ | disappointed\_relieved | -1 | +| ๐Ÿ˜ต | dizzy\_face | -1 | +| ๐Ÿค’ | face\_with\_thermometer | -1 | +| ๐Ÿ‘Š | fist\_oncoming; facepunch; punch | -1 | | ๐Ÿ˜ฆ | frowning | -1 | | ๐Ÿ‘ป | ghost | -1 | | ๐Ÿ˜ฏ | hushed | -1 | | ๐Ÿ˜ท | mask | -1 | -| ๐Ÿค“ | nerd_face | -1 | +| ๐Ÿค“ | nerd\_face | -1 | | ๐Ÿ˜” | pensive | -1 | -| ๐Ÿ™„ | roll_eyes | -1 | -| ๐Ÿ™ | slightly_frowning_face | -1 | -| ๐Ÿ˜œ | stuck_out_tongue_winking_eye | -1 | +| ๐Ÿ™„ | roll\_eyes | -1 | +| ๐Ÿ™ | slightly\_frowning\_face | -1 | +| ๐Ÿ˜œ | stuck\_out\_tongue\_winking\_eye | -1 | | ๐Ÿ˜“ | sweat | -1 | | ๐Ÿค” | thinking | -1 | -| ๐Ÿค | zipper_mouth_face | -1 | -| ๐Ÿคก | clown_face | 0 | -| ๐Ÿคค | drooling_face | 0 | +| ๐Ÿค | zipper\_mouth\_face | -1 | +| ๐Ÿคก | clown\_face | 0 | +| ๐Ÿคค | drooling\_face | 0 | | ๐Ÿ˜‘ | expressionless | 0 | -| ๐Ÿค‘ | money_mouth_face | 0 | -| ๐Ÿ˜ | neutral_face | 0 | -| ๐Ÿ˜ถ | no_mouth | 0 | +| ๐Ÿค‘ | money\_mouth\_face | 0 | +| ๐Ÿ˜ | neutral\_face | 0 | +| ๐Ÿ˜ถ | no\_mouth | 0 | | ๐Ÿ˜ด | sleeping | 0 | | ๐Ÿ˜ช | sleepy | 0 | -| ๐Ÿ˜ | stuck_out_tongue_closed_eyes | 0 | +| ๐Ÿ˜ | stuck\_out\_tongue\_closed\_eyes | 0 | | ๐Ÿ˜ค | triumph | 0 | -| ๐Ÿ™ƒ | upside_down_face | 0 | +| ๐Ÿ™ƒ | upside\_down\_face | 0 | | ๐Ÿค | handshake | 1 | | ๐Ÿ˜† | laughing; satisfied | 1 | | ๐Ÿ™ | pray | 1 | -| ๐Ÿ™‚ | slightly_smiling_face | 1 | -| ๐Ÿ˜› | stuck_out_tongue | 1 | +| ๐Ÿ™‚ | slightly\_smiling\_face | 1 | +| ๐Ÿ˜› | stuck\_out\_tongue | 1 | | ๐Ÿ˜Ž | sunglasses | 1 | | ๐Ÿ‘ | +1; thumbsup | 2 | | ๐Ÿ˜ฒ | astonished | 2 | | ๐Ÿ˜Š | blush | 2 | -| ๐Ÿค  | cowboy_hat_face | 2 | -| ๐Ÿคž | crossed_fingers | 2 | +| ๐Ÿค  | cowboy\_hat\_face | 2 | +| ๐Ÿคž | crossed\_fingers | 2 | | ๐Ÿ˜ | grin | 2 | | ๐Ÿ˜€ | grinning | 2 | | ๐Ÿค— | hugs | 2 | | ๐Ÿ’‹ | kiss | 2 | | ๐Ÿ˜— | kissing | 2 | -| ๐Ÿ˜ฝ | kissing_cat | 2 | -| ๐Ÿ˜š | kissing_closed_eyes | 2 | -| ๐Ÿ˜™ | kissing_smiling_eyes | 2 | +| ๐Ÿ˜ฝ | kissing\_cat | 2 | +| ๐Ÿ˜š | kissing\_closed\_eyes | 2 | +| ๐Ÿ˜™ | kissing\_smiling\_eyes | 2 | | ๐Ÿ‘„ | lips | 2 | -| ๐Ÿ‘Œ | ok_hand | 2 | +| ๐Ÿ‘Œ | ok\_hand | 2 | | โ˜บ๏ธ | relaxed | 2 | | ๐Ÿ˜Œ | relieved | 2 | | ๐Ÿ˜„ | smile | 2 | -| ๐Ÿ˜ธ | smile_cat | 2 | +| ๐Ÿ˜ธ | smile\_cat | 2 | | ๐Ÿ˜ƒ | smiley | 2 | -| ๐Ÿ˜บ | smiley_cat | 2 | +| ๐Ÿ˜บ | smiley\_cat | 2 | | ๐Ÿ˜ | smirk | 2 | -| ๐Ÿ˜ผ | smirk_cat | 2 | -| ๐Ÿ˜… | sweat_smile | 2 | +| ๐Ÿ˜ผ | smirk\_cat | 2 | +| ๐Ÿ˜… | sweat\_smile | 2 | | โœŒ๏ธ | v | 2 | | ๐Ÿ’ฏ | 100 | 3 | -| ๐Ÿ–ค | black_heart | 3 | -| ๐Ÿ’™ | blue_heart | 3 | +| ๐Ÿ–ค | black\_heart | 3 | +| ๐Ÿ’™ | blue\_heart | 3 | | ๐Ÿ‘ | clap | 3 | | ๐Ÿ’˜ | cupid | 3 | -| ๐Ÿ’ | gift_heart | 3 | -| ๐Ÿ’š | green_heart | 3 | +| ๐Ÿ’ | gift\_heart | 3 | +| ๐Ÿ’š | green\_heart | 3 | | โค๏ธ | heart | 3 | -| ๐Ÿ˜ | heart_eyes | 3 | -| ๐Ÿ˜ป | heart_eyes_cat | 3 | +| ๐Ÿ˜ | heart\_eyes | 3 | +| ๐Ÿ˜ป | heart\_eyes\_cat | 3 | | ๐Ÿ’“ | heartbeat | 3 | | ๐Ÿ’— | heartpulse | 3 | | ๐Ÿ˜‡ | innocent | 3 | | ๐Ÿ˜‚ | joy | 3 | -| ๐Ÿ˜น | joy_cat | 3 | -| ๐Ÿ˜˜ | kissing_heart | 3 | -| ๐Ÿ’œ | purple_heart | 3 | -| ๐Ÿ’ž | revolving_hearts | 3 | -| ๐Ÿ’– | sparkling_heart | 3 | -| ๐Ÿ’• | two_hearts | 3 | +| ๐Ÿ˜น | joy\_cat | 3 | +| ๐Ÿ˜˜ | kissing\_heart | 3 | +| ๐Ÿ’œ | purple\_heart | 3 | +| ๐Ÿ’ž | revolving\_hearts | 3 | +| ๐Ÿ’– | sparkling\_heart | 3 | +| ๐Ÿ’• | two\_hearts | 3 | | ๐Ÿ˜‰ | wink | 3 | -| ๐Ÿ’› | yellow_heart | 3 | +| ๐Ÿ’› | yellow\_heart | 3 | | ๐Ÿ˜‹ | yum | 3 | -| ๐Ÿ™Œ | raised_hands | 4 | +| ๐Ÿ™Œ | raised\_hands | 4 | | ๐Ÿคฃ | rofl | 4 | diff --git a/script/build-data.js b/script/build-data.js index 000256c..e20fd06 100644 --- a/script/build-data.js +++ b/script/build-data.js @@ -1,4 +1,4 @@ -import fs from 'fs' +import fs from 'node:fs' import {gemoji, nameToEmoji} from 'gemoji' import {toJson} from 'plain-text-data-to-json' diff --git a/script/build-support.js b/script/build-support.js index d081935..362f436 100644 --- a/script/build-support.js +++ b/script/build-support.js @@ -1,7 +1,5 @@ -// @ts-ignore remove when typed. -import zone from 'mdast-zone' -import u from 'unist-builder' -// @ts-ignore remove when typed. +import {zone} from 'mdast-zone' +import {u} from 'unist-builder' import sort from 'alphanum-sort/lib/compare.js' import {gemoji, emojiToName} from 'gemoji' import {emojiEmotion} from '../index.js' @@ -14,18 +12,14 @@ export default function buildSupport() { * @param {import('mdast').Root} tree */ function transformer(tree) { - zone(tree, 'support', replace) + zone(tree, 'support', function (start, _, end) { + return [start, table(), end] + }) } /** - * @param {import('unist').Node} start - * @param {unknown} _ - * @param {import('unist').Node} end + * @returns {import('mdast').Table} */ -function replace(start, _, end) { - return [start, table(), end] -} - function table() { var head = u('tableRow', [cell('Emoji'), cell('Name(s)'), cell('Polarity')]) diff --git a/test.js b/test.js index 9468867..ccbd931 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,4 @@ -import assert from 'assert' +import assert from 'node:assert' import test from 'tape' import {emojiEmotion} from './index.js' From 1925f8387ccc7794425a34f4b8efbbf971403a79 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:35:42 +0100 Subject: [PATCH 2/9] Refactor code-style --- index.js | 2 +- package.json | 7 +------ script/build-data.js | 16 ++++++++-------- script/build-support.js | 6 +++--- test.js | 8 +++----- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index ee132a0..da8bc32 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -export var emojiEmotion = [ +export const emojiEmotion = [ { name: '100', emoji: '๐Ÿ’ฏ', diff --git a/package.json b/package.json index 699e590..cd1f47e 100644 --- a/package.json +++ b/package.json @@ -72,12 +72,7 @@ "trailingComma": "none" }, "xo": { - "prettier": true, - "rules": { - "import/no-mutable-exports": "off", - "no-var": "off", - "prefer-arrow-callback": "off" - } + "prettier": true }, "remarkConfig": { "plugins": [ diff --git a/script/build-data.js b/script/build-data.js index e20fd06..2861076 100644 --- a/script/build-data.js +++ b/script/build-data.js @@ -3,16 +3,16 @@ import {gemoji, nameToEmoji} from 'gemoji' import {toJson} from 'plain-text-data-to-json' /** @type {Object.} */ -var raw = toJson(fs.readFileSync('faces.txt', 'utf8')) +const raw = toJson(fs.readFileSync('faces.txt', 'utf8')) /** @type {Array.} */ -var all = [] -var unclassified = new Set(['๐Ÿค–']) +const all = [] +const unclassified = new Set(['๐Ÿค–']) -var faces = Object.keys(raw) +const faces = Object.keys(raw) .sort() .map(function (name) { - var polarity = Number(raw[name]) - var emoji = nameToEmoji[name] + const polarity = Number(raw[name]) + const emoji = nameToEmoji[name] if (Number.isNaN(polarity)) { console.log('Invalid valence for %s: %s', name, raw[name]) @@ -27,7 +27,7 @@ var faces = Object.keys(raw) return {name, emoji, polarity} }) -var index = -1 +let index = -1 while (++index < gemoji.length) { if (gemoji[index].category !== 'people') { @@ -54,5 +54,5 @@ while (++index < gemoji.length) { fs.writeFileSync( 'index.js', - 'export var emojiEmotion = ' + JSON.stringify(faces, null, 2) + '\n' + 'export const emojiEmotion = ' + JSON.stringify(faces, null, 2) + '\n' ) diff --git a/script/build-support.js b/script/build-support.js index 362f436..c58616b 100644 --- a/script/build-support.js +++ b/script/build-support.js @@ -21,9 +21,9 @@ function transformer(tree) { * @returns {import('mdast').Table} */ function table() { - var head = u('tableRow', [cell('Emoji'), cell('Name(s)'), cell('Polarity')]) + const head = u('tableRow', [cell('Emoji'), cell('Name(s)'), cell('Polarity')]) - var body = emojiEmotion + const body = emojiEmotion .sort(function (a, b) { return ( a.polarity - b.polarity || @@ -31,7 +31,7 @@ function table() { ) }) .map(function (d) { - var info = gemoji.find((g) => g.emoji === d.emoji) + const info = gemoji.find((g) => g.emoji === d.emoji) return u('tableRow', [ cell(d.emoji), diff --git a/test.js b/test.js index ccbd931..af5cbd5 100644 --- a/test.js +++ b/test.js @@ -6,7 +6,7 @@ test('emoji-emotion', function (t) { t.ok(Array.isArray(emojiEmotion)) t.doesNotThrow(function () { - var index = -1 + let index = -1 while (++index < emojiEmotion.length) { assert.strictEqual( typeof emojiEmotion[index].emoji, @@ -17,12 +17,10 @@ test('emoji-emotion', function (t) { }, 'each entry should have an `emoji` string field') t.doesNotThrow(function () { - var index = -1 - /** @type {string} */ - var label + let index = -1 while (++index < emojiEmotion.length) { - label = JSON.stringify(emojiEmotion[index]) + const label = JSON.stringify(emojiEmotion[index]) assert.strictEqual( typeof emojiEmotion[index].polarity, From c69b9e56dd54eee1f38f0951263ebef0bb2357d8 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:37:25 +0100 Subject: [PATCH 3/9] Add strict types --- readme.md | 2 +- script/build-data.js | 4 ++-- script/build-support.js | 3 +++ tsconfig.json | 18 ++++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index 800f8b8..140faf8 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,7 @@ There is no default export. ### `emojiEmotion` -`Array.`, where each object has `name` (`string`), `emoji` (`string`), and +`Array`, where each object has `name` (`string`), `emoji` (`string`), and `polarity` (`number`). ## Data diff --git a/script/build-data.js b/script/build-data.js index 2861076..2134b0f 100644 --- a/script/build-data.js +++ b/script/build-data.js @@ -2,9 +2,9 @@ import fs from 'node:fs' import {gemoji, nameToEmoji} from 'gemoji' import {toJson} from 'plain-text-data-to-json' -/** @type {Object.} */ +/** @type {Record} */ const raw = toJson(fs.readFileSync('faces.txt', 'utf8')) -/** @type {Array.} */ +/** @type {Array} */ const all = [] const unclassified = new Set(['๐Ÿค–']) diff --git a/script/build-support.js b/script/build-support.js index c58616b..41ae15f 100644 --- a/script/build-support.js +++ b/script/build-support.js @@ -1,5 +1,7 @@ +import assert from 'node:assert/strict' import {zone} from 'mdast-zone' import {u} from 'unist-builder' +// @ts-expect-error untyped. import sort from 'alphanum-sort/lib/compare.js' import {gemoji, emojiToName} from 'gemoji' import {emojiEmotion} from '../index.js' @@ -32,6 +34,7 @@ function table() { }) .map(function (d) { const info = gemoji.find((g) => g.emoji === d.emoji) + assert(info, 'expected emoji for `' + d.name + '`') return u('tableRow', [ cell(d.emoji), diff --git a/tsconfig.json b/tsconfig.json index ee48d88..016d1f4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,17 @@ { - "include": ["*.js", "script/**/*.js"], + "include": ["**/**.js"], + "exclude": ["coverage", "node_modules"], "compilerOptions": { - "target": "ES2020", - "lib": ["ES2020"], - "module": "ES2020", - "moduleResolution": "node", - "allowJs": true, "checkJs": true, "declaration": true, "emitDeclarationOnly": true, - "allowSyntheticDefaultImports": true, - "skipLibCheck": true + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es2020"], + "module": "node16", + "newLine": "lf", + "skipLibCheck": true, + "strict": true, + "target": "es2020" } } From d01ea4d24e54f5d233196a40446fb989047c48ab Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:38:09 +0100 Subject: [PATCH 4/9] Refactor npm scripts --- package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cd1f47e..5cd25da 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", @@ -56,11 +55,11 @@ }, "scripts": { "prepack": "npm run build && npm run format", - "build": "rimraf \"{,script/**}*.d.ts\" && tsc && type-coverage", - "generate": "node script/build-data", + "generate": "node script/build-data.js", + "build": "tsc --build --clean && tsc --build && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "test-api": "node test.js", - "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", + "test-api": "node --conditions development test.js", + "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { From 9810efe796a4244a4d7310c3188a360d073b9af3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:39:21 +0100 Subject: [PATCH 5/9] Use Node test runner --- .github/workflows/main.yml | 6 +++--- package.json | 2 -- test.js | 14 ++++++-------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69924a4..638184c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,8 +7,8 @@ jobs: name: ${{matrix.node}} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: dcodeIO/setup-node-nvm@master + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} - run: npm install @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/fermium + - lts/hydrogen - node diff --git a/package.json b/package.json index 5cd25da..1e50d1c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ ], "devDependencies": { "@types/mdast": "^3.0.0", - "@types/tape": "^4.0.0", "@types/unist": "^2.0.0", "alphanum-sort": "^1.0.0", "c8": "^7.0.0", @@ -47,7 +46,6 @@ "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", "unist-builder": "^3.0.0", diff --git a/test.js b/test.js index af5cbd5..2e258c4 100644 --- a/test.js +++ b/test.js @@ -1,11 +1,11 @@ -import assert from 'node:assert' -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {emojiEmotion} from './index.js' -test('emoji-emotion', function (t) { - t.ok(Array.isArray(emojiEmotion)) +test('emoji-emotion', function () { + assert.ok(Array.isArray(emojiEmotion)) - t.doesNotThrow(function () { + assert.doesNotThrow(function () { let index = -1 while (++index < emojiEmotion.length) { assert.strictEqual( @@ -16,7 +16,7 @@ test('emoji-emotion', function (t) { } }, 'each entry should have an `emoji` string field') - t.doesNotThrow(function () { + assert.doesNotThrow(function () { let index = -1 while (++index < emojiEmotion.length) { @@ -36,6 +36,4 @@ test('emoji-emotion', function (t) { assert.ok(emojiEmotion[index].polarity <= 5, 'lte 5: ' + label) } }, 'each entry should have an `polarity` integer field') - - t.end() }) From 8e66ee3b65db7f43f56a1beeb3078eff14c4c3a2 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 09:44:56 +0100 Subject: [PATCH 6/9] Add docs to types --- index.js | 16 ++++++++++++++++ script/build-data.js | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index da8bc32..e6692d4 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,19 @@ +/** + * @typedef Info + * Emoji rated for valence + * @property {string} name + * Name of emoji (according to `wooorm/gemoji`). + * @property {string} emoji + * Unicode emoji. + * @property {number} polarity + * Integer between minus five (negative) and plus five (positive). + */ + +/** + * List of emoji rated for valence. + * + * @type {Array} + */ export const emojiEmotion = [ { name: '100', diff --git a/script/build-data.js b/script/build-data.js index 2134b0f..5de33df 100644 --- a/script/build-data.js +++ b/script/build-data.js @@ -54,5 +54,7 @@ while (++index < gemoji.length) { fs.writeFileSync( 'index.js', - 'export const emojiEmotion = ' + JSON.stringify(faces, null, 2) + '\n' + '/**\n * @typedef Info\n * Emoji rated for valence\n * @property {string} name\n * Name of emoji (according to `wooorm/gemoji`).\n * @property {string} emoji\n * Unicode emoji.\n * @property {number} polarity\n * Integer between minus five (negative) and plus five (positive).\n */\n\n/**\n * List of emoji rated for valence.\n *\n * @type {Array}\n */\nexport const emojiEmotion = ' + + JSON.stringify(faces, null, 2) + + '\n' ) From ac215260d0b6427fcd063acfa5bbb52c74ff9c25 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 10:05:21 +0100 Subject: [PATCH 7/9] Add improved docs --- index.js | 4 +- package.json | 2 +- readme.md | 121 ++++++++++++++++++++++++++++++++++++------- script/build-data.js | 8 +-- 4 files changed, 110 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index e6692d4..8c65985 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ /** * @typedef Info - * Emoji rated for valence + * Emoji rated for valence. * @property {string} name - * Name of emoji (according to `wooorm/gemoji`). + * Name of emoji, according to `wooorm/gemoji`. * @property {string} emoji * Unicode emoji. * @property {number} polarity diff --git a/package.json b/package.json index 1e50d1c..71e03c3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "emoji-emotion", "version": "3.0.0", - "description": "List of emoji rated for valence in JSON", + "description": "List of emoji rated for valence", "license": "MIT", "keywords": [ "gemoji", diff --git a/readme.md b/readme.md index 140faf8..f8b1873 100644 --- a/readme.md +++ b/readme.md @@ -5,20 +5,59 @@ [![Downloads][downloads-badge]][downloads] [![Size][size-badge]][size] -List of emoji rated for valence with an integer between minus five (negative) -and plus five (positive). +List of emoji rated for valence. -## Install +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`emojiEmotion`](#emojiemotion) +* [Data](#data) +* [Support](#support) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [Security](#security) +* [License](#license) + +## What is this? -This package is ESM only: Node 12+ is needed to use it and it must be `import`ed -instead of `require`d. +This is a list of unicode emoji rated for [valence][valence-wiki] (โ€œgoodnessโ€ +vs โ€œbadnessโ€). -[npm][]: +## When should I use this? + +This package can be used for sentiment analysis of emoji. +You can use [`afinn-165`][afinn-165] for English words. +Use [`gemoji`][gemoji] for more info on emoji. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 14.14+, 16.0+), install with [npm][]: ```sh npm install emoji-emotion ``` +In Deno with [`esm.sh`][esmsh]: + +```js +import {emojiEmotion} from 'https://esm.sh/emoji-emotion@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + ## Use ```js @@ -37,18 +76,30 @@ Yields: { name: 'black_heart', emoji: '๐Ÿ–ค', polarity: 3 } ] ``` -Note the information is intentionally limited. -Check out [`gemoji`][gemoji] for more info: tags, descriptions, names, etc. - ## API -This package exports the following identifiers: `emojiEmotion`. +This package exports the identifier `emojiEmotion`. There is no default export. ### `emojiEmotion` -`Array`, where each object has `name` (`string`), `emoji` (`string`), and -`polarity` (`number`). +List of emoji rated for valence (`Array`). + +##### `Info` + +Emoji rated for valence. + +##### `info.name` + +Name of emoji, according to [`gemoji`][gemoji] (`string`). + +##### `info.emoji` + +Unicode emoji (`string`). + +##### `info.polarity` + +Integer between minus five (negative) and plus five (positive) (`number`). ## Data @@ -59,13 +110,10 @@ Special care was given to **not** classify based on the images (as [different vendors use different pictograms][checkmoji]), but only on words and how they are used. -Note that some emoji receive arguably confusing polarities, such as +Some emoji receive arguably confusing polarities, such as `stuck_out_tongue_closed_eyes` (`0`), due to being used for both positive and negative emotions. -No images are included in this repository: the copyrighted material may or may -not be available on the users computer. - ## Support @@ -193,6 +241,33 @@ not be available on the users computer. +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional type `Info`. + +## Compatibility + +This package is at least compatible with all maintained versions of Node.js. +As of now, that is Node.js 14.14+ and 16.0+. +It also works in Deno and modern browsers. + +## Related + +* [`afinn-165`][afinn-165] + โ€” list of English words rated for valence +* [`gemoji`][gemoji] + โ€” info on gemoji (GitHub Emoji) + +## Contribute + +Yes please! +See [How to Contribute to Open Source][contribute]. + +## Security + +This package is safe. + ## License [MIT][license] ยฉ [Titus Wormer][author] @@ -217,14 +292,24 @@ not be available on the users computer. [npm]: https://docs.npmjs.com/cli/install +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[contribute]: https://opensource.guide/how-to-contribute/ + [license]: license [author]: https://wooorm.com -[gemoji]: https://github.com/wooorm/gemoji +[unicode]: http://www.unicode.org/emoji/charts/full-emoji-list.html -[unicode]: http://www.unicode.org/Public/emoji/1.0/full-emoji-list.html +[gemoji]: https://github.com/wooorm/gemoji [afinn-165]: https://github.com/words/afinn-165 [checkmoji]: https://wooorm.com/checkmoji/ + +[valence-wiki]: https://en.wikipedia.org/wiki/Valence_\(psychology\) diff --git a/script/build-data.js b/script/build-data.js index 5de33df..889017d 100644 --- a/script/build-data.js +++ b/script/build-data.js @@ -1,9 +1,9 @@ -import fs from 'node:fs' +import fs from 'node:fs/promises' import {gemoji, nameToEmoji} from 'gemoji' import {toJson} from 'plain-text-data-to-json' /** @type {Record} */ -const raw = toJson(fs.readFileSync('faces.txt', 'utf8')) +const raw = toJson(String(await fs.readFile('faces.txt'))) /** @type {Array} */ const all = [] const unclassified = new Set(['๐Ÿค–']) @@ -52,9 +52,9 @@ while (++index < gemoji.length) { } } -fs.writeFileSync( +await fs.writeFile( 'index.js', - '/**\n * @typedef Info\n * Emoji rated for valence\n * @property {string} name\n * Name of emoji (according to `wooorm/gemoji`).\n * @property {string} emoji\n * Unicode emoji.\n * @property {number} polarity\n * Integer between minus five (negative) and plus five (positive).\n */\n\n/**\n * List of emoji rated for valence.\n *\n * @type {Array}\n */\nexport const emojiEmotion = ' + + '/**\n * @typedef Info\n * Emoji rated for valence.\n * @property {string} name\n * Name of emoji, according to `wooorm/gemoji`.\n * @property {string} emoji\n * Unicode emoji.\n * @property {number} polarity\n * Integer between minus five (negative) and plus five (positive).\n */\n\n/**\n * List of emoji rated for valence.\n *\n * @type {Array}\n */\nexport const emojiEmotion = ' + JSON.stringify(faces, null, 2) + '\n' ) From 3736f8b05a6dca923e10b96724fd8c6a82941536 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 10:07:38 +0100 Subject: [PATCH 8/9] Add missing types dev-dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 71e03c3..cd2758a 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ ], "devDependencies": { "@types/mdast": "^3.0.0", + "@types/node": "^18.0.0", "@types/unist": "^2.0.0", "alphanum-sort": "^1.0.0", "c8": "^7.0.0", From 566af1b00486146e68aec38c7b872ca34f8ccd14 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 7 Nov 2022 10:08:59 +0100 Subject: [PATCH 9/9] 3.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd2758a..fd0ff87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "emoji-emotion", - "version": "3.0.0", + "version": "3.0.1", "description": "List of emoji rated for valence", "license": "MIT", "keywords": [