aboutsummaryrefslogtreecommitdiff
path: root/lua/extregs/uuid.lua
diff options
context:
space:
mode:
authorJosh Rahm <rahm@josher.dev>2026-10-18 15:49:48 -0600
committerJosh Rahm <rahm@josher.dev>2026-10-18 15:49:48 -0600
commit7b15a3a4b4fb4dc6be5d53a22c20d68f8181d68b (patch)
treed3e08937bc78441a2f3d64ad6935337cf6d9b0be /lua/extregs/uuid.lua
downloadextregs.nvim-main.tar.gz
extregs.nvim-main.tar.bz2
extregs.nvim-main.zip
[extregs] initial commit.HEADmain
added a bunch of useful extregs
Diffstat (limited to 'lua/extregs/uuid.lua')
-rw-r--r--lua/extregs/uuid.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/lua/extregs/uuid.lua b/lua/extregs/uuid.lua
new file mode 100644
index 0000000..e23a37f
--- /dev/null
+++ b/lua/extregs/uuid.lua
@@ -0,0 +1,16 @@
+local util = require('extregs.util')
+local M = {}
+function M.get_provider(_)
+ return util.readonly(function()
+ local bytes = vim.uv.random(16)
+ assert(bytes and #bytes == 16, 'unable to obtain random bytes')
+ local b = { bytes:byte(1, 16) }
+ b[7] = (b[7] % 16) + 64
+ b[9] = (b[9] % 64) + 128
+ local h = {}
+ for i = 1, 16 do h[i] = string.format('%%02x', b[i]) end
+ return table.concat(h, '', 1, 4) .. '-' .. table.concat(h, '', 5, 6) .. '-' ..
+ table.concat(h, '', 7, 8) .. '-' .. table.concat(h, '', 9, 10) .. '-' .. table.concat(h, '', 11, 16)
+ end)
+end
+return M