Skip to content

Commit 9187d20

Browse files
committed
feat: simpler algo wip
1 parent 940a654 commit 9187d20

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,40 +42,40 @@ Simple encode & decode:
4242

4343
```javascript
4444
const sqids = new Sqids()
45-
const id = sqids.encode([1, 2, 3]) // "8QRLaD"
45+
const id = sqids.encode([1, 2, 3]) // "86Rf07"
4646
const numbers = sqids.decode(id) // [1, 2, 3]
4747
```
4848

4949
> **Note**
5050
> 🚧 Because of the algorithm's design, **multiple IDs can decode back into the same sequence of numbers**. If it's important to your design that IDs are canonical, you have to manually re-encode decoded numbers and check that the generated ID matches.
5151
52-
Randomize IDs by providing a custom alphabet:
52+
Enforce a *minimum* length for IDs:
5353

5454
```javascript
5555
const sqids = new Sqids({
56-
alphabet: 'FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE',
56+
minLength: 10,
5757
})
58-
const id = sqids.encode([1, 2, 3]) // "B5aMa3"
58+
const id = sqids.encode([1, 2, 3]) // "86Rf07xd4z"
5959
const numbers = sqids.decode(id) // [1, 2, 3]
6060
```
6161

62-
Enforce a *minimum* length for IDs:
62+
Randomize IDs by providing a custom alphabet:
6363

6464
```javascript
6565
const sqids = new Sqids({
66-
minLength: 10,
66+
alphabet: 'FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE',
6767
})
68-
const id = sqids.encode([1, 2, 3]) // "75JT1cd0dL"
68+
const id = sqids.encode([1, 2, 3]) // "B4aajs"
6969
const numbers = sqids.decode(id) // [1, 2, 3]
7070
```
7171

7272
Prevent specific words from appearing anywhere in the auto-generated IDs:
7373

7474
```javascript
7575
const sqids = new Sqids({
76-
blocklist: new Set(['word1', 'word2']),
76+
blocklist: new Set(['86Rf07']),
7777
})
78-
const id = sqids.encode([1, 2, 3]) // "8QRLaD"
78+
const id = sqids.encode([1, 2, 3]) // "se8ojk"
7979
const numbers = sqids.decode(id) // [1, 2, 3]
8080
```
8181

0 commit comments

Comments
 (0)