Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bojand/grpc-create-metadata

Simple Node.js helper utility for creating gRPC metadata
https://github.com/bojand/grpc-create-metadata

grpc hacktoberfest

Last synced: 10 days ago
JSON representation

Simple Node.js helper utility for creating gRPC metadata

Awesome Lists containing this project

README

        

### grpc-create-metadata
Simple Node.js helper utility for creating gRPC metadata

**Example** *(Installation)*
```js
npm install grpc-create-metadata
```
**Example** *(Usage)*
```js
const grpc = require('grpc')
const create = require('grpc-create-metadata')
const meta = create({
name: 'Bob',
age: 20,
active: true
});
console.log(meta instanceof grpc.Metadata) // true
console.dir(meta.getMap()) // { foo: 'bar', age: '12', prop: 'true' }
```

#### module.exports(metadata, options) ⇒ Metadata
Utility helper function to create Metadata object from plain Javascript object
This strictly just calls Metadata.add with the key / value map of objects.
If the value is a Buffer it's passed as is.
If the value is a Sting it's passed as is.
Else if the value defined and not a string we simply call toString().
Note that Metadata only accept string or buffer values.

**Kind**: Exported function
**Returns**: Metadata - An instance of Metadata, or `undefined` if input is not an object

| Param | Type | Description |
| --- | --- | --- |
| metadata | Object | Plain javascript object to tranform into Metadata If an instance of Metadata is passed in it is simply returned |
| options | Object | options |
| options.addEmpty | Boolean | whether to add empty strings. Default: false |