Comments (7)
I understand you. But we can't suggest global settings API. What if your dependency use Nano ID too and new settings will create conflict there?
But there is more simple solution:
// random.js
import nanoid from 'nanoid'
module exports function random () {
return nanoid(alphabet, size)
}
// main.js
import random from './random'
from nanoid.
I do understand that work around, but I don't like that I need to have relative imports throughout my code.
The suggestion to set defaults
was what I really was looking for.
I do understand that you're hesitant to implement this.
But I also think that library authors should be aware that they shouldn't change the defaults, and that anyone changing the defaults, should be aware that it can have side effects.
from nanoid.
anyone changing the defaults, should be aware that it can have side effects.
I like how optimistic you are about users 😄. Unfortunately, I know by my practice with shortid
, that it doesn't work.
Developers do not read docs. Developers prefer to save few bytes instead of protecting system from long term problems.
How even you can be sure, that your dependency well not change defaults and broke your code? 😏
I don't like that I need to have relative imports throughout my code.
Sure. Can you tell me what alphabet, what size and why do you use them? Maybe I can find better solution.
from nanoid.
Developers should be the better kind of users 😇 But unfortunately, I must agree. Point taken.
Sure; all info is in the opening post; but here again:
const ALPHABET = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz';
const LENGTH = 17;
Why? So that I can replace meteor/random
with nanoid
, without changing the way generated ids look:
import { Random } from 'meteor/random';
Random.id();
A little more on the "why": Meteor style import definitions suck, as it's not easy testable. I try to lessen my dependencies on the framework, and move more to Meteor as a build tool. Thereby, depending on Random
is a no go.
In the long term, when I would leave Meteor entirely, I still want to have the database ids to look the same. Currently Random.id()
(meteor
) is responsible for id generation. This would become nanoid
if it was possible.
So perhaps a nanoid/unmistakable
or nanoid/readable
or nanoid/meteor-compat
?
from nanoid.
I have a better plan. Send this alphabet to nanoid-dictionary as unmistakable
alphabet. It has no 1
, l
, 0
since they could be misread as different symbols.
Then you can use it as it. Or ask nanoid-dictionary
to add shortcuts:
import unmistakable from 'nanoid-dictionary/unmistakable'
unmistakable(17)
from nanoid.
I added issues there:
CyberAP/nanoid-dictionary#1
CyberAP/nanoid-dictionary#2
from nanoid.
Hope that solves your issue: https://github.com/CyberAP/nanoid-generate#nolookalikes
from nanoid.
Related Issues (20)
- Docs: Unnecessary use of --save flag HOT 1
- ulid format preset HOT 1
- Doesn't work with AWS Lambdas
- Question: about the usage of a bitmask
- Error while importing in node js
- Issue while running in Firebase Emulator (Cloud Functions) HOT 1
- Errors with nanoid v3 when using jest and jsdom HOT 15
- Error on nanoid HOT 1
- ERR_REQUIRE_ESM' const { nanoid } = require("nanoid"); HOT 1
- Not working with expo HOT 22
- strange error HOT 2
- Error when calling nanoid in browser (from 5.0.5) HOT 6
- Nothing
- Undefined in Server Side Nextjs / Node HOT 1
- Cannot read properties of undefined (reading 'length') HOT 7
- Move benchmark to tibybench HOT 4
- Is it possible to create a single js file to import in a company inner project? HOT 4
- Error [ERR_REQUIRE_ESM] when using `nanoid` with CommonJS HOT 1
- What about benchmarks? HOT 1
- NanoId to Uint8Array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanoid.