JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15352
  • Score
    100M100P100Q132339F
  • License ISC

Utilities for working with common protobuf types

Package Exports

  • pb-util
  • pb-util/build
  • pb-util/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pb-util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pb-util

Utilities for working with common protobuf types.

Installing

$ npm i --save pb-util

API

value.encode(val)

Encodes a JSON value into a google.protobuf.Value.

val

Type: string number boolean null object array

const {value} = require('pb-util');

const stringValue = value.encode('hello!');
// => {
//   kind: 'stringValue',
//   stringValue: 'hello!'
// }

value.decode(protoValue)

Decodes a google.protobuf.Value into a JSON value.

protoValue

Type: google.protobuf.Value

const {value} = require('pb-util');

const str = value.decode({
  kind: 'stringValue',
  stringValue: 'beep boop'
});
// => 'beep boop'

struct.encode(json)

Encodes a JSON object into a google.protobuf.Struct.

json

Type: object

const {struct} = require('pb-util');

const structValue = struct.encode({foo: 'bar'});
// => {
//   fields: {
//     foo: {
//       kind: 'stringValue',
//       stringValue: 'bar'
//     }
//   }
// }

struct.decode(structValue)

Decodes a google.protobuf.Struct into a JSON object.

structValue

Type: google.protobuf.ListValue

const {struct} = require('pb-util');

const obj = struct.decode({
  fields: {
    foo: {
      kind: 'stringValue',
      stringValue: 'bar'
    },
    yes: {
      kind: 'boolValue',
      boolValue: true
    }
  }
});
// => {
//   foo: 'bar',
//   yes: true
// }

list.encode(array)

Encodes an array of JSON values into a google.protobuf.ListValue.

array

Type: array

const {list} = require('pb-util');

const listValue = list.encode(['foo', 'bar']);
// => {
//   values: [
//     {
//       kind: 'stringValue',
//       stringValue: 'foo'
//     },
//     {
//       kind: 'stringValue',
//       stringValue: 'bar'
//     }
//   ]
// }

list.decode(listValue)

Decodes a google.protobuf.ListValue into an array of JSON values.

listValue

Type: google.protobuf.ListValue

const {list} = require('pb-util');

const arr = list.decode({
  values: [
    {
      kind: 'stringValue',
      stringValue: 'foo'
    },
    {
      kind: 'numberValue',
      numberValue: 10
    }
  ]
});
// => ['foo', 10]

License

ISC