How to use transit-js - 10 common examples

To help you get started, we’ve selected a few transit-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github banterfm / graphql-crunch / bench / bench.js View on Github external
const {join} = require('path');
const {readFileSync} = require('fs');
const {gzipSync} = require('zlib');
const {crunch, uncrunch} = require('../src');
const transit = require('transit-js');
const msgpack = require("msgpack-lite");

const tWriter = transit.writer('json');
const tReader = transit.reader('json');

const blobs = {
  // From https://gist.githubusercontent.com/stevekrenzel/8553b5cc5462164bc9ac5b2897978405/raw/f07292666eb621a2d29dc8cee0c78a4ddb3bbadd/swapi.json
  "Large SWAPI": join(__dirname, './json/large.json'),

  // From https://gist.githubusercontent.com/stevekrenzel/88c16d8655d25bed7c1b61f1750eb362/raw/4c4b7806ba51afa479224011f8138ef1346f08f6/swapi.json
  "Small SWAPI": join(__dirname, './json/small.json'),

  // From https://catalog.data.gov/dataset/2010-census-populations-by-zip-code/resource/74f7a51d-36ae-4a28-9345-d8e07321f2e4
  "Census": join(__dirname, './json/census.json'),

  // From https://data.oregon.gov/api/views/i8h7-mn6v/rows.json
  "Businesses": join(__dirname, './json/businesses.json'),

  //"Banter Feed": join(__dirname, './json/feed.json'),
};
github banterfm / graphql-crunch / bench / bench.js View on Github external
const {join} = require('path');
const {readFileSync} = require('fs');
const {gzipSync} = require('zlib');
const {crunch, uncrunch} = require('../src');
const transit = require('transit-js');
const msgpack = require("msgpack-lite");

const tWriter = transit.writer('json');
const tReader = transit.reader('json');

const blobs = {
  // From https://gist.githubusercontent.com/stevekrenzel/8553b5cc5462164bc9ac5b2897978405/raw/f07292666eb621a2d29dc8cee0c78a4ddb3bbadd/swapi.json
  "Large SWAPI": join(__dirname, './json/large.json'),

  // From https://gist.githubusercontent.com/stevekrenzel/88c16d8655d25bed7c1b61f1750eb362/raw/4c4b7806ba51afa479224011f8138ef1346f08f6/swapi.json
  "Small SWAPI": join(__dirname, './json/small.json'),

  // From https://catalog.data.gov/dataset/2010-census-populations-by-zip-code/resource/74f7a51d-36ae-4a28-9345-d8e07321f2e4
  "Census": join(__dirname, './json/census.json'),

  // From https://data.oregon.gov/api/views/i8h7-mn6v/rows.json
  "Businesses": join(__dirname, './json/businesses.json'),

  //"Banter Feed": join(__dirname, './json/feed.json'),
github honzabrecka / composable-fetch / examples / composable.js View on Github external
const composableFetch = require('../dist/index')
const { pipeP, tryCatchP } = require('../dist/index')
const transit = require('transit-js')

const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const fetch = pipeP(
  composableFetch.retryableFetch,
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
  composableFetch.withClone,
  composableFetch.checkStatus,
)

const data = ({ data }) => data

const JSONReq = pipeP(
  composableFetch.withBaseUrl('https://example.com/api'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
  composableFetch.withJSONEncodedBody,
github honzabrecka / composable-fetch / examples / transit.js View on Github external
const { composableFetch, pipeP } = require('../dist/index')
const fetch = require('isomorphic-fetch')
const transit = require('transit-js')
const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const decodeTransit = (res) => {
  res.data = reader.read(res.data)
  return res
}

const fetchTransit = pipeP(
  composableFetch.withBaseUrl('https://echo-http-server.herokuapp.com'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
  composableFetch.withEncodedBody((v) => writer.write(v)),
  composableFetch.retryable(composableFetch.fetch1(fetch)),
  composableFetch.withTimeout(1000),
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
  composableFetch.decodeTextResponse,
github honzabrecka / composable-fetch / examples / transit.js View on Github external
const { composableFetch, pipeP } = require('../dist/index')
const fetch = require('isomorphic-fetch')
const transit = require('transit-js')
const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const decodeTransit = (res) => {
  res.data = reader.read(res.data)
  return res
}

const fetchTransit = pipeP(
  composableFetch.withBaseUrl('https://echo-http-server.herokuapp.com'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
  composableFetch.withEncodedBody((v) => writer.write(v)),
  composableFetch.retryable(composableFetch.fetch1(fetch)),
  composableFetch.withTimeout(1000),
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
github honzabrecka / composable-fetch / examples / composable.js View on Github external
const composableFetch = require('../dist/index')
const { pipeP, tryCatchP } = require('../dist/index')
const transit = require('transit-js')

const log = console.log.bind(console)
const writer = transit.writer('json')
const reader = transit.reader('json')

const fetch = pipeP(
  composableFetch.retryableFetch,
  composableFetch.withRetry(),
  composableFetch.withSafe204(),
  composableFetch.withClone,
  composableFetch.checkStatus,
)

const data = ({ data }) => data

const JSONReq = pipeP(
  composableFetch.withBaseUrl('https://example.com/api'),
  composableFetch.withHeader('Content-Type', 'application/json'),
  composableFetch.withHeader('Accept', 'application/json'),
github sweet-js / sweet-core / src / serializer.js View on Github external
TokenType.DEFAULT, TokenType.DO, TokenType.ELSE, TokenType.EXPORT,
               TokenType.EXTENDS, TokenType.FINALLY, TokenType.FOR, TokenType.FUNCTION,
               TokenType.IF, TokenType.IMPORT, TokenType.LET, TokenType.NEW,
               TokenType.RETURN, TokenType.SUPER, TokenType.SWITCH, TokenType.THIS,
               TokenType.THROW, TokenType.TRY, TokenType.VAR, TokenType.WHILE,
               TokenType.WITH, TokenType.NULL, TokenType.TRUE, TokenType.FALSE,
               TokenType.YIELD, TokenType.NUMBER, TokenType.STRING, TokenType.REGEXP,
               TokenType.IDENTIFIER, TokenType.CONST, TokenType.TEMPLATE,
               TokenType.ILLEGAL];

let ListHandler = transit.makeWriteHandler({
  tag: () => "array",
  rep: (v) => v
});

let MapHandler = transit.makeWriteHandler({
  tag: function() { return "map"; },
  rep: function(v) { return v; },
  stringRep: function() { return null; }
});

let SyntaxHandler = transit.makeWriteHandler({
  tag: () => "stx",
  rep: (v) => {
    if (List.isList(v.token)) {
      return [v.token, v.scopesets];
    } else {
      let t = transit.objectToMap(v.token);
      t.set("type", typeMap.indexOf(v.token.type));
      return [t, v.scopesets];
    }
  }
github sweet-js / sweet-core / src / serializer.js View on Github external
TokenType.YIELD, TokenType.NUMBER, TokenType.STRING, TokenType.REGEXP,
               TokenType.IDENTIFIER, TokenType.CONST, TokenType.TEMPLATE,
               TokenType.ILLEGAL];

let ListHandler = transit.makeWriteHandler({
  tag: () => "array",
  rep: (v) => v
});

let MapHandler = transit.makeWriteHandler({
  tag: function() { return "map"; },
  rep: function(v) { return v; },
  stringRep: function() { return null; }
});

let SyntaxHandler = transit.makeWriteHandler({
  tag: () => "stx",
  rep: (v) => {
    if (List.isList(v.token)) {
      return [v.token, v.scopesets];
    } else {
      let t = transit.objectToMap(v.token);
      t.set("type", typeMap.indexOf(v.token.type));
      return [t, v.scopesets];
    }
  }
});
let SymbolHandler = transit.makeWriteHandler({
  tag: () => "symb",
  rep: (v) =>  [v.name]
});
github sweet-js / sweet-core / src / serializer.js View on Github external
stringRep: function() { return null; }
});

let SyntaxHandler = transit.makeWriteHandler({
  tag: () => "stx",
  rep: (v) => {
    if (List.isList(v.token)) {
      return [v.token, v.scopesets];
    } else {
      let t = transit.objectToMap(v.token);
      t.set("type", typeMap.indexOf(v.token.type));
      return [t, v.scopesets];
    }
  }
});
let SymbolHandler = transit.makeWriteHandler({
  tag: () => "symb",
  rep: (v) =>  [v.name]
});

let writer = transit.writer("json", {
  handlers: transit.map([
    List, ListHandler,
    Map, MapHandler,
    Syntax, SyntaxHandler,
    SymbolClass, SymbolHandler
  ])
});

function makeReader(bindings) {
  return transit.reader("json", {
    arrayBuilder: {
github sweet-js / sweet-core / src / serializer.js View on Github external
TokenType.EQ_STRICT, TokenType.NE_STRICT, TokenType.LT, TokenType.GT,
               TokenType.LTE, TokenType.GTE, TokenType.INSTANCEOF, TokenType.IN,
               TokenType.NOT, TokenType.BIT_NOT, TokenType.AWAIT, TokenType.DELETE,
               TokenType.TYPEOF, TokenType.VOID, TokenType.BREAK, TokenType.CASE,
               TokenType.CATCH, TokenType.CLASS, TokenType.CONTINUE, TokenType.DEBUGGER,
               TokenType.DEFAULT, TokenType.DO, TokenType.ELSE, TokenType.EXPORT,
               TokenType.EXTENDS, TokenType.FINALLY, TokenType.FOR, TokenType.FUNCTION,
               TokenType.IF, TokenType.IMPORT, TokenType.LET, TokenType.NEW,
               TokenType.RETURN, TokenType.SUPER, TokenType.SWITCH, TokenType.THIS,
               TokenType.THROW, TokenType.TRY, TokenType.VAR, TokenType.WHILE,
               TokenType.WITH, TokenType.NULL, TokenType.TRUE, TokenType.FALSE,
               TokenType.YIELD, TokenType.NUMBER, TokenType.STRING, TokenType.REGEXP,
               TokenType.IDENTIFIER, TokenType.CONST, TokenType.TEMPLATE,
               TokenType.ILLEGAL];

let ListHandler = transit.makeWriteHandler({
  tag: () => "array",
  rep: (v) => v
});

let MapHandler = transit.makeWriteHandler({
  tag: function() { return "map"; },
  rep: function(v) { return v; },
  stringRep: function() { return null; }
});

let SyntaxHandler = transit.makeWriteHandler({
  tag: () => "stx",
  rep: (v) => {
    if (List.isList(v.token)) {
      return [v.token, v.scopesets];
    } else {

transit-js

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 Javascript.

Apache-2.0
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis