Skip to content

Commit

Permalink
SAFE_ALPHABET -> URL_ALPHABET
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Jan 8, 2025
1 parent 7439b8b commit 699b66c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/nanoid_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe Nanoid do
id = Nanoid.generate

(0...id.size).each do |j|
(Nanoid::SAFE_ALPHABET.index(id[j])).should_not be_nil
(Nanoid::URL_ALPHABET.index(id[j])).should_not be_nil
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/nanoid.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Nanoid
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}

SAFE_ALPHABET = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
URL_ALPHABET = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

def self.generate(size = 21, alphabet = SAFE_ALPHABET, secure = true) : String
def self.generate(size = 21, alphabet = URL_ALPHABET, secure = true) : String
return non_secure_generate(size, alphabet) unless secure

return simple_generate(size) if alphabet == SAFE_ALPHABET
return simple_generate(size) if alphabet == URL_ALPHABET

complex_generate(size: size, alphabet: alphabet)
end
Expand All @@ -21,7 +21,7 @@ module Nanoid
# range to the 0-63 value range. Therefore, adding hacks, such
# as empty string fallback or magic numbers, is unneccessary because
# the bitmask trims bytes down to the alphabet size.
buffer[i] = SAFE_ALPHABET[bytes[i] & 63].ord.to_u8
buffer[i] = URL_ALPHABET[bytes[i] & 63].ord.to_u8
end

{size, size}
Expand Down

0 comments on commit 699b66c

Please sign in to comment.