From 6e277df64a0c245fc7a2e021c5e07e21540f4c7a Mon Sep 17 00:00:00 2001 From: rhy <81539300+rhynomatt@users.noreply.github.com> Date: Wed, 11 Jan 2023 10:38:52 -0300 Subject: [PATCH] Rename uuid.lua to identifier.lua --- .test/tests.lua | 8 ++++---- uuid.lua => identifier.lua | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) rename uuid.lua => identifier.lua (92%) diff --git a/.test/tests.lua b/.test/tests.lua index 1474625..6159dcf 100644 --- a/.test/tests.lua +++ b/.test/tests.lua @@ -5,7 +5,7 @@ package.path = package.path .. ";../?.lua" local assert = require("batteries.assert") local tablex = require("batteries.tablex") -local uuid = require("batteries.uuid") +local identifier = require("batteries.identifier") -- tablex {{{ @@ -159,7 +159,7 @@ end local function test_uuid4() for i = 1, 100 do - local id = uuid.uuid4() + local id = identifier.uuid4() -- right len assert(#id == 36) @@ -182,12 +182,12 @@ end local function test_ulid() for i = 1, 100 do - local ulid = assert(uuid.ulid()) + local ulid = assert(identifier.ulid()) -- right len assert(#ulid == 26) -- have the same timestamp with the same time - local a, b = uuid.ulid(nil, 1):sub(1, 10), uuid.ulid(nil, 1):sub(1, 10) + local a, b = identifier.ulid(nil, 1):sub(1, 10), identifier.ulid(nil, 1):sub(1, 10) assert(a == b) -- don't have characters out of crockford base32 assert(not ulid:match("[ILOU%l]")) diff --git a/uuid.lua b/identifier.lua similarity index 92% rename from uuid.lua rename to identifier.lua index b252db2..0caf837 100644 --- a/uuid.lua +++ b/identifier.lua @@ -1,5 +1,5 @@ --[[ - uuid/ulid generation + identifier generation uuid is version 4, ulid is an alternative to uuid (see https://github.com/ulid/spec). @@ -9,9 +9,9 @@ within the same second yet ]] -local path = (...):gsub("uuid", "") +local path = (...):gsub("identifier", "") -local uuid = {} +local identifier = {} --(internal; use a provided random generator object, or not) local function _random(rng, ...) @@ -23,7 +23,7 @@ end local uuid4_template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" --generate a UUID version 4 -function uuid.uuid4(rng) +function identifier.uuid4(rng) --x should be 0x0-0xf, the single y should be 0x8-0xb --4 should always just be 4 (denoting uuid version) local out = uuid4_template:gsub("[xy]", function (c) @@ -54,7 +54,7 @@ end --generate an ULID using this rng at this time (now by default) --implementation based on https://github.com/Tieske/ulid.lua -function uuid.ulid(rng, time) +function identifier.ulid(rng, time) time = math.floor((time or _now()) * 1000) local time_part = {} @@ -73,4 +73,4 @@ function uuid.ulid(rng, time) return table.concat(time_part) .. table.concat(random_part) end -return uuid +return identifier