sqids 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/README.md +32 -4
- data/spec/minlength_spec.rb +1 -1
- data/sqids.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6375d093506a2d4058cecce28ee9f4e00148e7bde606bb4d64e613cbfb698d8
|
4
|
+
data.tar.gz: c5eb151f25ba5156995c4f7ab9fdf064d931ae619524ddae73cbe420b9ec3c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f92140fe71c4f38875cd66485188b303d46ba3114af2467386256bfa4e8e5bad8f6fff0a0d4f8b478a1ec7bfd2160689c63da46a4d7c9364300383ad43a1894
|
7
|
+
data.tar.gz: 50b51f34611e1d1465fc58cf1f97d406bf4768d7208a77cc2829e55b686806f3189834291dbc12b87774a3852dd41b55c0e994e51909d917fe5002a8adbcbd63
|
data/.github/workflows/tests.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,35 @@
|
|
1
1
|
# [Sqids Ruby](https://sqids.org/ruby)
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/sqids)
|
3
4
|
[](https://github.com/sqids/sqids-ruby/actions)
|
5
|
+
[](https://crates.io/crates/sqids)
|
4
6
|
|
5
|
-
Sqids (pronounced "squids") is a small library that lets you generate
|
7
|
+
[Sqids](https://sqids.org/ruby) (*pronounced "squids"*) is a small library that lets you **generate unique IDs from numbers**. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.
|
6
8
|
|
7
|
-
|
9
|
+
Features:
|
10
|
+
|
11
|
+
- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers
|
12
|
+
- **Quick decoding** - easily decode IDs back into numbers
|
13
|
+
- **Unique IDs** - generate unique IDs by shuffling the alphabet once
|
14
|
+
- **ID padding** - provide minimum length to make IDs more uniform
|
15
|
+
- **URL safe** - auto-generated IDs do not contain common profanity
|
16
|
+
- **Randomized output** - Sequential input provides nonconsecutive IDs
|
17
|
+
- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)
|
18
|
+
|
19
|
+
## 🧰 Use-cases
|
20
|
+
|
21
|
+
Good for:
|
22
|
+
|
23
|
+
- Generating IDs for public URLs (eg: link shortening)
|
24
|
+
- Generating IDs for internal systems (eg: event tracking)
|
25
|
+
- Decoding for quicker database lookups (eg: by primary keys)
|
26
|
+
|
27
|
+
Not good for:
|
28
|
+
|
29
|
+
- Sensitive data (this is not an encryption library)
|
30
|
+
- User IDs (can be decoded revealing user count)
|
31
|
+
|
32
|
+
## 🚀 Getting started
|
8
33
|
|
9
34
|
Add this line to your application's Gemfile:
|
10
35
|
|
@@ -24,7 +49,7 @@ Or install it via:
|
|
24
49
|
gem install sqids
|
25
50
|
```
|
26
51
|
|
27
|
-
## Examples
|
52
|
+
## 👩💻 Examples
|
28
53
|
|
29
54
|
Simple encode & decode:
|
30
55
|
|
@@ -34,6 +59,9 @@ id = sqids.encode([1, 2, 3]) # '8QRLaD'
|
|
34
59
|
numbers = sqids.decode(id) # [1, 2, 3]
|
35
60
|
```
|
36
61
|
|
62
|
+
> **Note**
|
63
|
+
> 🚧 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.
|
64
|
+
|
37
65
|
Randomize IDs by providing a custom alphabet:
|
38
66
|
|
39
67
|
```ruby
|
@@ -58,6 +86,6 @@ id = sqids.encode([1, 2, 3]) # '8QRLaD'
|
|
58
86
|
numbers = sqids.decode(id) # [1, 2, 3]
|
59
87
|
```
|
60
88
|
|
61
|
-
## License
|
89
|
+
## 📝 License
|
62
90
|
|
63
91
|
[MIT](LICENSE)
|
data/spec/minlength_spec.rb
CHANGED
data/sqids.gemspec
CHANGED
@@ -7,13 +7,13 @@ require 'sqids'
|
|
7
7
|
|
8
8
|
Gem::Specification.new do |gem|
|
9
9
|
gem.name = 'sqids'
|
10
|
-
gem.version = '0.1.
|
10
|
+
gem.version = '0.1.1'
|
11
11
|
gem.authors = ['Sqids Maintainers']
|
12
12
|
gem.summary = 'Generate YouTube-like ids from numbers.'
|
13
13
|
gem.homepage = 'https://sqids.org/ruby'
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
16
|
-
gem.required_ruby_version = '>= 3.
|
16
|
+
gem.required_ruby_version = '>= 3.0'
|
17
17
|
|
18
18
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
19
|
gem.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sqids Maintainers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -42,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '3.
|
45
|
+
version: '3.0'
|
46
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ">="
|