mirror of
https://github.com/Yu-Vitaqua-fer-Chronos/NULID.git
synced 2025-07-27 15:41:47 +00:00
Compare commits
No commits in common. "8c3165a000e9ee1fd1489b5746b2c647c25d0776" and "f998c0d751c6896423735397080bd9c59bf98327" have entirely different histories.
8c3165a000
...
f998c0d751
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
|
@ -1,10 +1,7 @@
|
||||||
name: Run Tests
|
name: Run Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
[push, pull_request]
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
nim-version: 'stable'
|
nim-version: 'stable'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.3.0"
|
version = "1.2.0"
|
||||||
author = "Yu Vitaqua fer Chronos"
|
author = "Yu Vitaqua fer Chronos"
|
||||||
description = "An implementation of ULID!"
|
description = "An implementation of ULID!"
|
||||||
license = "CC0"
|
license = "CC0"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import std/[
|
import std/[
|
||||||
times,
|
times
|
||||||
json
|
|
||||||
]
|
]
|
||||||
|
|
||||||
import crockfordb32
|
import crockfordb32
|
||||||
|
@ -29,9 +28,10 @@ when not NoLocks:
|
||||||
Note: There are 2 defines that can be passed to the compiler to trigger different
|
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:
|
functionality in this library at runtime, they are listed here:
|
||||||
- `--define:nulidInsecureRandom`: Uses `std/random` instead of `std/sysrand`.
|
- `--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):
|
when not defined(js):
|
||||||
|
@ -176,9 +176,6 @@ proc wait(gen: ULIDGenerator): int64 {.gcsafe.} =
|
||||||
proc ulid*(gen: ULIDGenerator, timestamp = LowInt48, randomness = LowUint80): ULID {.gcsafe.} =
|
proc ulid*(gen: ULIDGenerator, timestamp = LowInt48, randomness = LowUint80): ULID {.gcsafe.} =
|
||||||
## Generate a `ULID`, if timestamp is equal to `0`, the `randomness` parameter
|
## Generate a `ULID`, if timestamp is equal to `0`, the `randomness` parameter
|
||||||
## will be ignored.
|
## will be ignored.
|
||||||
##
|
|
||||||
## See also:
|
|
||||||
## * `ulid(int64, UInt128) <#ulid_2>`_
|
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let gen = initUlidGenerator()
|
let gen = initUlidGenerator()
|
||||||
|
|
||||||
|
@ -327,14 +324,6 @@ func `$`*(ulid: ULID): string =
|
||||||
else:
|
else:
|
||||||
result = JsBigInt.encode(ulid.toInt128(), 26)
|
result = JsBigInt.encode(ulid.toInt128(), 26)
|
||||||
|
|
||||||
# std/json support
|
|
||||||
proc `%`*(u: ULID): JsonNode = newJString($u)
|
|
||||||
|
|
||||||
proc to*(j: JsonNode, _: typedesc[ULID]): ULID =
|
|
||||||
if j.kind != JString:
|
|
||||||
raise newException(JsonKindError, "Expected a string!")
|
|
||||||
|
|
||||||
result = ULID.parse(j.getStr())
|
|
||||||
|
|
||||||
when HasJsony:
|
when HasJsony:
|
||||||
import jsony
|
import jsony
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
# the letter 't').
|
# the letter 't').
|
||||||
#
|
#
|
||||||
# To run these tests, simply execute `nimble test`.
|
# To run these tests, simply execute `nimble test`.
|
||||||
import std/[
|
|
||||||
unittest,
|
import unittest
|
||||||
json
|
|
||||||
]
|
|
||||||
|
|
||||||
const UlidRandStr = "541019288874337045949482"
|
const UlidRandStr = "541019288874337045949482"
|
||||||
|
|
||||||
|
@ -49,9 +47,3 @@ when not defined(js):
|
||||||
|
|
||||||
check ulid == ULID.fromBytes(ulidBytes)
|
check ulid == ULID.fromBytes(ulidBytes)
|
||||||
check ulid.toBytes == ulidBytes
|
check ulid.toBytes == ulidBytes
|
||||||
|
|
||||||
test "ULID std/json support":
|
|
||||||
let ulid = ULID.parse("01H999MBGTEA8BDS0M5AWEBB1A")
|
|
||||||
|
|
||||||
check (%ulid).getStr() == "01H999MBGTEA8BDS0M5AWEBB1A"
|
|
||||||
check (%ulid).to(ULID) == ulid
|
|
Loading…
Reference in a new issue