Liking cljdoc? Tell your friends :D

transit-cljs

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from ClojureScript.

This implementation's major.minor version number corresponds to the version of the Transit specification it supports.

NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete.

Releases and Dependency Information

Leiningen

Add the following to your project.clj :dependencies:

[com.cognitect/transit-cljs "TBD"]

Maven

Maven dependency information:

<dependency>
  <groupId>com.cognitect</groupId>
  <artifactId>transit-cljs</artifactId>
  <version>TBD</version>
</dependency>

Usage

(ns example
  (:require [cognitect.transit :as t]))

(defn roundtrip [x]
  (let [w (t/writer :json)
        r (t/reader :json)]
    (t/read r (t/write w x))))

(defn test-roundtrip []
  (let [list1 [:red :green :blue]
        list2 [:apple :pear :grape]
        data  {(t/integer 1) list1
               (t/integer 2) list2}
        data' (roundtrip data)]
    (asssert (= data data'))))

Default Type Mapping

Abbreviations:

  • cc = cljs.core
  • gm = goog.math
  • cct = com.cognitect.transit
Transit typeWrite acceptsRead returns
nullnullnull
stringStringString
booleanBooleanBoolean
integerNumber, gm.LongNumber, gm.Long
decimalNumberNumber
keywordcc.Keywordcc.Keyword
symbolcc.Symbolcc.Symbol
big integercct.BigIntegercct.BigInteger
big decimalcct.BigDecimalcct.BigDecimal
timeDateDate
uricct.URIcct.URI
uuidcct.UUIDcct.UUID
charStringString
arraycc.IVectorcc.IVector
setcc.ISetcc.ISet
mapcc.IMapcc.IMap
linkcct.Linkcct.Link

Contributing

This library is open source, developed internally by Cognitect. We welcome discussions of potential problems and enhancement suggestions on the transit-format mailing list. Issues can be filed using GitHub issues for this project. Because transit is incorporated into products and client projects, we prefer to do development internally and are not accepting pull requests or patches.

Development

Dependencies

Install dependencies with

lein deps

Running the tests & benchmarks

Running the tests:

lein cljsbuild once test
open index.html

In order to run the bin/verify tests you must first build the roundtrip file:

lein cljsbuild once roundtrip

Running the benchmarks:

lein cljsbuild once bench
node target/transit.bench.js

Copyright and License

Copyright © 2014 Cognitect

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Can you improve this documentation? These fine people already did:
David Nolen, Alex Miller, Tim Ewald & puredanger
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close