Skip to content

docs(readme): added node.js example #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

ShanTen
Copy link

@ShanTen ShanTen commented Mar 24, 2025

Including the Node.js code snippet directly in the README would be convenient for quick reference.

@miquelfire
Copy link

There is a push to switch to use ESM, so using import instead of require might be better.

Actually, I think it would be better to have the require/import lines in the NPM and Yarn sections

@ShanTen
Copy link
Author

ShanTen commented Mar 24, 2025

So something like..?

🚀 Getting started

yarn:

yarn add sqids

npm:

npm install sqids

cdnjs:

<script src="https://cdnjs.cloudflare.com/ajax/libs/sqids/0.3.0/sqids.min.js"></script>

jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/sqids/dist/sqids.min.js"></script>

🛠️ Using Sqids in Node.js

CJS:

const Sqids = require('sqids').default;

const sqids = new Sqids({
    blocklist: new Set(['86Rf07']),
});

ES6:

import Sqids from 'sqids';

const sqids = new Sqids({
  blocklist: new Set(['86Rf07']),
});

👩‍💻 Examples

...

@miquelfire
Copy link

I'm thinking that's too busy. Over all, you just need the import/require lines, maybe at the top of the Examples. Maybe something like this (I don't like the heading I used here):

👩‍💻 Examples

Node.js import:

// ESM
import Sqids from 'sqids';

// CJS
const Sqids = require('sqids').default;

Simple encode & decode:

@4kimov
Copy link
Member

4kimov commented Mar 25, 2025

@ShanTen @miquelfire I think I've been doing so many of these READMEs in diff languages, that I totally forgot about the import statement (and it should be there). I'll just use esm for now to keep it simple and close the PR, but thanks for the heads up!

@4kimov 4kimov closed this Mar 25, 2025
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.

3 participants