├── .all-contributorsrc ├── .eslintignore ├── .eslintrc.cjs ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Development.md ├── FUNDING.yml ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── 01-bug.yml │ ├── 02-documentation.yml │ ├── 03-feature.yml │ └── 04-tooling.yml ├── PULL_REQUEST_TEMPLATE.md ├── SECURITY.md ├── actions │ └── prepare │ │ └── action.yml ├── renovate.json └── workflows │ ├── accessibility-alt-text-bot.yml │ ├── build.yml │ ├── compliance.yml │ ├── contributors.yml │ ├── lint-knip.yml │ ├── lint-markdown.yml │ ├── lint-package-json.yml │ ├── lint-packages.yml │ ├── lint-spelling.yml │ ├── lint.yml │ ├── post-release.yml │ ├── pr-review-requested.yml │ ├── prettier.yml │ ├── release.yml │ ├── test-cjs.yml │ ├── test.yml │ └── tsc.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .markdownlint.json ├── .markdownlintignore ├── .npmpackagejsonlintrc.json ├── .nvmrc ├── .prettierignore ├── .prettierrc ├── .release-it.json ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── cspell.json ├── knip.jsonc ├── package.json ├── pnpm-lock.yaml ├── src ├── data.ts ├── e2e.cjs ├── emojify.test.ts ├── emojify.ts ├── emojilib.d.ts ├── find.test.ts ├── find.ts ├── findByCode.test.ts ├── findByCode.ts ├── findByName.test.ts ├── findByName.ts ├── get.test.ts ├── get.ts ├── has.test.ts ├── has.ts ├── index.ts ├── random.test.ts ├── random.ts ├── replace.test.ts ├── replace.ts ├── search.test.ts ├── search.ts ├── strip.test.ts ├── strip.ts ├── unemojify.test.ts ├── unemojify.ts ├── utils.ts ├── which.test.ts └── which.ts ├── tea.yaml ├── tsconfig.eslint.json ├── tsconfig.json ├── tsup.config.ts └── vitest.config.ts /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "badgeTemplate": "\"All 👪\" src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>_👪-21bb42.svg\" />", 3 | "commit": false, 4 | "commitConvention": "angular", 5 | "contributors": [ 6 | { 7 | "login": "ahanriat", 8 | "name": "Antoine Hanriat", 9 | "avatar_url": "https://avatars.githubusercontent.com/u/1374161?v=4", 10 | "profile": "https://github.com/ahanriat", 11 | "contributions": ["code"] 12 | }, 13 | { 14 | "login": "alexlitel", 15 | "name": "Alex Litel", 16 | "avatar_url": "https://avatars.githubusercontent.com/u/12000084?v=4", 17 | "profile": "https://github.com/alexlitel", 18 | "contributions": ["code"] 19 | }, 20 | { 21 | "login": "askoufis", 22 | "name": "Adam Skoufis", 23 | "avatar_url": "https://avatars.githubusercontent.com/u/5663042?v=4", 24 | "profile": "https://github.com/askoufis", 25 | "contributions": ["code"] 26 | }, 27 | { 28 | "login": "cagataycali", 29 | "name": "./c²", 30 | "avatar_url": "https://avatars.githubusercontent.com/u/9213230?v=4", 31 | "profile": "https://www.linkedin.com/in/cagataycali/", 32 | "contributions": ["code"] 33 | }, 34 | { 35 | "login": "charpeni", 36 | "name": "Nicolas Charpentier", 37 | "avatar_url": "https://avatars.githubusercontent.com/u/7189823?v=4", 38 | "profile": "https://charpeni.com/", 39 | "contributions": ["maintenance"] 40 | }, 41 | { 42 | "login": "cooperka", 43 | "name": "Kevin Cooper", 44 | "avatar_url": "https://avatars.githubusercontent.com/u/2047062?v=4", 45 | "profile": "https://cooperka.com/", 46 | "contributions": ["code"] 47 | }, 48 | { 49 | "login": "DanielHilton", 50 | "name": "Daniel Hilton", 51 | "avatar_url": "https://avatars.githubusercontent.com/u/28859662?v=4", 52 | "profile": "https://github.com/DanielHilton", 53 | "contributions": ["code"] 54 | }, 55 | { 56 | "login": "emctackett", 57 | "name": "Elizabeth", 58 | "avatar_url": "https://avatars.githubusercontent.com/u/19399698?v=4", 59 | "profile": "https://github.com/emctackett", 60 | "contributions": ["code", "maintenance"] 61 | }, 62 | { 63 | "login": "fossabot", 64 | "name": "fossabot", 65 | "avatar_url": "https://avatars.githubusercontent.com/u/29791463?v=4", 66 | "profile": "https://fossa.com/", 67 | "contributions": ["code"] 68 | }, 69 | { 70 | "login": "gabrielcsapo", 71 | "name": "Gabriel Csapo", 72 | "avatar_url": "https://avatars.githubusercontent.com/u/1854811?v=4", 73 | "profile": "https://www.gabrielcsapo.com/", 74 | "contributions": ["code"] 75 | }, 76 | { 77 | "login": "goodjun", 78 | "name": "goodjun", 79 | "avatar_url": "https://avatars.githubusercontent.com/u/18377597?v=4", 80 | "profile": "https://github.com/goodjun", 81 | "contributions": ["bug"] 82 | }, 83 | { 84 | "login": "greenkeeperio-bot", 85 | "name": "Greenkeeper", 86 | "avatar_url": "https://avatars.githubusercontent.com/u/14790466?v=4", 87 | "profile": "https://greenkeeper.io/", 88 | "contributions": ["code"] 89 | }, 90 | { 91 | "login": "HistoireDeBabar", 92 | "name": "Paul Barber", 93 | "avatar_url": "https://avatars.githubusercontent.com/u/6544057?v=4", 94 | "profile": "https://github.com/HistoireDeBabar", 95 | "contributions": ["code"] 96 | }, 97 | { 98 | "login": "jackiehluo", 99 | "name": "jackie luo", 100 | "avatar_url": "https://avatars.githubusercontent.com/u/8452682?v=4", 101 | "profile": "http://jackieluo.com/", 102 | "contributions": ["code"] 103 | }, 104 | { 105 | "login": "JoshuaKGoldberg", 106 | "name": "Josh Goldberg ✨", 107 | "avatar_url": "https://avatars.githubusercontent.com/u/3335181?v=4", 108 | "profile": "http://www.joshuakgoldberg.com/", 109 | "contributions": ["tool", "code", "infra", "maintenance"] 110 | }, 111 | { 112 | "login": "ludorenzetti", 113 | "name": "Ludo Renzetti", 114 | "avatar_url": "https://avatars.githubusercontent.com/u/8739517?v=4", 115 | "profile": "https://github.com/ludorenzetti", 116 | "contributions": ["code"] 117 | }, 118 | { 119 | "login": "merceyz", 120 | "name": "Kristoffer K.", 121 | "avatar_url": "https://avatars.githubusercontent.com/u/3842800?v=4", 122 | "profile": "https://github.com/merceyz", 123 | "contributions": ["code"] 124 | }, 125 | { 126 | "login": "ngryman", 127 | "name": "Nicolas Gryman", 128 | "avatar_url": "https://avatars.githubusercontent.com/u/892048?v=4", 129 | "profile": "https://ngryman.sh/", 130 | "contributions": ["code"] 131 | }, 132 | { 133 | "login": "omnidan", 134 | "name": "Daniel Bugl", 135 | "avatar_url": "https://avatars.githubusercontent.com/u/668674?v=4", 136 | "profile": "https://omnidan.net/", 137 | "contributions": [ 138 | "bug", 139 | "code", 140 | "fundingFinding", 141 | "ideas", 142 | "infra", 143 | "tool", 144 | "maintenance" 145 | ] 146 | }, 147 | { 148 | "login": "OrKoN", 149 | "name": "Alex Rudenko", 150 | "avatar_url": "https://avatars.githubusercontent.com/u/399150?v=4", 151 | "profile": "https://alex-rudenko.com/", 152 | "contributions": ["code"] 153 | }, 154 | { 155 | "login": "Richienb", 156 | "name": "Richie Bendall", 157 | "avatar_url": "https://avatars.githubusercontent.com/u/29491356?v=4", 158 | "profile": "https://richienb.github.io/", 159 | "contributions": ["code", "maintenance"] 160 | }, 161 | { 162 | "login": "ritikbanger", 163 | "name": "Ritik Banger", 164 | "avatar_url": "https://avatars.githubusercontent.com/u/47841501?v=4", 165 | "profile": "https://thetechinfinite.com/", 166 | "contributions": ["code"] 167 | }, 168 | { 169 | "login": "roopakv", 170 | "name": "Roopak Venkatakrishnan", 171 | "avatar_url": "https://avatars.githubusercontent.com/u/678239?v=4", 172 | "profile": "https://roopakv.com/", 173 | "contributions": ["code"] 174 | }, 175 | { 176 | "login": "shivkanthb", 177 | "name": "Shivkanth Bagavathy", 178 | "avatar_url": "https://avatars.githubusercontent.com/u/3232159?v=4", 179 | "profile": "https://shivkanth.com/", 180 | "contributions": ["code"] 181 | }, 182 | { 183 | "login": "sidbatra", 184 | "name": "Siddharth Batra", 185 | "avatar_url": "https://avatars.githubusercontent.com/u/622674?v=4", 186 | "profile": "http://siddharthbatra.com/", 187 | "contributions": ["code"] 188 | }, 189 | { 190 | "login": "smeijer", 191 | "name": "Stephan Meijer", 192 | "avatar_url": "https://avatars.githubusercontent.com/u/1196524?v=4", 193 | "profile": "https://github.com/smeijer", 194 | "contributions": ["code"] 195 | }, 196 | { 197 | "login": "tgbtyty", 198 | "name": "tgbtyty", 199 | "avatar_url": "https://avatars.githubusercontent.com/u/10119245?v=4", 200 | "profile": "https://github.com/tgbtyty", 201 | "contributions": ["code"] 202 | }, 203 | { 204 | "login": "Thomas101", 205 | "name": "Thomas Beverley", 206 | "avatar_url": "https://avatars.githubusercontent.com/u/103586?v=4", 207 | "profile": "https://github.com/Thomas101", 208 | "contributions": ["bug"] 209 | }, 210 | { 211 | "login": "timruffles", 212 | "name": "Tim Ruffles", 213 | "avatar_url": "https://avatars.githubusercontent.com/u/249800?v=4", 214 | "profile": "https://timr.co/", 215 | "contributions": ["code"] 216 | }, 217 | { 218 | "login": "toddmazierski", 219 | "name": "Todd Mazierski", 220 | "avatar_url": "https://avatars.githubusercontent.com/u/544541?v=4", 221 | "profile": "https://toddmazierski.com/", 222 | "contributions": ["bug"] 223 | }, 224 | { 225 | "login": "watadarkstar", 226 | "name": "Adrian Carolli", 227 | "avatar_url": "https://avatars.githubusercontent.com/u/3059371?v=4", 228 | "profile": "https://adriancarolli.surge.sh/", 229 | "contributions": ["code"] 230 | }, 231 | { 232 | "login": "wtgtybhertgeghgtwtg", 233 | "name": "wtgtybhertgeghgtwtg", 234 | "avatar_url": "https://avatars.githubusercontent.com/u/18507762?v=4", 235 | "profile": "https://github.com/wtgtybhertgeghgtwtg", 236 | "contributions": ["code"] 237 | } 238 | ], 239 | "contributorsPerLine": 7, 240 | "contributorsSortAlphabetically": true, 241 | "files": ["README.md"], 242 | "imageSize": 100, 243 | "projectName": "node-emoji", 244 | "projectOwner": "omnidan", 245 | "repoHost": "https://github.com", 246 | "repoType": "github" 247 | } 248 | 249 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | !.* 2 | coverage 3 | lib 4 | node_modules 5 | pnpm-lock.yaml 6 | tea.yaml 7 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import("@types/eslint").Linter.Config} */ 2 | module.exports = { 3 | env: { 4 | es2022: true, 5 | node: true, 6 | }, 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:eslint-comments/recommended', 10 | 'plugin:n/recommended', 11 | 'plugin:perfectionist/recommended-natural', 12 | 'plugin:regexp/recommended', 13 | 'plugin:vitest/recommended', 14 | ], 15 | overrides: [ 16 | { 17 | extends: ['plugin:markdown/recommended'], 18 | files: ['**/*.md'], 19 | processor: 'markdown/markdown', 20 | }, 21 | { 22 | extends: [ 23 | 'plugin:jsdoc/recommended-typescript-error', 24 | 'plugin:@typescript-eslint/strict', 25 | 'plugin:@typescript-eslint/stylistic', 26 | ], 27 | files: ['**/*.ts'], 28 | parser: '@typescript-eslint/parser', 29 | rules: { 30 | // These off-by-default rules work well for this repo and we like them on. 31 | 'jsdoc/informative-docs': 'error', 32 | 'logical-assignment-operators': [ 33 | 'error', 34 | 'always', 35 | { enforceForIfStatements: true }, 36 | ], 37 | 'operator-assignment': 'error', 38 | 39 | // These on-by-default rules don't work well for this repo and we like them off. 40 | 'jsdoc/require-jsdoc': 'off', 41 | 'jsdoc/require-param': 'off', 42 | 'jsdoc/require-property': 'off', 43 | 'jsdoc/require-returns': 'off', 44 | }, 45 | }, 46 | { 47 | files: '**/*.md/*.*s', 48 | rules: { 49 | 'n/no-missing-import': ['error', { allowModules: ['node-emoji'] }], 50 | }, 51 | }, 52 | { 53 | excludedFiles: ['**/*.md/*.ts'], 54 | extends: [ 55 | 'plugin:@typescript-eslint/strict-type-checked', 56 | 'plugin:@typescript-eslint/stylistic-type-checked', 57 | ], 58 | files: ['**/*.ts'], 59 | parser: '@typescript-eslint/parser', 60 | parserOptions: { 61 | project: './tsconfig.eslint.json', 62 | }, 63 | rules: { 64 | // These off-by-default rules work well for this repo and we like them on. 65 | 'deprecation/deprecation': 'error', 66 | }, 67 | }, 68 | { 69 | excludedFiles: ['package.json'], 70 | extends: ['plugin:jsonc/recommended-with-json'], 71 | files: ['*.json', '*.jsonc'], 72 | parser: 'jsonc-eslint-parser', 73 | rules: { 74 | 'jsonc/sort-keys': 'error', 75 | }, 76 | }, 77 | { 78 | files: ['*.jsonc'], 79 | rules: { 80 | 'jsonc/no-comments': 'off', 81 | }, 82 | }, 83 | { 84 | files: '**/*.test.ts', 85 | rules: { 86 | // These on-by-default rules aren't useful in test files. 87 | '@typescript-eslint/no-unsafe-assignment': 'off', 88 | '@typescript-eslint/no-unsafe-call': 'off', 89 | }, 90 | }, 91 | { 92 | extends: ['plugin:yml/standard', 'plugin:yml/prettier'], 93 | files: ['**/*.{yml,yaml}'], 94 | parser: 'yaml-eslint-parser', 95 | rules: { 96 | 'yml/file-extension': ['error', { extension: 'yml' }], 97 | 'yml/sort-keys': [ 98 | 'error', 99 | { 100 | order: { type: 'asc' }, 101 | pathPattern: '^.*$', 102 | }, 103 | ], 104 | 'yml/sort-sequence-values': [ 105 | 'error', 106 | { 107 | order: { type: 'asc' }, 108 | pathPattern: '^.*$', 109 | }, 110 | ], 111 | }, 112 | }, 113 | ], 114 | parser: '@typescript-eslint/parser', 115 | plugins: [ 116 | '@typescript-eslint', 117 | 'deprecation', 118 | 'jsdoc', 119 | 'no-only-tests', 120 | 'perfectionist', 121 | 'regexp', 122 | 'vitest', 123 | ], 124 | reportUnusedDisableDirectives: true, 125 | root: true, 126 | rules: { 127 | // These off/less-strict-by-default rules work well for this repo and we like them on. 128 | '@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'all' }], 129 | 'no-only-tests/no-only-tests': 'error', 130 | 131 | // These on-by-default rules don't work well for this repo and we like them off. 132 | 'no-case-declarations': 'off', 133 | 'no-constant-condition': 'off', 134 | 'no-inner-declarations': 'off', 135 | 'no-mixed-spaces-and-tabs': 'off', 136 | 137 | // Stylistic concerns that don't interfere with Prettier 138 | '@typescript-eslint/padding-line-between-statements': [ 139 | 'error', 140 | { blankLine: 'always', next: '*', prev: 'block-like' }, 141 | ], 142 | 'no-useless-rename': 'error', 143 | 'object-shorthand': 'error', 144 | 'perfectionist/sort-objects': [ 145 | 'error', 146 | { 147 | order: 'asc', 148 | 'partition-by-comment': true, 149 | type: 'natural', 150 | }, 151 | ], 152 | }, 153 | } 154 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | - Demonstrating empathy and kindness toward other people 21 | - Being respectful of differing opinions, viewpoints, and experiences 22 | - Giving and gracefully accepting constructive feedback 23 | - Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | - Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | - The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | - Trolling, insulting or derogatory comments, and personal or political attacks 33 | - Public or private harassment 34 | - Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | - Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | me@omnidan.net. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series of 86 | actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or permanent 93 | ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within the 113 | community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.1, available at 119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder][mozilla coc]. 123 | 124 | For answers to common questions about this code of conduct, see the FAQ at 125 | [https://www.contributor-covenant.org/faq][faq]. Translations are available at 126 | [https://www.contributor-covenant.org/translations][translations]. 127 | 128 | [homepage]: https://www.contributor-covenant.org 129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 130 | [mozilla coc]: https://github.com/mozilla/diversity 131 | [faq]: https://www.contributor-covenant.org/faq 132 | [translations]: https://www.contributor-covenant.org/translations 133 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for your interest in contributing to `node-emoji`! 💖 4 | 5 | > After this page, see [DEVELOPMENT.md](./DEVELOPMENT.md) for local development instructions. 6 | 7 | ## Code of Conduct 8 | 9 | This project contains a [Contributor Covenant code of conduct](./CODE_OF_CONDUCT.md) all contributors are expected to follow. 10 | 11 | ## Reporting Issues 12 | 13 | Please do [report an issue on the issue tracker](https://github.com/omnidan/node-emoji/issues/new/choose) if there's any bugfix, documentation improvement, or general enhancement you'd like to see in the repository! Please fully fill out all required fields in the most appropriate issue form. 14 | 15 | ## Sending Contributions 16 | 17 | Sending your own changes as contribution is always appreciated! 18 | There are two steps involved: 19 | 20 | 1. [Finding an Issue](#finding-an-issue) 21 | 2. [Sending a Pull Request](#sending-a-pull-request) 22 | 23 | ### Finding an Issue 24 | 25 | With the exception of very small typos, all changes to this repository generally need to correspond to an [unassigned open issue marked as `status: accepting prs` on the issue tracker](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue+is%3Aopen+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 26 | If this is your first time contributing, consider searching for [unassigned issues that also have the `good first issue` label](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3A%22status%3A+accepting+prs%22+no%3Aassignee+). 27 | If the issue you'd like to fix isn't found on the issue, see [Reporting Issues](#reporting-issues) for filing your own (please do!). 28 | 29 | #### Issue Claiming 30 | 31 | We don't use any kind of issue claiming system. 32 | We've found in the past that they result in accidental ["licked cookie"](https://devblogs.microsoft.com/oldnewthing/20091201-00/?p=15843) situations where contributors claim an issue but run out of time or energy trying before sending a PR. 33 | 34 | If an unassigned issue has been marked as `status: accepting prs` and an open PR does not exist, feel free to send a PR. 35 | Please don't post comments asking for permission or stating you will work on an issue. 36 | 37 | ### Sending a Pull Request 38 | 39 | Once you've identified an open issue accepting PRs that doesn't yet have a PR sent, you're free to send a pull request. 40 | Be sure to fill out the pull request template's requested information -- otherwise your PR will likely be closed. 41 | 42 | PRs are also expected to have a title that adheres to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0). 43 | Only PR titles need to be in that format, not individual commits. 44 | Don't worry if you get this wrong: you can always change the PR title after sending it. 45 | Check [previously merged PRs](https://github.com/omnidan/node-emoji/pulls?q=is%3Apr+is%3Amerged+-label%3Adependencies+) for reference. 46 | 47 | #### Draft PRs 48 | 49 | If you don't think your PR is ready for review, [set it as a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft). 50 | Draft PRs won't be reviewed. 51 | 52 | #### Granular PRs 53 | 54 | Please keep pull requests single-purpose: in other words, don't attempt to solve multiple unrelated problems in one pull request. 55 | Send one PR per area of concern. 56 | Multi-purpose pull requests are harder and slower to review, block all changes from being merged until the whole pull request is reviewed, and are difficult to name well with semantic PR titles. 57 | 58 | #### Pull Request Reviews 59 | 60 | When a PR is not in draft, it's considered ready for review. 61 | Please don't manually `@` tag anybody to request review. 62 | A maintainer will look at it when they're next able to. 63 | 64 | PRs should have passing [GitHub status checks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks) before review is requested (unless there are explicit questions asked in the PR about any failures). 65 | 66 | #### Asking Questions 67 | 68 | If you need help and/or have a question, posting a comment in the PR is a great way to do so. 69 | There's no need to tag anybody individually. 70 | One of us will drop by and help when we can. 71 | 72 | Please post comments as [line comments](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#adding-line-comments-to-a-pull-request) when possible, so that they can be threaded. 73 | You can [resolve conversations](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations) on your own when you feel they're resolved - no need to comment explicitly and/or wait for a maintainer. 74 | 75 | #### Requested Changes 76 | 77 | After a maintainer reviews your PR, they may request changes on it. 78 | Once you've made those changes, [re-request review on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review). 79 | 80 | Please try not to force-push commits to PRs that have already been reviewed. 81 | Doing so makes it harder to review the changes. 82 | We squash merge all commits so there's no need to try to preserve Git history within a PR branch. 83 | 84 | Once you've addressed all our feedback by making code changes and/or started a followup discussion, [re-request review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review) from each maintainer whose feedback you addressed. 85 | 86 | Once all feedback is addressed and the PR is approved, we'll ensure the branch is up to date with `main` and merge it for you. 87 | 88 | #### Post-Merge Recognition 89 | 90 | Once your PR is merged, if you haven't yet been added to the [_Contributors_ table in the README.md](../README.md#contributors) for its [type of contribution](https://allcontributors.org/docs/en/emoji-key 'Allcontributors emoji key'), you should be soon. 91 | Please do ping the maintainer who merged your PR if that doesn't happen within 24 hours - it was likely an oversight on our end! 92 | 93 | ## Emojis & Appreciation 94 | 95 | If you made it all the way to the end, bravo dear user, we love you. 96 | Please include your favorite emoji in the bottom of your issues and PRs to signal to us that you did in fact read this file and are trying to conform to it as best as possible. 97 | 💖 is a good starter if you're not sure which to use. 98 | -------------------------------------------------------------------------------- /.github/Development.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation): 4 | 5 | ```shell 6 | git clone https://github.com//node-emoji 7 | cd node-emoji 8 | pnpm install 9 | ``` 10 | 11 | > This repository includes a list of suggested VS Code extensions. 12 | > It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development. 13 | 14 | ## Building 15 | 16 | Run [**tsup**](https://tsup.egoist.dev) locally to build source files from `src/` into output files in `lib/`: 17 | 18 | ```shell 19 | pnpm build 20 | ``` 21 | 22 | Add `--watch` to run the builder in a watch mode that continuously cleans and recreates `lib/` as you save files: 23 | 24 | ```shell 25 | pnpm build --watch 26 | ``` 27 | 28 | ## Formatting 29 | 30 | [Prettier](https://prettier.io) is used to format code. 31 | It should be applied automatically when you save files in VS Code or make a Git commit. 32 | 33 | To manually reformat all files, you can run: 34 | 35 | ```shell 36 | pnpm format --write 37 | ``` 38 | 39 | ## Linting 40 | 41 | This package includes several forms of linting to enforce consistent code quality and styling. 42 | Each should be shown in VS Code, and can be run manually on the command-line: 43 | 44 | - `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files 45 | - `pnpm lint:knip` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports 46 | - `pnpm lint:md` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files 47 | - `pnpm lint:package-json` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the `package.json` file 48 | - `pnpm lint:packages` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the `pnpm-lock.yml` file 49 | - `pnpm lint:spelling` ([cspell](https://cspell.org)): Spell checks across all source files 50 | 51 | Read the individual documentation for each linter to understand how it can be configured and used best. 52 | 53 | For example, ESLint can be run with `--fix` to auto-fix some lint rule complaints: 54 | 55 | ```shell 56 | pnpm run lint --fix 57 | ``` 58 | 59 | ## Testing 60 | 61 | [Vitest](https://vitest.dev) is used for tests. 62 | You can run it locally on the command-line: 63 | 64 | ```shell 65 | pnpm run test 66 | ``` 67 | 68 | Add the `--coverage` flag to compute test coverage and place reports in the `coverage/` directory: 69 | 70 | ```shell 71 | pnpm run test --coverage 72 | ``` 73 | 74 | Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. 75 | Calls to `console.log`, `console.warn`, and other console methods will cause a test to fail. 76 | 77 | ### Debugging Tests 78 | 79 | This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests. 80 | To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5). 81 | 82 | ## Type Checking 83 | 84 | You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files. 85 | 86 | However, it can be useful to run the TypeScript command-line (`tsc`) to type check all files in `src/`: 87 | 88 | ```shell 89 | pnpm tsc 90 | ``` 91 | 92 | Add `--watch` to keep the type checker running in a watch mode that updates the display as you save files: 93 | 94 | ```shell 95 | pnpm tsc --watch 96 | ``` 97 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: omnidan 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ## Overview 8 | 9 | ... 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/01-bug.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have tried restarting my IDE and the issue persists. 7 | required: true 8 | - label: I have pulled the latest `main` branch of the repository. 9 | required: true 10 | - label: I have [searched for related issues](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue) and found none that matched my issue. 11 | required: true 12 | type: checkboxes 13 | - attributes: 14 | description: What did you expect to happen? 15 | label: Expected 16 | type: textarea 17 | validations: 18 | required: true 19 | - attributes: 20 | description: What happened instead? 21 | label: Actual 22 | type: textarea 23 | validations: 24 | required: true 25 | - attributes: 26 | description: Any additional info you'd like to provide. 27 | label: Additional Info 28 | type: textarea 29 | description: Report a bug trying to run the code 30 | labels: 31 | - 'type: bug' 32 | name: 🐛 Bug 33 | title: '🐛 Bug: ' 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/02-documentation.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have pulled the latest `main` branch of the repository. 7 | required: true 8 | - label: I have [searched for related issues](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue) and found none that matched my issue. 9 | required: true 10 | type: checkboxes 11 | - attributes: 12 | description: What would you like to report? 13 | label: Overview 14 | type: textarea 15 | validations: 16 | required: true 17 | - attributes: 18 | description: Any additional info you'd like to provide. 19 | label: Additional Info 20 | type: textarea 21 | description: Report a typo or missing area of documentation 22 | labels: 23 | - 'area: documentation' 24 | name: 📝 Documentation 25 | title: '📝 Documentation: ' 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/03-feature.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I am using the latest version of the package 7 | required: true 8 | - label: I have [searched for related issues](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue) and found none that matched my issue. 9 | required: true 10 | type: checkboxes 11 | - attributes: 12 | description: What did you expect to be able to do? 13 | label: Overview 14 | type: textarea 15 | validations: 16 | required: true 17 | - attributes: 18 | description: Any additional info you'd like to provide. 19 | label: Additional Info 20 | type: textarea 21 | description: Request that a new feature be added or an existing feature improved 22 | labels: 23 | - 'type: feature' 24 | name: 🚀 Feature 25 | title: '🚀 Feature: ' 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/04-tooling.yml: -------------------------------------------------------------------------------- 1 | body: 2 | - attributes: 3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! 4 | label: Bug Report Checklist 5 | options: 6 | - label: I have tried restarting my IDE and the issue persists. 7 | required: true 8 | - label: I have pulled the latest `main` branch of the repository. 9 | required: true 10 | - label: I have [searched for related issues](https://github.com/omnidan/node-emoji/issues?q=is%3Aissue) and found none that matched my issue. 11 | required: true 12 | type: checkboxes 13 | - attributes: 14 | description: What did you expect to be able to do? 15 | label: Overview 16 | type: textarea 17 | validations: 18 | required: true 19 | - attributes: 20 | description: Any additional info you'd like to provide. 21 | label: Additional Info 22 | type: textarea 23 | description: Report a bug or request an enhancement in repository tooling 24 | labels: 25 | - 'area: tooling' 26 | name: 🛠 Tooling 27 | title: '🛠 Tooling: ' 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | ## PR Checklist 6 | 7 | - [ ] Addresses an existing open issue: fixes #000 8 | - [ ] That issue was marked as [`status: accepting prs`](https://github.com/omnidan/node-emoji/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) 9 | - [ ] Steps in [CONTRIBUTING.md](https://github.com/omnidan/node-emoji/blob/main/.github/CONTRIBUTING.md) were taken 10 | 11 | ## Overview 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | We take all security vulnerabilities seriously. 4 | If you have a vulnerability or other security issues to disclose: 5 | 6 | - Thank you very much, please do! 7 | - Please send them to us by emailing `me@omnidan.net` 8 | 9 | We appreciate your efforts and responsible disclosure and will make every effort to acknowledge your contributions. 10 | -------------------------------------------------------------------------------- /.github/actions/prepare/action.yml: -------------------------------------------------------------------------------- 1 | description: Prepares the repo for a typical CI job 2 | 3 | name: Prepare 4 | 5 | runs: 6 | steps: 7 | - uses: pnpm/action-setup@v2 8 | - uses: actions/setup-node@v4 9 | with: 10 | cache: pnpm 11 | node-version: '18' 12 | - run: pnpm install --frozen-lockfile 13 | shell: bash 14 | using: composite 15 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": false 3 | } 4 | -------------------------------------------------------------------------------- /.github/workflows/accessibility-alt-text-bot.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | accessibility_alt_text_bot: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: github/accessibility-alt-text-bot@v1.7.1 6 | 7 | name: Accessibility Alt Text Bot 8 | 9 | on: 10 | issue_comment: 11 | types: 12 | - created 13 | - edited 14 | issues: 15 | types: 16 | - edited 17 | - opened 18 | pull_request: 19 | types: 20 | - edited 21 | - opened 22 | 23 | permissions: 24 | issues: write 25 | pull-requests: write 26 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm build 8 | - run: node ./lib/index.js 9 | 10 | name: Build 11 | 12 | on: 13 | pull_request: ~ 14 | push: 15 | branches: 16 | - main 17 | -------------------------------------------------------------------------------- /.github/workflows/compliance.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | compliance: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: mtfoley/pr-compliance-action@main 6 | with: 7 | body-auto-close: false 8 | ignore-authors: |- 9 | allcontributors 10 | allcontributors[bot] 11 | renovate 12 | renovate[bot] 13 | ignore-team-members: false 14 | 15 | name: Compliance 16 | 17 | on: 18 | pull_request: 19 | branches: 20 | - main 21 | types: 22 | - edited 23 | - opened 24 | - reopened 25 | - synchronize 26 | 27 | permissions: 28 | pull-requests: write 29 | -------------------------------------------------------------------------------- /.github/workflows/contributors.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | contributors: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | with: 7 | fetch-depth: 0 8 | - uses: ./.github/actions/prepare 9 | - env: 10 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} 11 | uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0 12 | 13 | name: Contributors 14 | 15 | on: 16 | push: 17 | branches: 18 | - main 19 | -------------------------------------------------------------------------------- /.github/workflows/lint-knip.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint_knip: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm lint:knip 8 | 9 | name: Lint Knip 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/lint-markdown.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint_markdown: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm lint:md 8 | 9 | name: Lint Markdown 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/lint-package-json.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint_package_json: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm lint:package-json 8 | 9 | name: Lint Package JSON 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/lint-packages.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint_packages: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm lint:packages 8 | 9 | name: Lint Packages 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/lint-spelling.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint_spelling: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm lint:spelling 8 | 9 | name: Lint spelling 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | lint: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm build 8 | - run: pnpm lint 9 | 10 | name: Lint 11 | 12 | on: 13 | pull_request: ~ 14 | push: 15 | branches: 16 | - main 17 | -------------------------------------------------------------------------------- /.github/workflows/post-release.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | post_release: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | with: 7 | fetch-depth: 0 8 | - run: echo "npm_version=$(npm pkg get version | tr -d '"')" >> "$GITHUB_ENV" 9 | - uses: apexskier/github-release-commenter@v1 10 | with: 11 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 12 | comment-template: | 13 | :tada: This is included in version {release_link} :tada: 14 | 15 | The release is available on: 16 | 17 | * [GitHub releases](https://github.com/omnidan/node-emoji/releases/tag/{release_tag}) 18 | * [npm package (@latest dist-tag)](https://www.npmjs.com/package/node-emoji/v/${{ env.npm_version }}) 19 | 20 | Cheers! 📦🚀 21 | 22 | name: Post Release 23 | 24 | on: 25 | release: 26 | types: 27 | - published 28 | -------------------------------------------------------------------------------- /.github/workflows/pr-review-requested.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | pr_review_requested: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions-ecosystem/action-remove-labels@v1 6 | with: 7 | labels: 'status: waiting for author' 8 | - if: failure() 9 | run: | 10 | echo "Don't worry if the previous step failed." 11 | echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221." 12 | 13 | name: PR Review Requested 14 | 15 | on: 16 | pull_request_target: 17 | types: 18 | - review_requested 19 | 20 | permissions: 21 | pull-requests: write 22 | -------------------------------------------------------------------------------- /.github/workflows/prettier.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | prettier: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm format --list-different 8 | 9 | name: Prettier 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | concurrency: 2 | group: ${{ github.workflow }} 3 | 4 | jobs: 5 | release: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v4 9 | with: 10 | fetch-depth: 0 11 | ref: main 12 | - uses: ./.github/actions/prepare 13 | - run: pnpm build 14 | - env: 15 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} 16 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 17 | uses: JoshuaKGoldberg/release-it-action@v0.3.1 18 | 19 | name: Release 20 | 21 | on: 22 | push: 23 | branches: 24 | - main 25 | 26 | permissions: 27 | contents: write 28 | id-token: write 29 | -------------------------------------------------------------------------------- /.github/workflows/test-cjs.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | test: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm build 8 | - run: pnpm run test:cjs 9 | 10 | name: Test CommonJS 11 | 12 | on: 13 | pull_request: ~ 14 | push: 15 | branches: 16 | - main 17 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | test: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm run test --coverage 8 | - name: Codecov 9 | uses: codecov/codecov-action@v5 10 | 11 | name: Test 12 | 13 | on: 14 | pull_request: ~ 15 | push: 16 | branches: 17 | - main 18 | -------------------------------------------------------------------------------- /.github/workflows/tsc.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | type_check: 3 | runs-on: ubuntu-latest 4 | steps: 5 | - uses: actions/checkout@v4 6 | - uses: ./.github/actions/prepare 7 | - run: pnpm tsc 8 | 9 | name: Type Check 10 | 11 | on: 12 | pull_request: ~ 13 | push: 14 | branches: 15 | - main 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | lib/ 3 | node_modules/ 4 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | npx lint-staged 4 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "markdownlint/style/prettier", 3 | "first-line-h1": false, 4 | "no-inline-html": false 5 | } 6 | -------------------------------------------------------------------------------- /.markdownlintignore: -------------------------------------------------------------------------------- 1 | .github/CODE_OF_CONDUCT.md 2 | CHANGELOG.md 3 | lib/ 4 | node_modules/ 5 | -------------------------------------------------------------------------------- /.npmpackagejsonlintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "npm-package-json-lint-config-default", 3 | "rules": { "require-description": "error", "require-license": "error" } 4 | } 5 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 22.13.1 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .all-contributorsrc 2 | coverage/ 3 | lib/ 4 | pnpm-lock.yaml 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/prettierrc", 3 | "overrides": [ 4 | { "files": ".*rc", "options": { "parser": "json" } }, 5 | { "files": ".nvmrc", "options": { "parser": "yaml" } } 6 | ], 7 | "plugins": ["prettier-plugin-curly", "prettier-plugin-packagejson"], 8 | "arrowParens": "avoid", 9 | "semi": false, 10 | "singleQuote": true 11 | } 12 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "git": { 3 | "commitMessage": "chore: release v${version}", 4 | "requireCommits": true 5 | }, 6 | "github": { 7 | "autoGenerate": true, 8 | "release": true, 9 | "releaseName": "v${version}" 10 | }, 11 | "npm": { "publishArgs": ["--access public", "--provenance"] }, 12 | "plugins": { 13 | "@release-it/conventional-changelog": { 14 | "infile": "CHANGELOG.md", 15 | "preset": "angular" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "DavidAnson.vscode-markdownlint", 4 | "dbaeumer.vscode-eslint", 5 | "esbenp.prettier-vscode", 6 | "streetsidesoftware.code-spell-checker" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "args": ["run", "${relativeFile}"], 5 | "autoAttachChildProcesses": true, 6 | "console": "integratedTerminal", 7 | "name": "Debug Current Test File", 8 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", 9 | "request": "launch", 10 | "skipFiles": ["/**", "**/node_modules/**"], 11 | "smartStep": true, 12 | "type": "node" 13 | } 14 | ], 15 | "version": "0.2.0" 16 | } 17 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, 3 | "editor.defaultFormatter": "esbenp.prettier-vscode", 4 | "editor.formatOnSave": true, 5 | "editor.rulers": [80], 6 | "eslint.probe": [ 7 | "javascript", 8 | "javascriptreact", 9 | "json", 10 | "jsonc", 11 | "markdown", 12 | "typescript", 13 | "typescriptreact", 14 | "yaml" 15 | ], 16 | "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }], 17 | "typescript.tsdk": "node_modules/typescript/lib" 18 | } 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [2.2.0](https://github.com/omnidan/node-emoji/compare/v2.1.3...v2.2.0) (2024-12-03) 2 | 3 | ### Features 4 | 5 | - allow RegExp objects to be passed to search that are evaluated for each emoji ([7046cbb](https://github.com/omnidan/node-emoji/commit/7046cbbdda4282b9503ea10c7ac632f39bba74bd)) 6 | 7 | ## [2.1.3](https://github.com/omnidan/node-emoji/compare/v2.1.2...v2.1.3) (2023-11-20) 8 | 9 | ### Bug Fixes 10 | 11 | - pin skin-tone to ^2.0.0 and add renovate.json ignoreDeps ([dcd6c43](https://github.com/omnidan/node-emoji/commit/dcd6c43f26b6537fb770b5309574c3e1ff3859c1)) 12 | 13 | ## [2.1.2](https://github.com/omnidan/node-emoji/compare/v2.1.1...v2.1.2) (2023-11-20) 14 | 15 | ### Bug Fixes 16 | 17 | - add back CJS support, with a test ([e2856d9](https://github.com/omnidan/node-emoji/commit/e2856d980d1e9335d5e62c7de25c1d22e6956584)) 18 | 19 | ## [2.1.1](https://github.com/omnidan/node-emoji/compare/v2.1.0...v2.1.1) (2023-11-18) 20 | 21 | ### Bug Fixes 22 | 23 | - underlines in README.md badges ([05e30ae](https://github.com/omnidan/node-emoji/commit/05e30aed2d9b6fdf2af7aba7ac44d396e3797869)) 24 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2014-2023 Daniel Bugl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

node-emoji

2 | 3 |

Friendly emoji lookups and parsing utilities for Node.js. 💖

4 | 5 |

6 | 7 | 8 | All Contributors: 32 👪 9 | 10 | 11 | Codecov Test Coverage 12 | Contributor Covenant 13 | License: MIT 14 | Sponsor: On GitHub 15 | Style: Prettier 16 | TypeScript: Strict 17 | npm package version 18 | Contributor Covenant 19 |

20 | 21 | `node-emoji` provides a fun, straightforward interface on top of the following excellent libraries: 22 | 23 | - [`emojilib`](https://npmjs.org/package/emojilib): provides a list of emojis and keyword search on top of it 24 | - [`skin-tone`](https://npmjs.org/package/skin-tone): parses out base emojis from skin tones 25 | 26 | ## Install 27 | 28 | ```sh 29 | npm install node-emoji 30 | ``` 31 | 32 | ### 2.0 Release 🚀 33 | 34 | This is the new 2.0 release of node-emoji, supporting ESM, new emoji and a new API. 35 | 36 | If you want to use the old version, please check out the [legacy branch](https://github.com/omnidan/node-emoji/tree/legacy). 37 | 38 | ## Usage 39 | 40 | ```js 41 | import * as emoji from 'node-emoji' 42 | 43 | emoji.emojify('I :heart: :coffee:!') // 'I ❤️ ☕️!' 44 | 45 | emoji.find('heart') // { emoji: '❤', name: 'heart' } 46 | emoji.find('❤️') // { emoji: '❤', name: 'heart' } 47 | 48 | emoji.get('unicorn') // 🦄 49 | emoji.get(':unicorn:') // 🦄 50 | 51 | emoji.has(':pizza:') // true 52 | emoji.has('🍕') // true 53 | emoji.has('unknown') // false 54 | 55 | emoji.random() // { name: 'house', emoji: '🏠' } 56 | 57 | emoji.replace('I ❤️ coffee!', 'love', { preserveSpaces: true }) // 'I love coffee!' 58 | 59 | emoji.search(':uni:') // [ { emoji: '🦄', name: 'unicorn' }, ... ] 60 | 61 | emoji.strip('I ❤️ coffee!') // 'I coffee!' 62 | 63 | emoji.unemojify('🍕 for 💃') // ':pizza: for :dancer:' 64 | 65 | emoji.which('🦄') // 'unicorn' 66 | ``` 67 | 68 | ## API 69 | 70 | ### emoji.emojify(input, options?) 71 | 72 | Parse all markdown-encoded emojis in a string. 73 | 74 | Parameters: 75 | 76 | 1. **`input`** (`string`): The input string containing the markdown-encoding emojis. 77 | 1. **`options`** _(optional)_: 78 | - **`fallback`** (`string`; default: `""`): The string to fallback to if an emoji was not found. 79 | - **`format`** (`() => (emoji: string, part: string, string: string) => string`; default: `value => value`): Add a middleware layer to modify each matched emoji after parsing. 80 | 81 | ```js 82 | import * as emoji from 'node-emoji' 83 | 84 | console.log(emoji.emojify('The :unicorn: is a fictitious animal.')) 85 | // 'The 🦄 is a fictitious animal.' 86 | ``` 87 | 88 | ### emoji.find(emoji) 89 | 90 | Get the name and character of an emoji. 91 | 92 | Parameters: 93 | 94 | 1. **`emoji`** (`string`): The emoji to get the data of. 95 | 96 | ```js 97 | import * as emoji from 'node-emoji' 98 | 99 | console.log(emoji.find('🦄')) 100 | // { name: 'unicorn', emoji: '🦄' } 101 | ``` 102 | 103 | ### emoji.get(name) 104 | 105 | Get an emoji from an emoji name. 106 | 107 | Parameters: 108 | 109 | 1. **`name`** (`string`): The name of the emoji to get. 110 | 111 | ```js 112 | import * as emoji from 'node-emoji' 113 | 114 | console.log(emoji.get('unicorn')) 115 | // '🦄' 116 | ``` 117 | 118 | ### emoji.has(emoji) 119 | 120 | Check if this library supports a specific emoji. 121 | 122 | Parameters: 123 | 124 | 1. **`emoji`** (`string`): The emoji to check. 125 | 126 | ```js 127 | import * as emoji from 'node-emoji' 128 | 129 | console.log(emoji.has('🦄')) 130 | // true 131 | ``` 132 | 133 | ### emoji.random() 134 | 135 | Get a random emoji. 136 | 137 | ```js 138 | import * as emoji from 'node-emoji' 139 | 140 | console.log(emoji.random()) 141 | // { name: 'unicorn', emoji: '🦄' } 142 | ``` 143 | 144 | ### emoji.replace(input, replacement) 145 | 146 | Replace the emojis in a string. 147 | 148 | Parameters: 149 | 150 | - **`input`** (`string`): The input string. 151 | - **`replacement`** (`string | (emoji: string, index: number, string: string) => string`): The character to replace the emoji with. 152 | Can be either a string or a callback that returns a string. 153 | 154 | ```js 155 | import * as emoji from 'node-emoji' 156 | 157 | console.log(emoji.replace('The 🦄 is a fictitious animal.', 'unicorn')) 158 | // 'The unicorn is a fictitious animal.' 159 | ``` 160 | 161 | ### emoji.search(keyword) 162 | 163 | Search for emojis containing the provided name in their name. 164 | 165 | Parameters: 166 | 167 | 1. **`keyword`** (`string`): The keyword to search for. 168 | 169 | ```js 170 | import * as emoji from 'node-emoji' 171 | 172 | console.log(emoji.search('honey')) 173 | // [ { name: 'honeybee', emoji: '🐝' }, { name: 'honey_pot', emoji: '🍯' } ] 174 | ``` 175 | 176 | ### emoji.strip(input, options?) 177 | 178 | Remove all of the emojis from a string. 179 | 180 | Parameters: 181 | 182 | 1. **`input`** (`string`): The input string to strip the emojis from. 183 | 1. **`options`** _(optional)_: 184 | 185 | - **`preserveSpaces`** (`boolean`): Whether to keep the extra space after a stripped emoji. 186 | 187 | ```js 188 | import * as emoji from 'node-emoji' 189 | 190 | console.log(emoji.strip('🦄 The unicorn is a fictitious animal.')) 191 | // 'The unicorn is a fictitious animal.' 192 | 193 | console.log( 194 | emoji.strip('🦄 The unicorn is a fictitious animal.', { 195 | preserveSpaces: true, 196 | }), 197 | ) 198 | // ' The unicorn is a fictitious animal.' 199 | ``` 200 | 201 | ### emoji.unemojify(input) 202 | 203 | Convert all emojis in a string to their markdown-encoded counterparts. 204 | 205 | Parameters: 206 | 207 | 1. **`input`** (`string`): The input string containing the emojis. 208 | 209 | ```js 210 | import * as emoji from 'node-emoji' 211 | 212 | console.log(emoji.unemojify('The 🦄 is a fictitious animal.')) 213 | // 'The :unicorn: is a fictitious animal.' 214 | ``` 215 | 216 | ### emoji.which(emoji, options?) 217 | 218 | Get an emoji name from an emoji. 219 | 220 | Parameters: 221 | 222 | 1. **`emoji`** (`string`): The emoji to get the name of. 223 | 1. **`options`** _(optional)_: 224 | - **`markdown`** (`boolean`; default: `false`): Whether to return a `":emoji:"` string instead of `"emoji"` 225 | 226 | ```js 227 | import * as emoji from 'node-emoji' 228 | 229 | console.log(emoji.which('🦄')) 230 | // 'unicorn' 231 | ``` 232 | 233 | ## Development 234 | 235 | See _[`.github/Development.md`](./github/Development.md)_. 236 | 237 | ## License 238 | 239 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fomnidan%2Fnode-emoji.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fomnidan%2Fnode-emoji?ref=badge_large) 240 | 241 | ### Special Thanks 242 | 243 | ...to Anand Chowdhary (@AnandChowdhary) and his company [Pabio](https://github.com/pabio) for sponsoring this project via [GitHub Sponsors](https://github.com/sponsors/omnidan)! 244 | 245 | ## Contributors 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 |
./c²
./c²

💻
Adam Skoufis
Adam Skoufis

💻
Adrian Carolli
Adrian Carolli

💻
Alex Litel
Alex Litel

💻
Alex Rudenko
Alex Rudenko

💻
Antoine Hanriat
Antoine Hanriat

💻
Daniel Bugl
Daniel Bugl

🐛 💻 🔍 🤔 🚇 🔧 🚧
Daniel Hilton
Daniel Hilton

💻
Elizabeth
Elizabeth

💻 🚧
Gabriel Csapo
Gabriel Csapo

💻
Greenkeeper
Greenkeeper

💻
Josh Goldberg ✨
Josh Goldberg ✨

🔧 💻 🚇 🚧
Kevin Cooper
Kevin Cooper

💻
Kristoffer K.
Kristoffer K.

💻
Ludo Renzetti
Ludo Renzetti

💻
Nicolas Charpentier
Nicolas Charpentier

🚧
Nicolas Gryman
Nicolas Gryman

💻
Paul Barber
Paul Barber

💻
Richie Bendall
Richie Bendall

💻 🚧
Ritik Banger
Ritik Banger

💻
Roopak Venkatakrishnan
Roopak Venkatakrishnan

💻
Shivkanth Bagavathy
Shivkanth Bagavathy

💻
Siddharth Batra
Siddharth Batra

💻
Stephan Meijer
Stephan Meijer

💻
Thomas Beverley
Thomas Beverley

🐛
Tim Ruffles
Tim Ruffles

💻
Todd Mazierski
Todd Mazierski

🐛
fossabot
fossabot

💻
goodjun
goodjun

🐛
jackie luo
jackie luo

💻
tgbtyty
tgbtyty

💻
wtgtybhertgeghgtwtg
wtgtybhertgeghgtwtg

💻
297 | 298 | 299 | 300 | 301 | 302 | 303 | -------------------------------------------------------------------------------- /cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "dictionaries": ["typescript"], 3 | "ignorePaths": [ 4 | ".github", 5 | "CHANGELOG.md", 6 | "coverage", 7 | "lib", 8 | "node_modules", 9 | "pnpm-lock.yaml" 10 | ], 11 | "words": [ 12 | "Anand", 13 | "Bugl", 14 | "Chowdhary", 15 | "Codecov", 16 | "codespace", 17 | "commitlint", 18 | "contributorsrc", 19 | "conventionalcommits", 20 | "couplekiss", 21 | "emojify", 22 | "emojilib", 23 | "knip", 24 | "lcov", 25 | "markdownlintignore", 26 | "npmpackagejsonlintrc", 27 | "omnidan", 28 | "outro", 29 | "Pabio", 30 | "packagejson", 31 | "quickstart", 32 | "sindresorhus", 33 | "smilies", 34 | "tsup", 35 | "unemojify", 36 | "wontfix" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /knip.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/knip@latest/schema.json", 3 | "entry": ["src/index.ts!"], 4 | "ignoreExportsUsedInFile": { "interface": true, "type": true }, 5 | "project": ["src/**/*.ts!"] 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-emoji", 3 | "version": "2.2.0", 4 | "description": "Friendly emoji lookups and parsing utilities for Node.js. 💖", 5 | "keywords": [ 6 | "emoji", 7 | "simple", 8 | "emoticons", 9 | "emoticon", 10 | "emojis", 11 | "smiley", 12 | "smileys", 13 | "smilies", 14 | "ideogram", 15 | "ideograms" 16 | ], 17 | "bugs": { 18 | "url": "https://github.com/omnidan/node-emoji/issues" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/omnidan/node-emoji" 23 | }, 24 | "license": "MIT", 25 | "author": { 26 | "name": "Daniel Bugl", 27 | "email": "me@omnidan.net" 28 | }, 29 | "type": "module", 30 | "exports": { 31 | ".": { 32 | "types": { 33 | "import": "./lib/index.d.ts", 34 | "require": "./lib/index.d.cts" 35 | }, 36 | "import": "./lib/index.js", 37 | "require": "./lib/index.cjs" 38 | } 39 | }, 40 | "main": "./lib/index.js", 41 | "files": [ 42 | "lib/", 43 | "package.json", 44 | "LICENSE.md", 45 | "README.md" 46 | ], 47 | "scripts": { 48 | "build": "tsup", 49 | "format": "prettier \"**/*\" --ignore-unknown", 50 | "lint": "eslint . .*js --max-warnings 0 --report-unused-disable-directives", 51 | "lint:knip": "knip", 52 | "lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line", 53 | "lint:package-json": "npmPkgJsonLint .", 54 | "lint:packages": "pnpm dedupe --check", 55 | "lint:spelling": "cspell \"**\" \".github/**/*\"", 56 | "prepare": "husky install", 57 | "should-semantic-release": "should-semantic-release --verbose", 58 | "test": "vitest", 59 | "test:cjs": "node ./src/e2e.cjs", 60 | "tsc": "tsc" 61 | }, 62 | "lint-staged": { 63 | "*": "prettier --ignore-unknown --write" 64 | }, 65 | "dependencies": { 66 | "@sindresorhus/is": "^4.6.0", 67 | "char-regex": "^1.0.2", 68 | "emojilib": "^2.4.0", 69 | "skin-tone": "^2.0.0" 70 | }, 71 | "devDependencies": { 72 | "@release-it/conventional-changelog": "^10.0.0", 73 | "@swc/core": "^1.3.58", 74 | "@types/eslint": "^8.44.7", 75 | "@typescript-eslint/eslint-plugin": "^6.10.0", 76 | "@typescript-eslint/parser": "^8.0.0", 77 | "@vitest/coverage-v8": "^0.34.6", 78 | "console-fail-test": "^0.5.0", 79 | "cspell": "^8.0.0", 80 | "eslint": "^8.53.0", 81 | "eslint-plugin-deprecation": "^3.0.0", 82 | "eslint-plugin-eslint-comments": "^3.2.0", 83 | "eslint-plugin-jsdoc": "^50.0.0", 84 | "eslint-plugin-jsonc": "^2.10.0", 85 | "eslint-plugin-markdown": "^3.0.1", 86 | "eslint-plugin-n": "^17.0.0", 87 | "eslint-plugin-no-only-tests": "^3.1.0", 88 | "eslint-plugin-perfectionist": "^2.3.0", 89 | "eslint-plugin-regexp": "^2.1.1", 90 | "eslint-plugin-vitest": "^0.3.9", 91 | "eslint-plugin-yml": "^1.10.0", 92 | "husky": "^8.0.3", 93 | "jsonc-eslint-parser": "^2.4.0", 94 | "knip": "^4.0.0", 95 | "lint-staged": "^15.1.0", 96 | "markdownlint": "^0.37.0", 97 | "markdownlint-cli": "^0.44.0", 98 | "npm-package-json-lint": "^8.0.0", 99 | "npm-package-json-lint-config-default": "^7.0.0", 100 | "prettier": "^3.0.3", 101 | "prettier-plugin-curly": "^0.3.0", 102 | "prettier-plugin-packagejson": "^2.4.6", 103 | "release-it": "^18.0.0", 104 | "sentences-per-line": "^0.3.0", 105 | "should-semantic-release": "^0.2.1", 106 | "tsup": "^8.0.0", 107 | "typescript": "^5.2.2", 108 | "vitest": "^0.34.6", 109 | "yaml-eslint-parser": "^1.2.2" 110 | }, 111 | "packageManager": "pnpm@10.2.0", 112 | "engines": { 113 | "node": ">=18" 114 | }, 115 | "publishConfig": { 116 | "provenance": true 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/data.ts: -------------------------------------------------------------------------------- 1 | import emojilib from 'emojilib' 2 | 3 | import { normalizeCode } from './utils.js' 4 | 5 | export interface Emoji { 6 | emoji: string 7 | key: string 8 | } 9 | 10 | export const emojiData = Object.entries(emojilib.lib).map( 11 | ([name, { char: emoji }]) => [name, emoji] as const, 12 | ) 13 | 14 | export const emojiCodesByName = new Map(emojiData) 15 | 16 | export const emojiNamesByCode = new Map( 17 | emojiData.map(([name, emoji]) => [normalizeCode(emoji), name]), 18 | ) 19 | -------------------------------------------------------------------------------- /src/e2e.cjs: -------------------------------------------------------------------------------- 1 | const { strict: assert } = require('node:assert') 2 | 3 | const emoji = require('../lib/index.cjs') 4 | 5 | assert.equal(emoji.emojify(':wave:'), '👋') 6 | -------------------------------------------------------------------------------- /src/emojify.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { emojify } from './emojify.js' 4 | 5 | describe('emojify', () => { 6 | it('handles flags correctly', () => { 7 | expect( 8 | emojify('Mexico :mexico: and Morocco :morocco: are not the same'), 9 | ).toBe('Mexico 🇲🇽 and Morocco 🇲🇦 are not the same') 10 | }) 11 | 12 | it('leaves unknown emoji when no fallback is provided', () => { 13 | expect(emojify('I :unknown_emoji: :star: :another_one:')).toBe( 14 | 'I :unknown_emoji: ⭐ :another_one:', 15 | ) 16 | }) 17 | 18 | it('replaces unknown emoji with the fallback when a fallback string is provided', () => { 19 | expect( 20 | emojify('I :unknown_emoji: :star: :another_one:', { 21 | fallback: 'unknown', 22 | }), 23 | ).toBe('I unknown ⭐ unknown') 24 | }) 25 | 26 | it('replaces unknown emoji with the fallback when a fallback function is provided', () => { 27 | expect( 28 | emojify('I :unknown_emoji: :star: :another_one:', { 29 | fallback: part => `(${part})`, 30 | }), 31 | ).toBe('I (unknown_emoji) ⭐ (another_one)') 32 | }) 33 | 34 | it('parses a single :emoji: in a string when there is only one emoji', () => { 35 | expect(emojify(':coffee:!')).toBe('☕!') 36 | }) 37 | 38 | it('parses multiple :emoji: in a string when there are multiple emoji', () => { 39 | expect( 40 | emojify( 41 | 'I :heart: :coffee:! - :hushed::star::heart_eyes: ::: test : : :+1:+', 42 | ), 43 | ).toBe('I ❤️ ☕! - 😯⭐😍 ::: test : : 👍+') 44 | }) 45 | 46 | it('formats emoji when given a format function', () => { 47 | expect( 48 | emojify('I :unknown_emoji: :star: :another_one:', { 49 | format: name => `[${name}]`, 50 | }), 51 | ).toBe('I [:unknown_emoji:] [⭐] [:another_one:]') 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /src/emojify.ts: -------------------------------------------------------------------------------- 1 | import is from '@sindresorhus/is' 2 | 3 | import { findByName } from './findByName.js' 4 | import { asFunction, normalizeName } from './utils.js' 5 | 6 | export type EmojifyFormat = ( 7 | name: string, 8 | part?: string, 9 | input?: string, 10 | ) => string 11 | 12 | export interface EmojifyOptions { 13 | /** 14 | * The string to fallback to if an emoji was not found. 15 | */ 16 | fallback?: ((part: string) => string) | string 17 | 18 | /** 19 | * Adds a middleware layer to modify each matched emoji after parsing. 20 | */ 21 | format?: EmojifyFormat 22 | } 23 | 24 | /** 25 | * Parse all markdown-encoded emojis in a string. 26 | */ 27 | export const emojify = ( 28 | input: string, 29 | { fallback, format = name => name }: EmojifyOptions = {}, 30 | ) => { 31 | const fallbackFunction = 32 | fallback === undefined ? fallback : asFunction(fallback) 33 | 34 | is.assert.string(input) 35 | is.assert.any([is.default.undefined, is.default.function_], fallbackFunction) 36 | is.assert.function_(format) 37 | 38 | return input.replace(/:[\w\-+]+:/g, part => { 39 | const found = findByName(part) 40 | if (found) { 41 | return format(found.emoji, part, input) 42 | } 43 | 44 | if (fallbackFunction) { 45 | return format(fallbackFunction(normalizeName(part))) 46 | } 47 | 48 | return format(part) 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /src/emojilib.d.ts: -------------------------------------------------------------------------------- 1 | // Types for emojilib@v2 2 | declare module 'emojilib' { 3 | export const lib: Record 4 | } 5 | -------------------------------------------------------------------------------- /src/find.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { find } from './find.js' 4 | 5 | describe('find', () => { 6 | it('returns an emoji when given a name', () => { 7 | expect(find('heart')).toEqual({ emoji: '❤️', key: 'heart' }) 8 | }) 9 | 10 | it('returns an emoji when given a :name:', () => { 11 | expect(find(':heart:')).toEqual({ emoji: '❤️', key: 'heart' }) 12 | }) 13 | 14 | it('returns an emoji when given a code', () => { 15 | expect(find('❤')).toEqual({ emoji: '❤', key: 'heart' }) 16 | }) 17 | 18 | it('returns the base emoji when given an alternate emoji code', () => { 19 | expect(find('❤️')).toEqual({ emoji: '❤', key: 'heart' }) 20 | }) 21 | 22 | it('returns undefined when given an unknown name', () => { 23 | expect(find('unknown_emoji')).toBeUndefined() 24 | }) 25 | 26 | it('returns undefined when given an unknown :name:', () => { 27 | expect(find('unknown_emoji')).toBeUndefined() 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /src/find.ts: -------------------------------------------------------------------------------- 1 | import { findByCode } from './findByCode.js' 2 | import { findByName } from './findByName.js' 3 | 4 | /** 5 | * Get the name and character of an emoji. 6 | */ 7 | export const find = (codeOrName: string) => { 8 | return findByCode(codeOrName) ?? findByName(codeOrName) 9 | } 10 | -------------------------------------------------------------------------------- /src/findByCode.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { findByCode } from './findByCode.js' 4 | 5 | describe('findByCode', () => { 6 | it('returns undefined when given a name', () => { 7 | expect(findByCode('heart')).toBeUndefined() 8 | }) 9 | 10 | it('returns undefined when given a :name:', () => { 11 | expect(findByCode(':heart:')).toBeUndefined() 12 | }) 13 | 14 | it('returns the emoji when given an emoji code', () => { 15 | expect(findByCode('❤')).toEqual({ emoji: '❤', key: 'heart' }) 16 | }) 17 | 18 | it('returns the base emoji when given an alternate emoji code', () => { 19 | expect(findByCode('❤️')).toEqual({ emoji: '❤', key: 'heart' }) 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /src/findByCode.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { emojiNamesByCode } from './data.js' 4 | import { normalizeCode } from './utils.js' 5 | 6 | export const findByCode = (code: string) => { 7 | assert.string(code) 8 | 9 | const emojiNormalized = normalizeCode(code) 10 | const key = emojiNamesByCode.get(emojiNormalized) 11 | 12 | return key ? { emoji: emojiNormalized, key } : undefined 13 | } 14 | -------------------------------------------------------------------------------- /src/findByName.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { findByName } from './findByName.js' 4 | 5 | describe('findByName', () => { 6 | it('returns an emoji when given a name', () => { 7 | expect(findByName('heart')).toEqual({ emoji: '❤️', key: 'heart' }) 8 | }) 9 | 10 | it('returns an emoji when given a :name:', () => { 11 | expect(findByName(':heart:')).toEqual({ emoji: '❤️', key: 'heart' }) 12 | }) 13 | 14 | it('returns undefined when given an emoji code', () => { 15 | expect(findByName('❤')).toBeUndefined() 16 | }) 17 | 18 | it('returns undefined when given an alternate emoji code', () => { 19 | expect(findByName('❤️')).toBeUndefined() 20 | }) 21 | 22 | it('returns undefined when given an unknown name', () => { 23 | expect(findByName('unknown_emoji')).toBeUndefined() 24 | }) 25 | 26 | it('returns undefined when given an unknown :name:', () => { 27 | expect(findByName('unknown_emoji')).toBeUndefined() 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /src/findByName.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { emojiCodesByName } from './data.js' 4 | import { normalizeName } from './utils.js' 5 | 6 | export const findByName = (name: string) => { 7 | assert.string(name) 8 | 9 | const nameNormalized = normalizeName(name) 10 | const emoji = emojiCodesByName.get(nameNormalized) 11 | 12 | return emoji ? { emoji, key: nameNormalized } : undefined 13 | } 14 | -------------------------------------------------------------------------------- /src/get.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { get } from './get.js' 4 | 5 | describe('get', () => { 6 | it('returns an emoji code when given a string', () => { 7 | expect(get('coffee')).toBe('☕') 8 | }) 9 | 10 | it('returns the contained emoji code when given markdown emoji', () => { 11 | expect(get(':coffee:')).toBe('☕') 12 | }) 13 | 14 | it('returns undefined when given an emoji', () => { 15 | expect(get('👯')).toBeUndefined() 16 | }) 17 | 18 | it('returns undefined when given an unknown word', () => { 19 | expect(get('unknown')).toBeUndefined() 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /src/get.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { emojiCodesByName } from './data.js' 4 | import { normalizeName } from './utils.js' 5 | 6 | /** 7 | * Get an emoji from an emoji name. 8 | */ 9 | export const get = (codeOrName: string) => { 10 | assert.string(codeOrName) 11 | 12 | return emojiCodesByName.get(normalizeName(codeOrName)) 13 | } 14 | -------------------------------------------------------------------------------- /src/has.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { has } from './has.js' 4 | 5 | describe('has', () => { 6 | it('returns true when given an emoji', () => { 7 | expect(has('☕')).toBe(true) 8 | }) 9 | 10 | it('returns true when given the name of an emoji', () => { 11 | expect(has('coffee')).toBe(true) 12 | }) 13 | 14 | it('returns true when given a markdown emoji name', () => { 15 | expect(has(':coffee:')).toBe(true) 16 | }) 17 | 18 | it('returns false when given unrelated text', () => { 19 | expect(has('nonexistent')).toBe(false) 20 | }) 21 | 22 | it('returns false when given an unknown markdown name', () => { 23 | expect(has(':nonexistent:')).toBe(false) 24 | }) 25 | 26 | it('returns true when given a emoji in base form', () => { 27 | expect(has('❤️')).toBe(true) 28 | }) 29 | 30 | it('returns true when given an emoji in code text form', () => { 31 | expect(has('❤')).toBe(true) 32 | }) 33 | 34 | it('returns false when given multiple emoji codes', () => { 35 | expect(has('🍕❤️‍💋‍☕')).toBe(false) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /src/has.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { emojiCodesByName, emojiNamesByCode } from './data.js' 4 | import { normalizeCode, normalizeName } from './utils.js' 5 | 6 | /** 7 | * Check if this library supports a specific emoji. 8 | */ 9 | export const has = (codeOrName: string) => { 10 | assert.string(codeOrName) 11 | 12 | return ( 13 | emojiCodesByName.has(normalizeName(codeOrName)) || 14 | emojiNamesByCode.has(normalizeCode(codeOrName)) 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './emojify.js' 2 | export * from './find.js' 3 | export * from './get.js' 4 | export * from './has.js' 5 | export * from './random.js' 6 | export * from './replace.js' 7 | export * from './search.js' 8 | export * from './strip.js' 9 | export * from './unemojify.js' 10 | export * from './which.js' 11 | -------------------------------------------------------------------------------- /src/random.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { get } from './get.js' 4 | import { has } from './has.js' 5 | import { random } from './random.js' 6 | 7 | describe('random', () => { 8 | it('returns a random emoji and the corresponding key', () => { 9 | const result = random() 10 | 11 | expect(has(result.name)).toBe(true) 12 | expect(result.emoji).toBe(get(result.name)) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /src/random.ts: -------------------------------------------------------------------------------- 1 | import { emojiData } from './data.js' 2 | import { randomItem } from './utils.js' 3 | 4 | /** 5 | * Get a random emoji. 6 | */ 7 | export const random = () => { 8 | const [name, emoji] = randomItem(emojiData) 9 | return { emoji, name } 10 | } 11 | -------------------------------------------------------------------------------- /src/replace.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { replace } from './replace.js' 4 | 5 | describe('replace', () => { 6 | it('returns an empty string when given an empty string', () => { 7 | expect(replace('', 'b')).toBe('') 8 | }) 9 | 10 | it('returns the input text when given text without emojis', () => { 11 | expect(replace('no emojis', 'b')).toBe('no emojis') 12 | }) 13 | 14 | it('returns a single emoji replacement when given text with one emoji', () => { 15 | expect(replace('a ☕ c', 'b')).toBe('a bc') 16 | }) 17 | 18 | it('returns multiple emoji replacement when given text with multiple emojis', () => { 19 | expect(replace('a ☕ c 🍕 d', 'b')).toBe('a bc bd') 20 | }) 21 | 22 | it('preserves spaces around emojis when preserveSpaces is true', () => { 23 | expect(replace('a ☕ c 🍕 d', 'b', { preserveSpaces: true })).toBe( 24 | 'a b c b d', 25 | ) 26 | }) 27 | 28 | it('replaces with the replacer when given a replacer', () => { 29 | expect(replace('a 🌭 c', ({ emoji }) => `>${emoji}<`)).toBe('a >🌭 { 33 | expect( 34 | replace('a 🌭 c', ({ emoji }) => `>${emoji}<`, { 35 | preserveSpaces: true, 36 | }), 37 | ).toBe('a >🌭< c') 38 | }) 39 | 40 | it('calls the replacer again when given multiple emojis', () => { 41 | expect( 42 | replace( 43 | 'a 🌭 b 🌭 🍵☕ c', 44 | (() => { 45 | let counter = 0 46 | const letters = ['w', 'x', 'y', 'z'] 47 | return () => letters[counter++] 48 | })(), 49 | ), 50 | ).toBe('a wb xyzc') // cspell:disable-line 51 | }) 52 | 53 | it('strips complex emojis', () => { 54 | expect(replace('before 👩‍❤️‍💋‍👩 after', '')).toBe('before after') 55 | }) 56 | 57 | it('strips flag emojis', () => { 58 | expect(replace('There is no flag 🇲🇽', '')).toBe('There is no flag ') 59 | }) 60 | 61 | it('ignores known existing complex emojis', () => { 62 | expect(replace('Some 🍕❤️‍💋‍☕ emoji', '')).toBe('Some ❤️‍💋‍☕ emoji') 63 | }) 64 | }) 65 | -------------------------------------------------------------------------------- /src/replace.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { Emoji } from './data.js' 4 | import { findByCode } from './findByCode.js' 5 | import { asFunction, charRegexMatcher } from './utils.js' 6 | 7 | export type ReplaceReplacement = ( 8 | emoji: Emoji, 9 | index: number, 10 | string: string, 11 | ) => string 12 | 13 | /** 14 | * Replace the emojis in a string. 15 | */ 16 | export const replace = ( 17 | input: string, 18 | replacement: ReplaceReplacement | string, 19 | { preserveSpaces = false } = {}, 20 | ) => { 21 | const replace = asFunction(replacement) 22 | 23 | assert.string(input) 24 | assert.function_(replace) 25 | assert.boolean(preserveSpaces) 26 | 27 | const characters = input.match(charRegexMatcher) 28 | if (characters === null) { 29 | return input 30 | } 31 | 32 | return characters 33 | .map((character, index) => { 34 | const found = findByCode(character) 35 | if (!found) { 36 | return character 37 | } 38 | 39 | if (!preserveSpaces && characters[index + 1] === ' ') { 40 | characters[index + 1] = '' 41 | } 42 | 43 | return replace(found, index, input) 44 | }) 45 | .join('') 46 | } 47 | -------------------------------------------------------------------------------- /src/search.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { search } from './search.js' 4 | 5 | describe('search', () => { 6 | it('returns a single pair when given a one-of emoji name', () => { 7 | expect(search('100')).toEqual([{ emoji: '💯', name: '100' }]) 8 | }) 9 | 10 | it('returns a single pair when given one-of emoji name as regular expression', () => { 11 | expect(search(/100/)).toEqual([{ emoji: '💯', name: '100' }]) 12 | }) 13 | 14 | it('returns multiple emojis when given a common substring', () => { 15 | expect(search('cartwheel')).toEqual([ 16 | { 17 | emoji: '🤸‍♀️', 18 | name: 'woman_cartwheeling', 19 | }, 20 | { 21 | emoji: '🤸‍♂️', 22 | name: 'man_cartwheeling', 23 | }, 24 | ]) 25 | }) 26 | 27 | it('returns multiple emojis when given a common regular expression', () => { 28 | expect(search(/cartwheel/)).toEqual([ 29 | { 30 | emoji: '🤸‍♀️', 31 | name: 'woman_cartwheeling', 32 | }, 33 | { 34 | emoji: '🤸‍♂️', 35 | name: 'man_cartwheeling', 36 | }, 37 | ]) 38 | }) 39 | 40 | it('should match when you include the colon', () => { 41 | expect(search(':cartwheel:')).toEqual([ 42 | { 43 | emoji: '🤸‍♀️', 44 | name: 'woman_cartwheeling', 45 | }, 46 | { 47 | emoji: '🤸‍♂️', 48 | name: 'man_cartwheeling', 49 | }, 50 | ]) 51 | }) 52 | 53 | it('should match when you include the colon in the regular expression', () => { 54 | expect(search(/:cartwheel:/)).toEqual([ 55 | { 56 | emoji: '🤸‍♀️', 57 | name: 'woman_cartwheeling', 58 | }, 59 | { 60 | emoji: '🤸‍♂️', 61 | name: 'man_cartwheeling', 62 | }, 63 | ]) 64 | }) 65 | 66 | it('returns an empty array when no matching emojis are found for a string search', () => { 67 | expect(search('notAnEmoji')).toEqual([]) 68 | }) 69 | 70 | it('returns an empty array when no matching emojis are found for a regular expression search', () => { 71 | expect(search(/notAnEmoji/)).toEqual([]) 72 | }) 73 | }) 74 | -------------------------------------------------------------------------------- /src/search.ts: -------------------------------------------------------------------------------- 1 | import is, { assert } from '@sindresorhus/is' 2 | 3 | import { emojiData } from './data.js' 4 | import { normalizeName } from './utils.js' 5 | 6 | /** 7 | * Search for emojis containing the provided name or pattern in their name. 8 | */ 9 | export const search = (keyword: RegExp | string) => { 10 | assert.any([is.default.string, is.default.regExp], keyword) 11 | 12 | if (is.default.string(keyword)) { 13 | keyword = normalizeName(keyword) 14 | } 15 | 16 | if (is.default.regExp(keyword)) { 17 | const normalizedPattern = normalizeName(keyword.source) 18 | keyword = new RegExp(normalizedPattern) 19 | } 20 | 21 | return emojiData 22 | .filter(([name]) => name.match(keyword)) 23 | .map(([name, emoji]) => ({ emoji, name })) 24 | } 25 | -------------------------------------------------------------------------------- /src/strip.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { strip } from './strip.js' 4 | 5 | describe('strip', () => { 6 | it('returns an empty string when given an empty string', () => { 7 | expect(strip('')).toBe('') 8 | }) 9 | 10 | it('returns an the input string when given a string with no emojis', () => { 11 | expect(strip('abc')).toBe('abc') 12 | }) 13 | 14 | it('returns an input string with an emoji removed when given an input string with one emoji', () => { 15 | expect(strip('a ☕ c')).toBe('a c') 16 | }) 17 | 18 | it('returns an input string with multiple emojis removed when given an input string with multiple emojis', () => { 19 | expect(strip('a ☕ b 🍕 c')).toBe('a b c') 20 | }) 21 | 22 | it('preserves spaces around emoji when preserveSpaces is true', () => { 23 | expect(strip('a ☕ c', { preserveSpaces: true })).toBe('a c') 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /src/strip.ts: -------------------------------------------------------------------------------- 1 | import { replace } from './replace.js' 2 | 3 | export interface StripOptions { 4 | /** 5 | * Whether to keep the extra space after a stripped emoji. 6 | */ 7 | preserveSpaces?: boolean 8 | } 9 | 10 | /** 11 | * Remove all the emojis from a string. 12 | */ 13 | export const strip = (input: string, { preserveSpaces }: StripOptions = {}) => 14 | replace(input, '', { preserveSpaces }) 15 | -------------------------------------------------------------------------------- /src/unemojify.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { unemojify } from './unemojify.js' 4 | 5 | describe('unemojify', () => { 6 | it('returns a blank string when given a blank string', () => { 7 | expect(unemojify('')).toBe('') 8 | }) 9 | 10 | it('returns a replaced emoji name when given a string with one emoji', () => { 11 | expect(unemojify('a ☕ c')).toBe('a :coffee: c') 12 | }) 13 | 14 | it('returns multiple replaced emoji names when given a string with multiple emojis', () => { 15 | expect(unemojify('a ☕ 🌭 c')).toBe('a :coffee: :hotdog: c') 16 | }) 17 | 18 | it('returns a complex emoji name when given a complex emoji:', () => { 19 | expect(unemojify('before 👩‍❤️‍💋‍👩 after')).toBe( 20 | 'before :couplekiss_woman_woman: after', 21 | ) 22 | }) 23 | 24 | it('parses emojis with names next to non-space characters', () => { 25 | expect(unemojify('I ❤️ ☕️! - 😯⭐️😍 ::: test : : 👍+')).toBe( 26 | 'I :heart: :coffee:! - :hushed::star::heart_eyes: ::: test : : :+1:+', 27 | ) 28 | }) 29 | 30 | it('ignores only unknown emoji when given a string with some valid, some unknown emojis', () => { 31 | // Emoji :melting_face: (U+1FAE0) Unicode 14.0 draft: https://emojipedia.org/unicode-14.0 32 | expect(unemojify('I ⭐️ :another_one: 🫠')).toBe( 33 | 'I :star: :another_one: 🫠', 34 | ) 35 | }) 36 | 37 | // see issue #21 38 | it('should parse flags correctly', () => { 39 | expect(unemojify('The flags of 🇲🇽 and 🇲🇦 are not the same')).toBe( 40 | 'The flags of :mexico: and :morocco: are not the same', 41 | ) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /src/unemojify.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | 3 | import { charRegexMatcher } from './utils.js' 4 | import { which } from './which.js' 5 | 6 | /** 7 | * Convert all emojis in a string to their markdown-encoded counterparts. 8 | */ 9 | export const unemojify = (input: string) => { 10 | assert.string(input) 11 | 12 | const characters = input.match(charRegexMatcher) 13 | if (characters === null) { 14 | return input 15 | } 16 | 17 | return characters 18 | .map(character => which(character, { markdown: true }) ?? character) 19 | .join('') 20 | } 21 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import charRegex from 'char-regex' 2 | 3 | export const charRegexMatcher = charRegex() 4 | 5 | export function asFunction( 6 | input: ((...args: Args) => T) | T, 7 | ): (...args: Args) => T { 8 | return typeof input === 'function' ? input : () => input 9 | } 10 | 11 | /** 12 | * Non spacing mark contained by some emoticons (65039 - '️' - 0xFE0F). 13 | * 14 | * It's the 'Variant Form', which provides more information so that emoticons 15 | * can be rendered as more colorful graphics. FE0E is a unicode text version 16 | * whereas FE0F should be rendered as a graphical version. 17 | * The code gracefully degrades. 18 | */ 19 | const NON_SPACING_MARK = String.fromCharCode(65039) 20 | 21 | const nonSpacingRegex = new RegExp(NON_SPACING_MARK, 'g') 22 | 23 | /** 24 | * Removes the non-spacing-mark from the emoji code. 25 | * 26 | * Never send a stripped version to clients, as it kills graphical emoticons. 27 | */ 28 | export function normalizeCode(code: string) { 29 | return code.replace(nonSpacingRegex, '') 30 | } 31 | 32 | export function normalizeName(name: string) { 33 | return /:.+:/.test(name) ? name.slice(1, -1) : name 34 | } 35 | 36 | export function randomItem(array: T[]) { 37 | return array[Math.floor(Math.random() * array.length)] 38 | } 39 | -------------------------------------------------------------------------------- /src/which.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | import { which } from './which.js' 4 | 5 | describe('which', () => { 6 | it('returns a simple emoji name when given an emoji', () => { 7 | expect(which('☕')).toBe('coffee') 8 | }) 9 | 10 | it('returns a simple emoji name as markdown when specified as markdown', () => { 11 | expect(which('☕', { markdown: true })).toBe(':coffee:') 12 | }) 13 | 14 | it('returns a skin toned emoji name when given a skin toned emoji', () => { 15 | expect(which('👍🏾')).toBe('+1') 16 | }) 17 | 18 | it('returns a skin toned emoji name as markdown when specified as markdown', () => { 19 | expect(which('👍🏾', { markdown: true })).toBe(':+1:') 20 | }) 21 | 22 | // see issue #21 23 | it('should work for flags', () => { 24 | expect(which('🇲🇽')).toBe('mexico') 25 | expect(which('🇲🇦')).toBe('morocco') 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /src/which.ts: -------------------------------------------------------------------------------- 1 | import { assert } from '@sindresorhus/is' 2 | import skinTone from 'skin-tone' 3 | 4 | import { findByCode } from './findByCode.js' 5 | 6 | export interface WhichOptions { 7 | markdown?: boolean 8 | } 9 | 10 | /** 11 | * Get an emoji name from an emoji. 12 | */ 13 | export const which = ( 14 | emoji: string, 15 | { markdown = false }: WhichOptions = {}, 16 | ) => { 17 | assert.string(emoji) 18 | assert.boolean(markdown) 19 | 20 | const result = findByCode(skinTone(emoji, 'none')) 21 | if (result === undefined) { 22 | return undefined 23 | } 24 | 25 | return markdown ? `:${result.key}:` : result.key 26 | } 27 | -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0xA11fbA75aBC493b9b2902F9Ccc686DfB277Ae933' 6 | quorum: 1 7 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { "extends": "./tsconfig.json", "include": ["."] } 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationMap": true, 5 | "esModuleInterop": true, 6 | "module": "NodeNext", 7 | "moduleResolution": "NodeNext", 8 | "noEmit": true, 9 | "outDir": "lib", 10 | "resolveJsonModule": true, 11 | "skipLibCheck": true, 12 | "sourceMap": true, 13 | "strict": true, 14 | "target": "ES2022" 15 | }, 16 | "include": ["src"] 17 | } 18 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup' 2 | 3 | export default defineConfig({ 4 | clean: true, 5 | dts: true, 6 | entry: ['src/**/index.ts'], 7 | format: ['cjs', 'esm'], 8 | outDir: 'lib', 9 | sourcemap: true, 10 | }) 11 | -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config' 2 | 3 | export default defineConfig({ 4 | test: { 5 | clearMocks: true, 6 | coverage: { 7 | all: true, 8 | branches: 100, 9 | exclude: ['lib', 'src/*.d.ts', 'src/e2e.cjs', 'src/index.ts'], 10 | functions: 100, 11 | include: ['src'], 12 | lines: 100, 13 | reporter: ['html', 'lcov'], 14 | statements: 100, 15 | }, 16 | exclude: ['lib', 'node_modules'], 17 | setupFiles: ['console-fail-test/setup'], 18 | }, 19 | }) 20 | --------------------------------------------------------------------------------