nuid.bytes
Cross-platform byte (de)serialization and conversion.
Requirements
jvm
, node + npm
, clj
, shadow-cljs
From Clojure and ClojureScript
tools.deps:
{nuid/bytes {:git/url "https://github.com/nuid/bytes" :sha "..."}}
usage:
$ clj # or shadow-cljs node-repl
=> (require '[nuid.bytes :as bytes])
=> (def b (bytes/from "π΄")) ;; defaults to utf8
=> (bytes/str b) ;; => "π΄"
=> (bytes/str b :utf16le) ;; => "ιΏ°λ"
=> (def b2 (bytes/from "π΄" :utf16le))
=> (bytes/str b2 :utf16le) ;; => "π΄"
Notes
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.
From JavaScript
In JavaScript, this library relies upon and mimics a subset of the Buffer
API in both node and the browser
node:
$ shadow-cljs release node
$ node
> var B = require('./target/node/nuid_bytes');
> var b = B.from("π΄");
> B.toString(b);
> B.toString(b, "utf16le");
browser:
$ shadow-cljs release browser
## go use ./target/browser/nuid_bytes.js in a browser script
From Java
In Java, this library relies on the String
and Charset
classes. To call nuid.bytes
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.
From CLR
Coming soon.
Notes
The purpose of nuid.bytes
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.
Licensing
Apache v2.0 or MIT
Contributing
Install git-hooks
and fire away. Make sure not to get bitten by externs
if modifying npm
dependencies.
formatting:
$ clojure -A:cljfmt # check
$ clojure -A:cljfmt:cljfmt/fix # fix
dependencies:
## check
$ npm outdated
$ clojure -A:depot
## update
$ npm upgrade -s
$ clojure -A:depot:depot/update