penpot/frontend/src/uxbox/util/uuid.cljs
2020-01-21 12:17:49 +01:00

36 lines
1 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2016-2020 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.uuid
"Provides a UUID v4 uuid generation.
In difference with builtin `random-uuid` function this
implementation tries to use high quality RNG if is
available (browser crypto object or nodejs crypto module).
If no high qualiry RNG, switches to the default Math based
RNG with proper waring in the console."
(:refer-clojure :exclude [zero? next])
(:require [uxbox.util.uuid-impl :as impl]))
(def zero #uuid "00000000-0000-0000-0000-000000000000")
(defn zero?
[v]
(= zero v))
(defn next
"Generate a v1 (time-based) UUID."
[]
(uuid (impl/v1)))
(defn random
"Generate a v4 (random) UUID."
[]
(uuid (impl/v4)))