How to use the transit-js.makeWriteHandler function in transit-js

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

54 / 100
Full package analysis