Version bump, add version in docs

This commit is contained in:
Yu Vitaqua fer Chronos 2023-10-12 22:43:02 +01:00
parent 0007fd249e
commit 0976774b98
5 changed files with 28 additions and 11 deletions

View file

@ -1,6 +1,8 @@
import src/nulid/private/constants
# Package
version = "0.2.3"
version = NulidVersion
author = "Yu Vitaqua fer Chronos"
description = "An implementation of ULID!"
license = "CC0"

View file

@ -8,11 +8,16 @@ import pkg/[
nint128
]
import ./nulid/private/[
dochelpers,
constants
]
import ./nulid/private/stew/endians2
const insecureRandom = defined(nulidInsecureRandom) or defined(js) # No sysrand on the JS backend
fmtCmnt "NULID Version: {NulidVersion}"
when insecureRandom:
when InsecureRandom:
import std/random
else:
@ -23,8 +28,8 @@ const HighUint80 = u128("1208925819614629174706176")
type
NULID* = object
## An object representing a ULID.
timestamp*: int64 = 0
randomness*: UInt128 = 0.u128
timestamp*: int64
randomness*: UInt128
NULIDGenerator* = ref object
## A NULID generator object, contains details needed to follow the spec.
@ -33,14 +38,14 @@ type
lastTime: int64 # Timestamp of last ULID
random: UInt128 # A random number
when insecureRandom:
when InsecureRandom:
rand: Rand # Random generator when using insecure random
proc initNulidGenerator*(): NULIDGenerator =
## Initialises a `NULIDGenerator` for use.
result = NULIDGenerator(lastTime: 0, random: 0.u128)
when insecureRandom:
when InsecureRandom:
result.rand = initRand()
# Discouraged to use it but it's fine for single-threaded apps really
@ -56,7 +61,7 @@ func toArray[T](oa: openArray[T], size: static Slice[int]): array[size.len, T] =
proc randomBits(n: NULIDGenerator): UInt128 =
var arr: array[16, byte]
when insecureRandom:
when InsecureRandom:
var rnd: array[10, byte]
rnd[0..7] = cast[array[8, byte]](n.rand.next())

View file

@ -0,0 +1,4 @@
# No sysrand on the JS backend nor VM
const InsecureRandom* = defined(nulidInsecureRandom) or defined(js) or defined(nimvm)
const NulidVersion* = "0.2.4"

View file

@ -0,0 +1,8 @@
import std/[
strformat,
macros
]
macro ct(s: static string) = newCommentStmtNode(s)
template fmtCmnt*(s: static string): untyped = ct(&s)

View file

@ -11,11 +11,9 @@ import pkg/nint128
import nulid
let gen = initNulidGenerator()
test "NULID Generation":
for _ in 0..5:
let nulid = gen.nulidSync()
let nulid = nulidSync()
echo nulid
test "NULID Parsing":