Skip to content

Commit

Permalink
release: complete documentation for v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolorunduro Winner-Timothy B committed Jul 5, 2017
1 parent 05b2a0b commit de43d35
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
A csharp library to generate completely random short id's. they can be used as primary keys or unique identifiers. This library is different in that you can specify the length of the id's generated.

## How to use

To make use of the `shortid`, add it to your project via the Nuget package manager UI or console via this command:

```
Expand Down Expand Up @@ -56,4 +57,33 @@ string id = ShortId.Generate(true, false, 12);
// id = VvoCDPazES_w
```

**NOTE: when specifying the desired length, shorter lengths increase the possibility thata duplicate id would be generated**
**NOTE: when specifying the desired length, shorter lengths increase the possibility thata duplicate id would be generated**


## Customize ShortId

`ShortId` has several features that help with customizing the ids generated. Characters sets can be introduced and the random number generator can be seeded.

To change the character set in use, run the following:

```csharp
string characters = //whatever you want;
ShortId.SetCharacters(characters);
```

**NOTE: the new character set must number `null`, an empty string or whitespace. Also, all whitespace characters would be removed, finally the character set cannot be less than 20 characters.**

`ShortId` also allows the seed for the random number generator to be set.

To set the seed, run the following:

```csharp
int seed = 1939048828;
ShortId.SetSeed(seed);
```

Finally, `ShortId` allows for all customizations to be reset using the following:

```csharp
ShortId.Reset();
```
11 changes: 7 additions & 4 deletions shortid/ShortId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ public static void SetCharacters(string characters)
{
throw new ArgumentException("The replacement characters must not be null or empty.");
}
if (characters.Contains(" "))
{
characters = characters.Replace(" ", "");
}

characters = characters
.Replace(" ", "")
.Replace("\t", "")
.Replace("\n", "")
.Replace("\r", "");

if (characters.Length < 20)
{
throw new InvalidOperationException(
Expand Down

0 comments on commit de43d35

Please sign in to comment.