Skip to content

Commit

Permalink
Merge pull request #2 from sqids/register_julia_package
Browse files Browse the repository at this point in the history
Edit README and Project.toml for Pkg-Registration
  • Loading branch information
antimon2 authored Jul 15, 2023
2 parents 4752ec2 + 2d39f03 commit a84853d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Sqids"
uuid = "5846b9ac-096c-425b-b363-8d1a03210e20"
authors = ["GOTOH Shunsuke <antimon2.me@gmail.com> and contributors"]
version = "0.1.0-DEV"
version = "0.1.0"

[compat]
julia = "1.6"
Expand Down
42 changes: 31 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,71 @@
# [Sqids Julia](https://sqids.org/julia)
# [Sqids.jl](https://sqids.org/julia)

[![Github Actions](https://img.shields.io/github/actions/workflow/status/sqids/sqids-julia/CI.yml)](https://github.com/sqids/sqids-julia/actions)

Sqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

## Getting started

Install Sqids via:
Install Sqids via (on the Julia REPL):

```julia
# @todo
julia> ] # enter Pkg REPL-mode

pkg> add Sqids
```

## Examples

Start using Sqids:

```julia
using Sqids
```

Simple encode & decode:

```julia
config = Sqids.configure()
id = Sqids.encode(config, [1, 2, 3]) # "8QRLaD"
numbers = Sqids.decode(config, id) # [1, 2, 3]
id = Sqids.encode(config, [1, 2, 3]) #> "8QRLaD"
numbers = Sqids.decode(config, id) #> [1, 2, 3]
```

Randomize IDs by providing a custom alphabet:

```julia
config = Sqids.configure(alphabet="FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE")
id = Sqids.encode(config, [1, 2, 3]) # "B5aMa3"
numbers = Sqids.decode(config, id) # [1, 2, 3]
id = Sqids.encode(config, [1, 2, 3]) #> "B5aMa3"
numbers = Sqids.decode(config, id) #> [1, 2, 3]
```

Enforce a *minimum* length for IDs:

```julia
config = Sqids.configure(minLength=10)
id = Sqids.encode(config, [1, 2, 3]) # "75JT1cd0dL"
numbers = Sqids.decode(config, id) # [1, 2, 3]
id = Sqids.encode(config, [1, 2, 3]) #> "75JT1cd0dL"
numbers = Sqids.decode(config, id) #> [1, 2, 3]
```

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

```julia
config = Sqids.configure(blocklist=["word1","word2"])
id = Sqids.encode(config, [1, 2, 3]) # "8QRLaD"
numbers = Sqids.decode(config, id) # [1, 2, 3]
id = Sqids.encode(config, [1, 2, 3]) #> "8QRLaD"
numbers = Sqids.decode(config, id) #> [1, 2, 3]
```

### Julia-specific

If `strict=false` is set when configuring, it enables handling of limitless values using `Int128` or `BigInt`, integer types larger than 64 bits.

```julia
config = Sqids.configure(strict=false) # not-strict mode
id = Sqids.encode(config, Int128[9223372036854775808]) #> "piF3yT7tOtoO"
numbers = Sqids.decode(config, id) #> Int128[9223372036854775808]
```

Note that while this setting allows for automatic type selection of the decoded value, it may cause type instability and minor performance slowdowns.

## Notes

- **Do not encode sensitive data.** These IDs can be easily decoded.
Expand Down

0 comments on commit a84853d

Please sign in to comment.