Skip to content

Commit

Permalink
Update code snippets in README files to match the new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aradalvand committed Sep 10, 2023
1 parent ac07075 commit f40e66f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions nuget-readme.md → NUGET-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Sqids (_pronounced "squids"_) is a small library that lets you generate YouTube-

```cs
using Sqids;
var sqids = new SqidsEncoder();

string id = sqids.Encode(1, 2, 3); // "8QRLaD"
int[] numbers = sqids.Decode(id); // new[] { 1, 2, 3 }
var sqids = new SqidsEncoder<int>();

var id = sqids.Encode(1, 2, 3); // "86Rf07"
var numbers = sqids.Decode(id); // [1, 2, 3]
```

> **Note:** For more documentation and examples, check out the [GitHub repository](https://github.com/sqids/sqids-dotnet).
> **Note:** For the full documentation and other examples, check out the [GitHub repository](https://github.com/sqids/sqids-dotnet).
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ var sqids = new SqidsEncoder();
#### Single number:

```cs
string id = sqids.Encode(1); // "Uk"
int number = sqids.Decode(id).Single(); // 1
var id = sqids.Encode(1); // "Uk"
var number = sqids.Decode(id).Single(); // 1
```

#### Multiple numbers:

```cs
string id = sqids.Encode(1, 2, 3); // "86Rf07"
int[] numbers = sqids.Decode(id); // new[] { 1, 2, 3 }
var id = sqids.Encode(1, 2, 3); // "86Rf07"
var numbers = sqids.Decode(id); // [1, 2, 3]
```

> **Note**
Expand Down Expand Up @@ -164,7 +164,7 @@ Due to the design of Sqids's algorithm, decoding random IDs can sometimes produc
The best way to mitigate this is to check if an ID is "canonical" before using its decoded value to do a database lookup, for example; and this can be done by simply re-encoding the decoded number(s) and checking if the result matches the incoming ID:

```cs
int[] numbers = sqids.Decode(input);
var numbers = sqids.Decode(input);
bool isCanonical = input == sqids.Encode(numbers); // If `input` is `OSc`, this evaluates to `true` (because that's the canonical encoding of `3168`), and if `input` is `2fs`, it evaluates to `false`.
```

Expand Down

0 comments on commit f40e66f

Please sign in to comment.