sqids 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +32 -4
- data/lib/sqids.rb +1 -1
- data/spec/blocklist_spec.rb +11 -0
- data/spec/minlength_spec.rb +1 -1
- data/spec/uniques_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: 8c79695a1c507e1785e6c454fed0e0f4bca689598608d5b680b019493dfe9406
|
4
|
+
data.tar.gz: 9c64e11d7b0a8c551caf8b24d73fd01cb0aaf8ade971a4b6d535f120e1be8d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9992329b56a99da95e7ee85e1b928407d7cbb40f5312cbc18a0f17ed95b0ba51b175088dc84db69d894bfa0814d587f5cdbe327c7a6a1d56c89eb004c68a83ae
|
7
|
+
data.tar.gz: 00d797e9d692a9c4ad82f80971649d2e4553d317c78b72e258ae497fa94521246205e56873971685b42d9b4ee7d8507d71bdf4c05fd80eab9735f58176adf230
|
data/.github/workflows/tests.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
**v0.1.2:**
|
4
|
+
- Bug fix: spec update (PR #7): blocklist filtering in uppercase-only alphabet [[PR #7](https://github.com/sqids/sqids-spec/pull/7)]
|
5
|
+
- Lower uniques test from 1_000_000 to 10_000
|
6
|
+
|
7
|
+
**v0.1.1:**
|
8
|
+
- Lowering Ruby version requirement to 3.0
|
9
|
+
|
3
10
|
**v0.1.0:**
|
4
11
|
- First implementation of [the spec](https://github.com/sqids/sqids-spec)
|
data/README.md
CHANGED
@@ -1,10 +1,35 @@
|
|
1
1
|
# [Sqids Ruby](https://sqids.org/ruby)
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sqids.svg)](https://rubygems.org/gems/sqids)
|
3
4
|
[![Github Actions](https://img.shields.io/github/actions/workflow/status/sqids/sqids-ruby/tests.yml)](https://github.com/sqids/sqids-ruby/actions)
|
5
|
+
[![Downloads](https://img.shields.io/gem/dt/sqids)](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/lib/sqids.rb
CHANGED
@@ -28,7 +28,7 @@ class Sqids
|
|
28
28
|
end
|
29
29
|
|
30
30
|
filtered_blocklist = blocklist.select do |word|
|
31
|
-
word.length >= 3 && (word.chars - alphabet.chars).empty?
|
31
|
+
word.length >= 3 && (word.downcase.chars - alphabet.downcase.chars).empty?
|
32
32
|
end.to_set(&:downcase)
|
33
33
|
|
34
34
|
@alphabet = shuffle(alphabet)
|
data/spec/blocklist_spec.rb
CHANGED
@@ -52,4 +52,15 @@ describe Sqids do
|
|
52
52
|
|
53
53
|
expect(sqids.decode(sqids.encode([1_000]))).to eq([1_000])
|
54
54
|
end
|
55
|
+
|
56
|
+
it 'blocklist filtering in constructor' do
|
57
|
+
# lowercase blocklist in only-uppercase alphabet
|
58
|
+
sqids = Sqids.new(alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', blocklist: Set.new(['sqnmpn']))
|
59
|
+
|
60
|
+
id = sqids.encode([1, 2, 3])
|
61
|
+
numbers = sqids.decode(id)
|
62
|
+
|
63
|
+
expect(id).to eq('ULPBZGBM') # without blocklist, would've been "SQNMPN"
|
64
|
+
expect(numbers).to eq([1, 2, 3])
|
65
|
+
end
|
55
66
|
end
|
data/spec/minlength_spec.rb
CHANGED
data/spec/uniques_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.2'
|
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.2
|
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-31 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
|
- - ">="
|