glecuid/cuid2
Values
pub fn create_id() -> String
Generates a CUIDv2 using the default generator.
Examples
cuid2.create_id()
// -> "avu4793cnw6ljhov1s7Oxidg"
pub fn generate(g: @internal Generator) -> String
Generates a CUIDv2 using custom generator.
Examples
cuid2.new()
|> cuid2.with_length(10)
|> cuid2.with_fingerprint("my_machine")
|> cuid2.with_counter(fn() { int.random(100) })
|> cuid2.with_randomizer(fn() { 0.5 })
|> cuid2.generate()
// -> "av77nekw5e"
pub fn is_cuid(input: String) -> Bool
Determines whether or not the string is a valid CUIDv2.
pub fn new() -> @internal Generator
Creates a Generator with default values to be customized.
pub fn with_counter(
g: @internal Generator,
counter: fn() -> Int,
) -> @internal Generator
Sets a custom counter to be used by the Generator.
Counter is a function that returns an incrementing Int
every time it is called.
pub fn with_fingerprint(
g: @internal Generator,
fingerprint: String,
) -> @internal Generator
Sets a custom fingerprint to be used by the Generator.
Fingerprint is a unique String to help prevent collision
when generating ids in a distributed system.
pub fn with_length(
g: @internal Generator,
length: Int,
) -> @internal Generator
Sets the length of the ids generated by the Generator.
pub fn with_random_counter(
g: @internal Generator,
) -> @internal Generator
Sets a random counter to be used by the Generator.
This counter returns a random Int instead of an incrementing value.
pub fn with_randomizer(
g: @internal Generator,
randomizer: fn() -> Float,
) -> @internal Generator
Sets a custom randomizer to be used by the Generator.
Randomizer is a function that returns a random Float
between zero (inclusive) and one (exclusive).