Skip to content

Commit

Permalink
chore: format files
Browse files Browse the repository at this point in the history
  • Loading branch information
okkdev authored and rvcas committed Jun 4, 2024
1 parent 2952d87 commit 0b8ca6f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
13 changes: 6 additions & 7 deletions src/ids/cuid.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -161,8 +161,7 @@ fn get_fingerprint() -> String {

let hostid = { sum + list.length(localhost) + base } % operator

id
+ hostid
id + hostid
|> int.to_base36()
}

Expand Down
6 changes: 4 additions & 2 deletions src/ids/nanoid.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/ids/snowflake.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/ids/cuid_test.gleam
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
10 changes: 5 additions & 5 deletions test/ids/nanoid_test.gleam
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 4 additions & 4 deletions test/ids/snowflake_test.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/ids/ulid_test.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/ids/uuid_test.gleam
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 0b8ca6f

Please sign in to comment.