This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-24
Channels
- # babashka (19)
- # beginners (43)
- # calva (10)
- # clj-kondo (3)
- # cljsrn (8)
- # clojure (106)
- # clojure-europe (8)
- # clojure-hungary (5)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (14)
- # core-typed (1)
- # graalvm (2)
- # graphql (1)
- # malli (2)
- # membrane (9)
- # observability (2)
- # off-topic (66)
- # polylith (3)
- # practicalli (3)
- # re-frame (17)
- # reagent (3)
- # remote-jobs (7)
- # rewrite-clj (17)
- # sci (29)
- # shadow-cljs (45)
- # sql (5)
- # tools-deps (15)
- # vim (8)
is there a way to work with bigints in cljs? trying to coerce a string (reitit route) to one
bigints are a headache with transit, just ended up using Long
(defn -string->bigint [x]
(if (string? x)
(try
#?(:clj (Long/parseLong x)
:cljs (let [x' (js/parseInt x)]
(if (> x' js/Number.MAX_SAFE_INTEGER)
(goog.math.Long/fromString x 10)
x')))
(catch #?(:clj Exception, :cljs js/Error) _ x))
x))
(defn string-transformer []
(mt/transformer
{:name :string
:decoders (assoc (mt/-string-decoders)
:i64 -string->bigint)
:encoders (assoc (mt/-string-encoders)
:i64 mt/-any->string)}))