nanoid 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/nanoid.rb +12 -15
- data/lib/nanoid/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8be37a0041248f42abd8449d04aea6562c82d6f5024ecd96f2822a234f174e5e
|
4
|
+
data.tar.gz: f25ad50c1113a25faeebd80f1e1e982c5d269ee600d6c39434247951535e1028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39b1f9dc17118b306e6da1278756a4a786cc4fd5b7c7146dd971c80acb65787717158f6e1ed6cea44fc29b9bbf56fe30e036042b84acdd2efdbf0858d44a2467
|
7
|
+
data.tar.gz: be9753553725d9935464b09b85a60e6be23b54543bac1f8067758b156f4cbafb23b5fbfe98eb864d522f8b5dd360887a620a2dd05fd8e8a9ce3725d3f9734b69
|
data/lib/nanoid.rb
CHANGED
@@ -14,8 +14,8 @@ module Nanoid
|
|
14
14
|
def self.simple_generate(size:)
|
15
15
|
bytes = random_bytes(size)
|
16
16
|
|
17
|
-
(0...size).reduce('') do |acc, i|
|
18
|
-
acc
|
17
|
+
(0...size).reduce(''.dup) do |acc, i|
|
18
|
+
acc << SAFE_ALPHABET[bytes[i] & 63]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,22 +24,19 @@ module Nanoid
|
|
24
24
|
mask = (2 << Math.log(alphabet_size - 1) / Math.log(2)) - 1
|
25
25
|
step = (1.6 * mask * size / alphabet_size).ceil
|
26
26
|
|
27
|
-
id = ''
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
27
|
+
id = ''.dup
|
28
|
+
|
29
|
+
loop do
|
30
|
+
bytes = random_bytes(size)
|
31
|
+
(0...step).each do |idx|
|
32
|
+
byte = bytes[idx] & mask
|
33
|
+
character = byte && alphabet[byte]
|
34
|
+
if character
|
35
|
+
id << character
|
36
|
+
return id if id.size == size
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
42
|
-
id
|
43
40
|
end
|
44
41
|
|
45
42
|
def self.random_bytes(size)
|
data/lib/nanoid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radovan Smitala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.7.7
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Ruby implementation of Nanoid, secure URL-friendly unique ID generator
|