File tree Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 1
1
name : Run Tests
2
2
3
3
on :
4
- [push, pull_request]
4
+ pull_request
5
+ push :
6
+ branches :
7
+ - ' **'
5
8
6
9
env :
7
10
nim-version : ' stable'
Original file line number Diff line number Diff line change 1
1
# Package
2
2
3
- version = " 1.2 .0"
3
+ version = " 1.3 .0"
4
4
author = " Yu Vitaqua fer Chronos"
5
5
description = " An implementation of ULID!"
6
6
license = " CC0"
Original file line number Diff line number Diff line change 1
1
import std/ [
2
- times
2
+ times,
3
+ json
3
4
]
4
5
5
6
import crockfordb32
@@ -28,10 +29,9 @@ when not NoLocks:
28
29
Note: There are 2 defines that can be passed to the compiler to trigger different
29
30
functionality in this library at runtime, they are listed here:
30
31
- `--define:nulidInsecureRandom`: Uses `std/random` instead of `std/sysrand`.
31
- - `--define:nulidNoLocks`
32
+ - `--define:nulidNoLocks`: Disables the use of locks.
32
33
33
- The JS backend used `-d:nulidNoLocks` by default and Nimscript uses both.
34
- these flags by default (whether either work with NULID is untested).
34
+ The JS backend used `-d:nulidNoLocks` by default.
35
35
]##
36
36
37
37
when not defined(js):
@@ -327,6 +327,14 @@ func `$`*(ulid: ULID): string =
327
327
else :
328
328
result = JsBigInt.encode(ulid.toInt128(), 26 )
329
329
330
+ # std/json support
331
+ proc `%` * (u: ULID): JsonNode = newJString($ u)
332
+
333
+ proc to* (j: JsonNode, _: typedesc [ULID]) : ULID =
334
+ if j.kind != JString:
335
+ raise newException(JsonKindError, " Expected a string!" )
336
+
337
+ result = ULID.parse(j.getStr())
330
338
331
339
when HasJsony:
332
340
import jsony
Original file line number Diff line number Diff line change 4
4
# the letter 't').
5
5
#
6
6
# To run these tests, simply execute `nimble test`.
7
-
8
- import unittest
7
+ import std/ [
8
+ unittest,
9
+ json
10
+ ]
9
11
10
12
const UlidRandStr = " 541019288874337045949482"
11
13
@@ -47,3 +49,9 @@ when not defined(js):
47
49
48
50
check ulid == ULID.fromBytes(ulidBytes)
49
51
check ulid.toBytes == ulidBytes
52
+
53
+ test " ULID std/json support" :
54
+ let ulid = ULID.parse(" 01H999MBGTEA8BDS0M5AWEBB1A" )
55
+
56
+ check (% ulid).getStr() == " 01H999MBGTEA8BDS0M5AWEBB1A"
57
+ check (% ulid).to(ULID) == ulid
You can’t perform that action at this time.
0 commit comments