Cross-platform hex {en,de}coding.
jvm, node + npm, clj, shadow-cljs
{nuid/hex {:git/url "https://github.com/nuid/hex" :sha "..."}}
$ clj # or shadow-cljs node-repl
=> (require '[nuid.hex :as hex])
=> (def h (hex/encode "🐴")) ;; defaults to reading input as utf8
=> h ;; => "f09f90b4"
=> (hex/decode h) ;; => array-like: [240 159 144 180] (endianness may vary)
=> (hex/str h) ;; => "🐴"
=> (hex/str h :utf16le) ;; => "鿰뒐"
Because this library exists as a common interface over exception facilities, it may only be useful as a functional API to the underlying facilities in the host platform. The below is included just in case.
$ shadow-cljs release node
$ node
> var Hex = require('./target/node/nuid_hex');
> var h = Hex.encode("🐴");
> var b = Hex.decode(h);
> Array.from(b);
> Hex.toString(h);
> Hex.toString(h, "utf16le")
$ shadow-cljs release browser
## go use ./target/browser/nuid_hex.js in a browser script
To call nuid.hex from Java or other JVM languages, use one of the recommended interop strategies (var/IFn or uberjar/aot). Doing so may require modifications or additions to the API for convenience.
Coming soon.
The purpose of nuid.hex and sibling nuid libraries is to abstract over platform-specific differences and provide a common interface to fundamental dependencies. This allows us to express dependent logic once in pure Clojure(Script), and use it from each of the host platforms (Java, JavaScript, CLR). Along with tools.deps, this approach yields the code-sharing, circular-dependency avoidance, and local development benefits of a monorepo, with the modularity and orthogonality of an isolated library.
Apache v2.0 or MIT
Install git-hooks and fire away. Make sure not to get bitten by externs if modifying npm dependencies.
$ clojure -A:cljfmt # check
$ clojure -A:cljfmt:cljfmt/fix # fix
## check
$ npm outdated
$ clojure -A:depot
## update
$ npm upgrade -s
$ clojure -A:depot:depot/update