From a448a9b7e6e9f9803e5f50b94201ea692d3a62a8 Mon Sep 17 00:00:00 2001 From: Ivan Akimov Date: Mon, 17 Jul 2023 15:27:05 -0500 Subject: [PATCH] wip --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e555f6b..9c8f96e 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,51 @@ Sqids (pronounced "squids") is a small library that lets you generate YouTube-lo ## Getting started -@todo +Install Sqids via: + +```bash +yarn add sqids +``` ## Examples -@todo +Simple encode & decode: + +```javascript +const sqids = new Sqids() +const id = sqids.encode([1, 2, 3]) // "8QRLaD" +const numbers = sqids.decode(id) // [1, 2, 3] +``` + +Randomize IDs by providing a custom alphabet: + +```javascript +const sqids = new Sqids({ + alphabet: 'FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE', +}) +const id = sqids.encode([1, 2, 3]) // "B5aMa3" +const numbers = sqids.decode(id) // [1, 2, 3] +``` + +Enforce a *minimum* length for IDs: + +```javascript +const sqids = new Sqids({ + minLength: 10, +}) +const id = sqids.encode([1, 2, 3]) // "75JT1cd0dL" +const numbers = sqids.decode(id) // [1, 2, 3] +``` + +Prevent specific words from appearing anywhere in the auto-generated IDs: + +```javascript +const sqids = new Sqids({ + blocklist: new Set(['word1', 'word2']), +}) +const id = sqids.encode([1, 2, 3]) // "8QRLaD" +const numbers = sqids.decode(id) // [1, 2, 3] +``` ## License