Compare commits

..

No commits in common. "a5d234e0c204f38fc2fbd9827e120f0513b84bb3" and "d0470fca92b68b8ea78946a8544fcc917ff6109d" have entirely different histories.

4 changed files with 9 additions and 31 deletions

View file

@ -1,10 +1,7 @@
name: Run Tests
on:
pull_request:
push:
branches:
- '**'
[push, pull_request]
env:
nim-version: 'stable'

View file

@ -1,6 +1,6 @@
# Package
version = "1.3.0"
version = "1.2.0"
author = "Yu Vitaqua fer Chronos"
description = "An implementation of ULID!"
license = "CC0"

View file

@ -1,6 +1,5 @@
import std/[
times,
json
times
]
import crockfordb32
@ -29,9 +28,10 @@ when not NoLocks:
Note: There are 2 defines that can be passed to the compiler to trigger different
functionality in this library at runtime, they are listed here:
- `--define:nulidInsecureRandom`: Uses `std/random` instead of `std/sysrand`.
- `--define:nulidNoLocks`: Disables the use of locks.
- `--define:nulidNoLocks`
The JS backend used `-d:nulidNoLocks` by default.
The JS backend used `-d:nulidNoLocks` by default and Nimscript uses both.
these flags by default (whether either work with NULID is untested).
]##
when not defined(js):
@ -58,7 +58,7 @@ type
ULIDGenerator* = ref object
## A `ULID` generator object, contains details needed to follow the spec.
## A generator was made to be compliant with the ULID spec and also to be
## threadsafe.
## threadsafe not use globals that could change.
when NoLocks:
lastTime: int64 # Timestamp of last ULID, 48 bits
when not defined(js):
@ -327,17 +327,6 @@ func `$`*(ulid: ULID): string =
else:
result = JsBigInt.encode(ulid.toInt128(), 26)
# std/json support
proc `%`*(u: ULID): JsonNode =
## Serializes a `ULID` to JSON.
newJString($u)
proc to*(j: JsonNode, _: typedesc[ULID]): ULID =
## Deserializes a `ULID` from JSON.
if j.kind != JString:
raise newException(JsonKindError, "Expected a string!")
result = ULID.parse(j.getStr())
when HasJsony:
import jsony

View file

@ -4,10 +4,8 @@
# the letter 't').
#
# To run these tests, simply execute `nimble test`.
import std/[
unittest,
json
]
import unittest
const UlidRandStr = "541019288874337045949482"
@ -49,9 +47,3 @@ when not defined(js):
check ulid == ULID.fromBytes(ulidBytes)
check ulid.toBytes == ulidBytes
test "ULID std/json support":
let ulid = ULID.parse("01H999MBGTEA8BDS0M5AWEBB1A")
check (%ulid).getStr() == "01H999MBGTEA8BDS0M5AWEBB1A"
check (%ulid).to(ULID) == ulid