Socket
Book a DemoInstallSign in
Socket

@consento/codecs

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@consento/codecs

Serializable (named) codecs, including msgpack that work with typescript

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
4
Maintainers
3
Weekly downloads
 
Created
Source

@consento/codecs

Extended version of codecs that is suited for serialization, supports typescript and supports msgpack.

const codecs = require('@consento/codecs')
const json = codecs('json')
const buffer = json.encode({ hello: 'world'}) // JSON buffer
json.decode(buffer)

Fallback support

This is particularly interesting for TypeScript as proper type declarations can be tough!

Codecs supports an additional fallback property that is used if a given codec is not available.

import codecs, { Codec, CodecOption } from '@consento/codecs'

const fn = function <TCodec extends CodecOption = undefined> ({ codec }: { codec?: TCodec } = {}): Codec<TCodec, 'msgpack'> {
  return codecs(codec, 'msgpack') // The default fallback is 'binary', here we change it to 'msgpack'
}

fn().name === 'msgpack'
fn({ codec: 'json' }).name === 'json'

License

MIT

Keywords

codecs

FAQs

Package last updated on 20 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts