nanoid 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nanoid.rb +18 -2
  3. data/lib/nanoid/version.rb +1 -1
  4. metadata +24 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be37a0041248f42abd8449d04aea6562c82d6f5024ecd96f2822a234f174e5e
4
- data.tar.gz: f25ad50c1113a25faeebd80f1e1e982c5d269ee600d6c39434247951535e1028
3
+ metadata.gz: 3c430242702b77fa4e2feba4521d9f13c2c7bc4018f74f738701f6b9fc2ab64a
4
+ data.tar.gz: 0ead08a72370897eb4b32767d1216f814e1b97ad38ad3c3433a24031698d8270
5
5
  SHA512:
6
- metadata.gz: 39b1f9dc17118b306e6da1278756a4a786cc4fd5b7c7146dd971c80acb65787717158f6e1ed6cea44fc29b9bbf56fe30e036042b84acdd2efdbf0858d44a2467
7
- data.tar.gz: be9753553725d9935464b09b85a60e6be23b54543bac1f8067758b156f4cbafb23b5fbfe98eb864d522f8b5dd360887a620a2dd05fd8e8a9ce3725d3f9734b69
6
+ metadata.gz: fbc9131545a9f0acaf81563a8b6631ec31d8b27e6ee9581cd3b62b3f12f2cd26f75300e6a3a939f95fb2e95d6fc7b1c0f23d69c48e2d77ce16f76e5936b91b61
7
+ data.tar.gz: ac0d65a40e60983b635f939fc455ab408435364ea76636a71c5df02d2e5b25b6a551d2ea1168c3e5e5c8ef97a39adea4df096e57e29295cab169c9d13806c1a1
@@ -3,14 +3,18 @@
3
3
  require 'securerandom'
4
4
 
5
5
  module Nanoid
6
- SAFE_ALPHABET = '_~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
6
+ SAFE_ALPHABET = '_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
7
+
8
+ def self.generate(size: 21, alphabet: SAFE_ALPHABET, non_secure: false)
9
+ return non_secure_generate(size: size, alphabet: alphabet) if non_secure
7
10
 
8
- def self.generate(size: 21, alphabet: SAFE_ALPHABET)
9
11
  return simple_generate(size: size) if alphabet == SAFE_ALPHABET
10
12
 
11
13
  complex_generate(size: size, alphabet: alphabet)
12
14
  end
13
15
 
16
+ private
17
+
14
18
  def self.simple_generate(size:)
15
19
  bytes = random_bytes(size)
16
20
 
@@ -39,6 +43,18 @@ module Nanoid
39
43
  end
40
44
  end
41
45
 
46
+ def self.non_secure_generate(size:, alphabet:)
47
+ alphabet_size = alphabet.size
48
+
49
+ id = ''.dup
50
+
51
+ size.times do
52
+ id << alphabet[(Random.rand * alphabet_size).floor]
53
+ end
54
+
55
+ id
56
+ end
57
+
42
58
  def self.random_bytes(size)
43
59
  SecureRandom.random_bytes(size).bytes
44
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NanoId
4
- VERSION = '1.0.0'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.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: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: benchmark-ips
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '2.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: '1.15'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '12.0'
40
+ version: '1.15'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: reek
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '4.5'
75
+ version: '5.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '4.5'
82
+ version: '5.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement