Skip to content

docs: update js examples to use ES module imports - #252

Open
shuuji3 wants to merge 2 commits into
muan:mainfrom
shuuji3:docs/update-readme-esmodule
Open

docs: update js examples to use ES module imports#252
shuuji3 wants to merge 2 commits into
muan:mainfrom
shuuji3:docs/update-readme-esmodule

Conversation

@shuuji3

@shuuji3 shuuji3 commented Jun 3, 2026

Copy link
Copy Markdown

resolves #225

Hello 🙂 Thanks for keeping maintaining helpful library. I've updated the js example to use the modern ES Modules.

I split the code and output parts separately because the interactive node env cannot use import * from 'lib' syntax as is.

Glad to hear feedback.

Comment thread README.md

```js
> var orderedEmoji = require('unicode-emoji-json/data-ordered-emoji')
import orderedEmoji from 'unicode-emoji-json/data-ordered-emoji.json' with { type: 'json' }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add the .json postfix here to be able to resolve the JSON path since ES Modules doesn't implicitly tries various extensions.

If you'd like to keep the same non-.json resolution to ease migration, I think you could add a new exports property in unicode-emoji-json package like this:

  "exports": {
    "./data-ordered-emoji": "./data-ordered-emoji.json",
    "./data-emoji-components": "./data-emoji-components.json",
    "./data-by-group": "./data-by-group.json"
  },

@shuuji3 shuuji3 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also fixed the CI badge.

Comment thread README.md
@@ -1,4 +1,4 @@
# emojilib ![CI status](https://github.com/muan/emojilib/workflows/Test%20dataset/badge.svg?branch=main) [![npm](https://img.shields.io/npm/dt/emojilib.svg?style=flat-square&colorB=fd7463)](https://www.npmjs.com/package/emojilib) [![JavaScript Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square&colorB=f1d04a)](https://github.com/feross/standard)
# emojilib [![Test dataset](https://github.com/muan/emojilib/actions/workflows/test.yml/badge.svg)](https://github.com/muan/emojilib/actions/workflows/test.yml) [![npm](https://img.shields.io/npm/dt/emojilib.svg?style=flat-square&colorB=fd7463)](https://www.npmjs.com/package/emojilib) [![JavaScript Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square&colorB=f1d04a)](https://github.com/feross/standard)

@shuuji3 shuuji3 Jun 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before
Image

After
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update README with ESM instructions

1 participant