New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@endeo/specials

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endeo/specials

Build "object spec" for compact object encoding.

  • 0.2.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@endeo/specials

Build Status Dependency Status npm version Coverage Status

Build "object spec" for compact object encoding.

A flexible specification allowing progressive improvements for greater performance.

Features:

  1. knows a list of property names for an object to allow encoding without them which avoids all those bytes.
  2. optionally knows defaults to avoid encoding those values.
  3. optionally knows type to avoid the value's type check every time for faster encoding and decoding.
  4. optionally uses special keys to trigger automatic encoding/decoding changes for compression (or any reason). You may define your own special keys and how they are used.

See packages:

  1. endeo
  2. enbyte
  3. debyte
  4. unstring

Install

npm install --save @endeo/specials

Usage

// get the Specials builder
var build = require('@endeo/specials')

// the types we'd like to refer to by name.
// i'm using some default ones.
var types = require('@endeo/types')

// build it
var specials = build({ types: types })

// add more types:
specials.addType('someId', {
  // optionally provide one or both
  encode: function(enbyte, value, output) {},
  decode: function(debyte, input) {}
})

// add a type which is always one of a set of values
specials.addType('fruit', {
  // basically encodes the index of the value
  select: [ 'apple', 'banana', 'orange' ]
})

// a "creator" function makes an object
// representing the object with all its keys
// and default values.
function createThing() {
  return {
    key1: 'someDefault',
    key2: 2,
    fruit: 'banana'
  }
}

// the "enhancers" are extra info you can supply
var enhancers = {
  key1: 'name of a type',
  key2: {
    // optionally ref a known type still
    type: 'name of a type',

    // optionally provide encode() / decode()
    encode: function(enbyte, value, output) {},
    decode: function(debyte, input) {}
  },
  fruit: 'fruit' // use type 'fruit' above
}

// create an "object spec" (Special)
var spec = specials.build(1, createThing, enhancers)

// set the spec's ID on your objects.

// on a class:
function SomeClass() {}
spec.imprint(SomeClass.prototype)

// on an object:
var someObject = {}
spec.imprint(someObject)

MIT License

FAQs

Package last updated on 21 May 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc