From 0b8ca6f332ffea56ed86eaa0cbdb170b2f24bd33 Mon Sep 17 00:00:00 2001 From: okkdev Date: Tue, 4 Jun 2024 16:50:37 +0200 Subject: [PATCH] chore: format files --- src/ids/cuid.gleam | 13 ++++++------- src/ids/nanoid.gleam | 6 ++++-- src/ids/snowflake.gleam | 8 ++++---- test/ids/cuid_test.gleam | 6 +++--- test/ids/nanoid_test.gleam | 10 +++++----- test/ids/snowflake_test.gleam | 8 ++++---- test/ids/ulid_test.gleam | 6 +++--- test/ids/uuid_test.gleam | 4 ++-- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/ids/cuid.gleam b/src/ids/cuid.gleam index f88d30e..8ec0815 100644 --- a/src/ids/cuid.gleam +++ b/src/ids/cuid.gleam @@ -6,11 +6,11 @@ //// Slugs are also supported. //// +import gleam/erlang.{Millisecond} +import gleam/erlang/process.{type Subject} import gleam/int import gleam/list -import gleam/erlang.{Millisecond} import gleam/otp/actor.{type Next, type StartResult} -import gleam/erlang/process.{type Subject} import gleam/string /// The messages handled by the actor. @@ -88,15 +88,15 @@ fn handle_msg(msg: Message, state: State) -> Next(Message, State) { let slug = format_id([ timestamp() - |> string.slice(-2, 2), + |> string.slice(-2, 2), format_count(state.count) - |> string.slice(-4, 4), + |> string.slice(-4, 4), string.concat([ string.slice(state.fingerprint, 0, 1), string.slice(state.fingerprint, -1, 1), ]), random_block() - |> string.slice(-2, 2), + |> string.slice(-2, 2), ]) actor.send(reply, slug) actor.continue(State(..state, count: new_count(state.count))) @@ -161,8 +161,7 @@ fn get_fingerprint() -> String { let hostid = { sum + list.length(localhost) + base } % operator - id - + hostid + id + hostid |> int.to_base36() } diff --git a/src/ids/nanoid.gleam b/src/ids/nanoid.gleam index ab2b930..455a945 100644 --- a/src/ids/nanoid.gleam +++ b/src/ids/nanoid.gleam @@ -2,11 +2,11 @@ //// and unique string IDs. //// -import gleam/string import gleam/bit_array import gleam/float import gleam/int import gleam/list +import gleam/string /// The default alphabet used when generating NanoIDs. pub const default_alphabet: BitArray = << @@ -172,7 +172,9 @@ fn calculate_mask(alphabet_length: Int) -> Int { fn calculate_step(mask: Int, size: Int, alphabet_length: Int) -> Int { let step: Float = float.ceiling( - 1.6 *. int.to_float(mask) *. int.to_float(size) + 1.6 + *. int.to_float(mask) + *. int.to_float(size) /. int.to_float(alphabet_length), ) float.round(step) diff --git a/src/ids/snowflake.gleam b/src/ids/snowflake.gleam index 000234a..79b754a 100644 --- a/src/ids/snowflake.gleam +++ b/src/ids/snowflake.gleam @@ -1,11 +1,11 @@ //// A module for generating Snowflake IDs. -import gleam/int -import gleam/string -import gleam/result import gleam/erlang -import gleam/otp/actor.{type Next} import gleam/erlang/process.{type Subject} +import gleam/int +import gleam/otp/actor.{type Next} +import gleam/result +import gleam/string @external(erlang, "binary", "encode_unsigned") fn encode_unsigned(i: Int) -> BitArray diff --git a/test/ids/cuid_test.gleam b/test/ids/cuid_test.gleam index a47bbb0..cf6d77b 100644 --- a/test/ids/cuid_test.gleam +++ b/test/ids/cuid_test.gleam @@ -1,9 +1,9 @@ -import gleeunit/should -import ids/cuid -import gleam/iterator.{Done, Next} import gleam/dict +import gleam/iterator.{Done, Next} import gleam/pair import gleam/string +import gleeunit/should +import ids/cuid pub fn gen_test() { let assert Ok(channel) = cuid.start() diff --git a/test/ids/nanoid_test.gleam b/test/ids/nanoid_test.gleam index 624dd03..4ddb83b 100644 --- a/test/ids/nanoid_test.gleam +++ b/test/ids/nanoid_test.gleam @@ -1,10 +1,10 @@ -import gleeunit -import ids/nanoid -import gleeunit/should -import gleam/list -import gleam/string import gleam/bit_array +import gleam/list import gleam/set.{type Set} +import gleam/string +import gleeunit +import gleeunit/should +import ids/nanoid pub fn main() { gleeunit.main() diff --git a/test/ids/snowflake_test.gleam b/test/ids/snowflake_test.gleam index 3fe446f..04af020 100644 --- a/test/ids/snowflake_test.gleam +++ b/test/ids/snowflake_test.gleam @@ -1,9 +1,9 @@ -import ids/snowflake -import gleeunit/should -import gleam/string +import gleam/erlang import gleam/int import gleam/list -import gleam/erlang +import gleam/string +import gleeunit/should +import ids/snowflake pub fn gen_test() { let machine_id = 1 diff --git a/test/ids/ulid_test.gleam b/test/ids/ulid_test.gleam index 4c6fbe1..b120df8 100644 --- a/test/ids/ulid_test.gleam +++ b/test/ids/ulid_test.gleam @@ -1,8 +1,8 @@ -import ids/ulid -import gleeunit/should -import gleam/string import gleam/list import gleam/result +import gleam/string +import gleeunit/should +import ids/ulid @external(erlang, "binary", "decode_unsigned") fn decode_unsigned(b: BitArray) -> Int diff --git a/test/ids/uuid_test.gleam b/test/ids/uuid_test.gleam index b63254c..11e898b 100644 --- a/test/ids/uuid_test.gleam +++ b/test/ids/uuid_test.gleam @@ -1,7 +1,7 @@ -import gleeunit/should -import ids/uuid import gleam/bit_array import gleam/erlang +import gleeunit/should +import ids/uuid pub fn gen_v4_test() { let assert Ok(id) = uuid.generate_v4()