API Docs for: 0.8.812

Class transit

Class defined in: src/com/cognitect/transit.js:39
transit.bigDec( s )
src/com/cognitect/transit.js:229

Create a transit big decimal.

Parameters:
  • s <String>

    A string representing an arbitrary precisions decimal value.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit big decimal.

transit.bigInt( s )
src/com/cognitect/transit.js:213

Create a transit big integer.

Parameters:
  • s <String>

    A string representing an arbitrary size integer value.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit big integer.

transit.binary( s )
src/com/cognitect/transit.js:281

Create transit binary blob.

Parameters:
  • s <String>

    A base64 encoded string.


Returns: <com.cognitect.transit.types.TaggedValue | Uint8Array>

A transit binary blob instance.

transit.date( A )
src/com/cognitect/transit.js:168

Create a transit date.

Parameters:
  • A <Number | String>

    number or string representing milliseconds since epoch.


Returns: <Date>

A JavaScript Date.

transit.decoder( options )
src/com/cognitect/transit.js:522

Construct a Transit JSON decoder.

Parameters:
  • options <Object>

    to the decoder. Can include map of handlers.


Returns: <com.cognitect.transit.impl.decoder.Decoder>

a Transit JSON decoder

Example
var decoder = transit.decoder();
var x = decoder.decode(json, transit.readCache());
transit.extendToEQ( x )
src/com/cognitect/transit.js:466

Extend an object to hashing and equality required by transit maps and sets. Only required for custom types, JavaScript primitive types and transit types are handled.

Parameters:
  • x <Object>

    A JavaScript object, will be mutated.


Returns: <Object>

x

Example
transit.extendToEq(Point.protototype, {
    hashCode: function() {
        var bits = (this.x | 0) ^ ((this.y | 0) * 31);
        return bits ^ (bits >>> 32);
    },
    equals: function(other) {
        return this.x == other.x && this.y == other.y;
    }
});
transit.hash( x )
src/com/cognitect/transit.js:420

Compute the hashCode for any JavaScript object that has been extend to transit's equality and hashing protocol. JavaScript primitives and transit value are already extended to this protocol. Custom types may be extended to the protocol via transit.extenToEQ.

Parameters:
  • x <Object>

    Any JavaScript object that has been extended to transit's equality and hashing protocol.


Returns: <Number>

Returns JavaScript number - semantically a 32bit integer.

transit.hashArrayLike( x )
src/com/cognitect/transit.js:442

Compute the hashCode for JavaScript array-like types - either a JavaScript array or a JavaScript object that implements Array forEach.

Parameters:
  • x <Object>

    A JavaScript Array or Object that implements Array forEach.


Returns: <Number>

Returns JavaScript number - semantically a 32bit integer.

transit.hashMapLike( x )
src/com/cognitect/transit.js:432

Compute the hashCode for JavaScript map-like types - either a JavaScript object or a JavaScript object that implements ES6 Map forEach.

Parameters:
  • x <Object>

    A plain JavaScript Object or Object that implements ES6 Map forEach.


Returns: <Number>

Returns JavaScript number - semantically a 32bit integer.

transit.integer( s )
src/com/cognitect/transit.js:176

Create an integer. If given a transit integer or a JavaScript number will simply return that value. Given a string will return a JavaScript number if the string represents an integer value in the 53bit range and a transit integer otherwise.

Parameters:
  • s <Number | String>

    A value representing an integer.


Returns: <Number | goog.math.Long>

A JavaScript number or transit integer.

transit.isBigDec( x )
src/com/cognitect/transit.js:237

Test if an object is a transit big decimal.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit big decimal, false otherwise.

transit.isBigInt( x )
src/com/cognitect/transit.js:221

Test if an object is a transit big integer.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit big integer, false otherwise.

transit.isBinary( x )
src/com/cognitect/transit.js:289

Test if an object is a transit binary blob.

Parameters:
  • x <Object>

    Any JavaScript value.

transit.isInteger( x )
src/com/cognitect/transit.js:187

Test if an object is a transit integer. Will return true if argument is a 64 bit integer or a JavaScript number that has an interpretation as an integer value, i.e. parseFloat(n) === parseInt(n)

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if the value is a transit integer, false otherwise.

transit.isKeyword( x )
src/com/cognitect/transit.js:255

Test if an object is a transit keyword.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit keyword, false otherwise.

transit.isLink( x )
src/com/cognitect/transit.js:412

Test if an object is a transit link.

Parameters:
  • x <Object>

    Any JavaScript object.


Returns: <Boolean>

true if x is a transit link, false otherwise.

transit.isList( x )
src/com/cognitect/transit.js:358

Test if an object is a transit list.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit list, false otherwise.

transit.isMap( x )
src/com/cognitect/transit.js:323

Test if an object is a transit map.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit map, false otherwise.

transit.isQuoted( x )
src/com/cognitect/transit.js:374

Test if an object is a transit quoted value.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit value, false otherwise.

transit.isSet( x )
src/com/cognitect/transit.js:342

Test if an object is a transit set.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit set, false otherwise.

transit.isSymbol( x )
src/com/cognitect/transit.js:273

Test if an object is a transit symbol

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit symbol, false otherwise.

transit.isTaggedValue( x )
src/com/cognitect/transit.js:393

Test if an object is a transit tagged value.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if x is a transit value, false otherwise.

transit.isURI( Any )
src/com/cognitect/transit.js:304

Test if an object is a transit URI.

Parameters:
  • Any <Object>

    JavaScript value.


Returns: <Boolean>

true if x is a transit symbol, false otherwise.

transit.isUUID( x )
src/com/cognitect/transit.js:205

Test if an object is a transit UUID.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <Boolean>

true if the vlaue is a transit UUID instance, false otherwise.

transit.keyword( name )
src/com/cognitect/transit.js:245

Create transit keyword.

Parameters:
  • name <String>

    A string.


Returns: <com.cognitect.transit.types.Keyword>

A transit keyword.

Example
transit.keyword("foo");
transit.link( A )
src/com/cognitect/transit.js:401

Create a transit link.

Parameters:
  • A <com.cognitect.transit.types.TransitArrayMap | com.cognitect.transit.types.TransitMap>

    transit map which must contain at a minimum the following keys: href, rel. It may optionally include name, render, and prompt. href must be a transit.uri, all other values are strings, and render must be either "image" or "link".


Returns: <Object>

A transit link.

transit.list( A )
src/com/cognitect/transit.js:350

Create a transit list.

Parameters:
  • A <Array>

    JavaScript array.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit list.

transit.makeWriteHandler( obj )
src/com/cognitect/transit.js:134

Create a transit writer handler.

Parameters:
  • obj <Object>

    An object containing 3 functions, tag, rep and stringRep. "tag" should return a string representing the tag to be written on the wire. "rep" should return the representation on the wire. "stringRep" is should return the string representation of the value. Optional "getVerboseHandler" should return a handler for writing verbose output.


Returns: <Object>

A transit write handler.

Example
var PointHandler = transit.makeWriteHandler({
     tag: function(p) { return "point"; },
     rep: function(p) { return [p.x, p.y]; },
     stringRep: function(p) { return null; }
});
transit.map( xs )
src/com/cognitect/transit.js:312

Create a transit hash map. Transit maps satisfy the current version of the ECMAScript 6 Map specification.

Parameters:
  • xs <Array>

    A JavaScript array of alternating key value pairs.


Returns: <com.cognitect.transit.types.TransitArrayMap | com.cognitect.transit.types.TransitMap>

A transit map.

Example
transit.map([new Date(), "foo", [1,2], 3]);
transit.mapToObject( m )
src/com/cognitect/transit.js:487

Convert a transit map instance into a JavaScript Object. Throws if the map has keys which have no string representation.

Parameters:
  • m <com.cognitect.transit.types.TransitArrayMap | com.cognitect.transit.types.TransitMap>

    a transit map


Returns: <Object>

a JavaScript Object

transit.objectToMap( a )
src/com/cognitect/transit.js:506

Convert a POJO into a transit map.

Parameters:
  • a <Object>

    JavaScript Object


Returns: <com.cognitect.transit.types.TransitArrayMap | com.cognitect.transit.types.TransitMap>

a transit map

transit.quoted( x )
src/com/cognitect/transit.js:366

Create a transit quoted value.

Parameters:
  • x <Object>

    Any JavaScript value.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit quoted value.

transit.readCache( )
src/com/cognitect/transit.js:534

Construct a Transit read cache


Returns: <com.cognitect.transit.caching.ReadCache>

a Transit read cache

transit.reader( type, opts )
src/com/cognitect/transit.js:61

Create a transit reader instance.

Parameters:
  • type <String=>

    type of reader to construct. Default to "json". For verbose mode supply "json-verbose".

  • opts <Object=>

    reader options. A JavaScript object to customize the writer Valid entries include "defaultHandler", and "handler". "defaultHandler" should be JavaScript function taking two arguments, the first is the tag, the second the value. "handlers" should be an object of tags to handle. The values are functions that will receive the value of matched tag. "preferBuffers" may be supplied to customize binary decoding. If available binary data will read as Node.js Buffers, If Buffer is not available or "prefersBuffers" is set to false data will be read as Uint8Array. If neither Buffer nor Uint8Array is available - defaults to tagged value that simply wraps the base64 encoded string.


Returns: <com.cognitect.transit.impl.reader.Reader>

A transit reader.

Example
var r = transit.reader("json", {
    handlers: {
       "point": function(v) { return new Point(v[0], v[1]); }
    }
});
transit.set( xs )
src/com/cognitect/transit.js:331

Create a transit set. Transit sets satisfy the current version of the of the ECMAScript 6 Set specification.

Parameters:
  • xs <Array>

    A JavaScript array of values.


Returns: <com.cognitect.transit.types.TransitSet>

A transit set.

Example
transit.set(["foo", [1,2], 3, {bar: "baz"}]);
transit.symbol( name )
src/com/cognitect/transit.js:263

Create a transit symbol.

Parameters:
  • name <String>

    A string.


Returns: <com.cognitect.transit.types.Symbol>

A transit symbol instance.

Example
transit.symbol("foo");
transit.tagged( tag, value )
src/com/cognitect/transit.js:382

Create a transit tagged value.

Parameters:
  • tag <String>

    A tag.

  • value <Object>

    A JavaScrpt array, object, or string.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit tagged value.

Example
transit.tagged("point", new Point(1,2));
transit.uri( A )
src/com/cognitect/transit.js:296

Create a transit URI.

Parameters:
  • A <String>

    string representing a valid URI.


Returns: <com.cognitect.transit.types.TaggedValue>

A transit URI.

transit.uuid( UNKNOWN )
src/com/cognitect/transit.js:197

Create transit UUID from a string

Parameters:
  • UNKNOWN <String>

Returns: <com.cognitect.transit.types.UUID>

A transit UUID.

transit.writeCache( )
src/com/cognitect/transit.js:541

Construct a Transit write cache


Returns: <com.cognitect.transit.caching.WriteCache>

a Transit write cache

transit.writer( type, opts )
src/com/cognitect/transit.js:96

Create a transit writer instance.

Parameters:
  • type <String=>

    type of writer to construct. Defaults to "json". For verbose mode supply "json-verbose".

  • opts <Object=>

    writer options. A JavaScript object to customize the writer. "handlers" options, a transit.map of JavaScript constructor and transit writer handler instance entries. "handlerForForeign" option, for dealing with values from other JavaScript contexts. This function will be passed the unmatchable value and the installed handlers. The function should return the correct handler. Note if this function is provided, special handling for Objects will also be auto-installed to catch plain Objects from the foreign context.


Returns: <com.cognitect.transit.impl.writer.Writer>

A transit writer.

Example
var r = transit.writer("json", {
    handlers: transit.map([
       Point, PointHandler
    ])
});