cuid2 0.1.0 → 1.0.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/.rubocop.yml +1 -2
- data/CHANGELOG.md +13 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/lib/cuid2/version.rb +1 -1
- data/lib/cuid2.rb +7 -12
- metadata +8 -9
- data/Gemfile.lock +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd089934aa9c92e1a739506370ddd051a7ac547ce4f0d146384aba1441161653
|
4
|
+
data.tar.gz: b79970213bb1c370211bb8138dd61e863905ff32abaf8d2b844b21659bbc10db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d91b851afeaddcb9dcc0b81cba723083fa419f0c6cfe4fb3193f4b6967a22eecde8cde2dfcc4cbea8308b42bd9a7c380d22677b86d6c1dc5820df5d821bd1f
|
7
|
+
data.tar.gz: f59aee5706e5b33b7787670e8816a7b773ade28322de2b8a75bc93716aefb7417f423a1cd9ce1ada56fc2f1ebb681f7eeb5b5c49aca109c81ae9cbce5f8771b2
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,16 @@
|
|
3
3
|
## [0.1.0] - 2023-02-18
|
4
4
|
|
5
5
|
- Initial release
|
6
|
+
|
7
|
+
## [1.0.1] - 2024-03-26
|
8
|
+
|
9
|
+
#### *Add random first character to CUID*
|
10
|
+
|
11
|
+
This commit introduces a change to the CUID generation process. Now, each
|
12
|
+
CUID starts with a random letter from 'a' to 'z'. This change is intended
|
13
|
+
to increase the uniqueness of each CUID and reduce the likelihood of
|
14
|
+
collisions.
|
15
|
+
|
16
|
+
The tests have been updated to reflect this change. A new test has been
|
17
|
+
added to ensure that the first character of the CUID is not always the
|
18
|
+
same.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Rubens Stulzer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -16,6 +16,25 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
16
|
|
17
17
|
$ gem install cuid2
|
18
18
|
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First require it.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'cuid2'
|
25
|
+
```
|
26
|
+
|
27
|
+
Generate a Cuid2 with call.
|
28
|
+
|
29
|
+
```
|
30
|
+
Cuid2.generate
|
31
|
+
=> "zw881lkfxx644yknviucss31"
|
32
|
+
Cuid2.call
|
33
|
+
=> "yra4dr2qteivp6kkur89gd11"
|
34
|
+
Cuid2.()
|
35
|
+
=> "cr6x94qpqagcgbay780xifun"
|
36
|
+
```
|
37
|
+
|
19
38
|
## Contributing
|
20
39
|
|
21
40
|
Bug reports and pull requests are welcome on GitHub at https://github.com/stulzer/cuid2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/stulzer/cuid2/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/cuid2/version.rb
CHANGED
data/lib/cuid2.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'cuid2/version'
|
4
4
|
require 'digest'
|
5
5
|
|
6
|
+
# CUID2 is a Ruby implementation of the CUID2 algorithm.
|
6
7
|
module Cuid2
|
7
8
|
# Entropy is a class that generates a random string of characters
|
8
9
|
class Entropy
|
@@ -37,20 +38,18 @@ module Cuid2
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
|
41
|
-
class Generate
|
42
|
-
DEFAULT_LENGTH = 24
|
41
|
+
DEFAULT_LENGTH = 24
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def generate(length = DEFAULT_LENGTH)
|
43
|
+
class << self
|
44
|
+
def call(length = DEFAULT_LENGTH)
|
45
|
+
random_letter = ('a'..'z').to_a[(rand * 26).floor]
|
49
46
|
hash_input = (time + Entropy.create(length) + count + fingerprint).to_s
|
50
47
|
|
51
48
|
"#{random_letter}#{Cuid2::Hash.create(hash_input, length)[2..length]}"
|
52
49
|
end
|
53
50
|
|
51
|
+
alias generate call
|
52
|
+
|
54
53
|
private
|
55
54
|
|
56
55
|
def time
|
@@ -69,10 +68,6 @@ module Cuid2
|
|
69
68
|
(rand + 1) * 2057
|
70
69
|
end
|
71
70
|
|
72
|
-
def random_letter
|
73
|
-
('a'..'z').to_a[(random * 26).floor]
|
74
|
-
end
|
75
|
-
|
76
71
|
def fingerprint
|
77
72
|
Cuid2::Hash.create("#{((random + 1) * 2063).floor} #{Object.constants.map(&:to_s)}")
|
78
73
|
end
|
metadata
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuid2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rubens Stulzer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
Use Cuid2, instead.
|
13
|
+
description: Secure, collision-resistant ids optimized for horizontal scaling and
|
14
|
+
performance.Next generation UUIDs. Need unique ids in your app? Forget UUIDs which
|
15
|
+
often collide in large apps.Use Cuid2, instead.
|
17
16
|
email:
|
18
17
|
- rubens.stulzer@gmail.com
|
19
18
|
executables: []
|
@@ -24,7 +23,7 @@ files:
|
|
24
23
|
- CHANGELOG.md
|
25
24
|
- CODE_OF_CONDUCT.md
|
26
25
|
- Gemfile
|
27
|
-
-
|
26
|
+
- LICENSE
|
28
27
|
- README.md
|
29
28
|
- Rakefile
|
30
29
|
- lib/cuid2.rb
|
@@ -45,14 +44,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
44
|
requirements:
|
46
45
|
- - ">="
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
47
|
+
version: 3.2.0
|
49
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
49
|
requirements:
|
51
50
|
- - ">="
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
53
|
requirements: []
|
55
|
-
rubygems_version: 3.4.
|
54
|
+
rubygems_version: 3.4.21
|
56
55
|
signing_key:
|
57
56
|
specification_version: 4
|
58
57
|
summary: Cuid2 is a Ruby implementation of the Cuid2 algorithm by Eric Elliott.
|
data/Gemfile.lock
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
cuid2 (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.2)
|
10
|
-
diff-lcs (1.5.0)
|
11
|
-
json (2.6.3)
|
12
|
-
parallel (1.22.1)
|
13
|
-
parser (3.2.1.0)
|
14
|
-
ast (~> 2.4.1)
|
15
|
-
rainbow (3.1.1)
|
16
|
-
rake (13.0.6)
|
17
|
-
regexp_parser (2.7.0)
|
18
|
-
rexml (3.2.5)
|
19
|
-
rspec (3.12.0)
|
20
|
-
rspec-core (~> 3.12.0)
|
21
|
-
rspec-expectations (~> 3.12.0)
|
22
|
-
rspec-mocks (~> 3.12.0)
|
23
|
-
rspec-core (3.12.1)
|
24
|
-
rspec-support (~> 3.12.0)
|
25
|
-
rspec-expectations (3.12.2)
|
26
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.12.0)
|
28
|
-
rspec-mocks (3.12.3)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.12.0)
|
31
|
-
rspec-support (3.12.0)
|
32
|
-
rubocop (1.45.1)
|
33
|
-
json (~> 2.3)
|
34
|
-
parallel (~> 1.10)
|
35
|
-
parser (>= 3.2.0.0)
|
36
|
-
rainbow (>= 2.2.2, < 4.0)
|
37
|
-
regexp_parser (>= 1.8, < 3.0)
|
38
|
-
rexml (>= 3.2.5, < 4.0)
|
39
|
-
rubocop-ast (>= 1.24.1, < 2.0)
|
40
|
-
ruby-progressbar (~> 1.7)
|
41
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
42
|
-
rubocop-ast (1.26.0)
|
43
|
-
parser (>= 3.2.1.0)
|
44
|
-
ruby-progressbar (1.11.0)
|
45
|
-
unicode-display_width (2.4.2)
|
46
|
-
|
47
|
-
PLATFORMS
|
48
|
-
arm64-darwin-22
|
49
|
-
|
50
|
-
DEPENDENCIES
|
51
|
-
cuid2!
|
52
|
-
rake (~> 13.0)
|
53
|
-
rspec (~> 3.0)
|
54
|
-
rubocop (~> 1.21)
|
55
|
-
|
56
|
-
BUNDLED WITH
|
57
|
-
2.4.6
|