Title: | Generate Short Unique YouTube-Like IDs (Hashes) from Integers |
---|---|
Description: | An R port of the hashids library. hashids generates YouTube-like hashes from integers or vector of integers. Hashes generated from integers are relatively short, unique and non-seqential. hashids can be used to generate unique ids for URLs and hide database row numbers from the user. By default hashids will avoid generating common English cursewords by preventing certain letters being next to each other. hashids are not one-way: it is easy to encode an integer to a hashid and decode a hashid back into an integer. |
Authors: | Alex Shum [aut, cre], Ivan Akimov [aut] (original author of hashids -- implemented in javascript), David Aurelio [ctb] (implemented hashids in python 2 and 3) |
Maintainer: | Alex Shum <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.0.9000 |
Built: | 2025-03-04 05:33:10 UTC |
Source: | https://github.com/alshum/hashids-r |
Calculate the ascii value number of a character
ascii_val(char)
ascii_val(char)
char |
character |
ascii value integer
Converts a base 16 string to a base 10 number. Because I couldn't get base R functions to work for big hex numbers.
base16_to_dec(str_16)
base16_to_dec(str_16)
str_16 |
base 16 number as a string. |
base 10 integer.
Converts a base 10 number to base 16 number. Because I couldn't get R's as.hexmode() to work for big integers.
dec_to_base16(dec)
dec_to_base16(dec)
dec |
base 10 integer |
base 16 number as a string
Decodes a hashid into the original integer or integer vector
decode(hash_str, settings)
decode(hash_str, settings)
hash_str |
hashid string to decode into integer or integer vector |
settings |
Settings list generated by hashid_settings |
integer or integer vector
Decodes a hashid into the original hexidecimal number
decode_hex(hashid, settings)
decode_hex(hashid, settings)
hashid |
hashid to decode |
settings |
Settings list generated by hashid_settings |
hexidecimal number as a string
Encodes an integer or integer vector into a hashid string. All numbers must be non-negative integers.
encode(int, settings)
encode(int, settings)
int |
Integer or integer vector to encode |
settings |
Settings list generated by hashid_settings |
hashid string
Encodes a hexademical number into a hashid
encode_hex(hex_str, settings)
encode_hex(hex_str, settings)
hex_str |
Hexadecimal number as string |
settings |
Settings list generated by hashid_settings |
hashid string
Enforces hashid minimum length by padding the hashid with additional characters.
enforce_min_length(encoded, min_length, alphabet, guards, values_hash)
enforce_min_length(encoded, min_length, alphabet, guards, values_hash)
encoded |
encoded hashid |
min_length |
minimum length required for hashid |
alphabet |
set of letters used to generate hashid |
guards |
set of guards used to generate hashid |
values_hash |
value hashed used to select guard characters |
hashid with padded characters to insure minimum length
Maps an integer to a string. Generated string will be inversely proportional to alphabet length.
hash(number, alphabet)
hash(number, alphabet)
number |
Integer to hash |
alphabet |
Possible letters for string. |
hashed string
Default alphabet, separators, and ratio of character separators and guards for hashid
DEFAULT_ALPHABET DEFAULT_SEPS RATIO_SEPARATORS RATIO_GUARDS
DEFAULT_ALPHABET DEFAULT_SEPS RATIO_SEPARATORS RATIO_GUARDS
chr "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
http://www.hashids.org
A function to create a hashid settings list.
hashid_settings(salt, min_length = 0, alphabet = DEFAULT_ALPHABET, sep = DEFAULT_SEPS)
hashid_settings(salt, min_length = 0, alphabet = DEFAULT_ALPHABET, sep = DEFAULT_SEPS)
salt |
An additional string to make hashids more unique. |
min_length |
Minimum length for hashid. |
alphabet |
String of characters for hashid. |
sep |
String of characters to use as separators. |
A list of parameters used in encoding and decoding.
Permutes the characters in a string based on an inputted salt string.
shuffle(string, salt)
shuffle(string, salt)
string |
String to be permuted |
salt |
cryptograph salt string that is used to permute strings |
shuffled string
Splits a string based on a set of splitting characters
split(string, splitters)
split(string, splitters)
string |
String to split |
splitters |
set of splitting characters as a string |
split vector of characters
Unhashes a string to an integer based on alphabet.
unhash(hashed, alphabet)
unhash(hashed, alphabet)
hashed |
String to unhash |
alphabet |
Set of letters used for hashing |
Unhashed integer