Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 5bfae80

Browse files
committed
Add a ulid provider
1 parent 8ec215b commit 5bfae80

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ a field within the JSON object.
1919

2020
- uuid1
2121
- uuid4
22+
- ulid
2223
- null
2324
- randomBool
2425
- randomChar

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies:
3838
- regex-tdfa
3939
- optparse-applicative
4040
- time
41+
- ulid
4142

4243
library:
4344
source-dirs: src

src/Fake.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import Data.Time.Calendar (Day (..), showGregorian)
3131
import Data.Time.Clock (UTCTime (..), secondsToDiffTime)
3232
import Data.Time.Format (defaultTimeLocale, formatTime,
3333
iso8601DateFormat, parseTimeM)
34+
import qualified Data.ULID as ULID
35+
import Data.ULID.Random (mkULIDRandom)
36+
import Data.ULID.TimeStamp (getULIDTimeStamp)
3437
import qualified Data.UUID as UUID
3538
import qualified Data.UUID.V1 as UUID1
3639
import qualified Data.Vector as V
@@ -333,6 +336,12 @@ dayAsValue :: Day -> Value
333336
dayAsValue = String . T.pack . showGregorian
334337

335338

339+
getUlid :: Fake Value
340+
getUlid = ULID.ULID
341+
<$> liftIO getULIDTimeStamp <*> State.state mkULIDRandom
342+
<&> String . T.pack . show
343+
344+
336345
-- | Create a value getter for an expression
337346
--
338347
-- >>> exec "uuid4"
@@ -347,6 +356,7 @@ eval (StringLiteral x) = pure $ String x
347356
eval (DoubleLiteral x) = pure $ Number x
348357
eval (FunctionCall "uuid4" []) = String . UUID.toText <$> State.state random
349358
eval (FunctionCall "uuid1" []) = String . UUID.toText <$> liftIO uuid1
359+
eval (FunctionCall "ulid" []) = getUlid
350360
eval (FunctionCall "null" []) = pure Null
351361
eval (FunctionCall "randomBool" []) = randomBool
352362
eval (FunctionCall "randomChar" []) = randomChar

stack.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ resolver: lts-13.0
44
packages:
55
- .
66

7-
extra-deps: []
7+
extra-deps:
8+
- ulid-0.2.0.0@sha256:ac415298b0272479909ca576f4444862ae942ed85c7849fa0675e3bf496be6f3
9+
- crockford-0.2@sha256:6ec593711a20bd4b81a0fc13f3d850d2d890690941d777230fbf980c483e434a

0 commit comments

Comments
 (0)