This package has been deprecated

Author message:

Archived. Use etag.

ziptag

0.0.8 • Public • Published

ziptag Build Status codecov Greenkeeper badge

Fast RFC-7232 compliant etags for JSON.

NPM

Installation

Available through npm: npm install --save ziptag.

Usage

This module exports a single function which takes any value as input and returns a valid ETag as a string.

For ES2015 import users: this module exports the named export ziptag. For commonjs users: you're free to do const ziptag = require('ziptag').

ziptag(object, [ignorePaths], [maxDepth]) => string

Examples:

const ziptag = require('ziptag')
 
// W/"e21zZzonaGVsbG8gd29ybGQn"
ziptag({ msg: 'hello world' })
 
// W/"e25hbWU6J0pvaG4nYWdlOjIwYmRheTow"
ziptag({ name: 'John', age: 20, bday: new Date(0) })
 
// W/"e3BlcnNvbjp7bmFtZTonSm9obidhZ2U6MjBiZGF5OjA="
ziptag({
  person: {
    name: 'John',
    age: 20,
    bday: new Date(0)
  }
})

Parameters

  • ignorePaths: a map of paths to ignore, value of the key to ignore should be false. Example: { "path.to.key": false }
  • maxDepth: the maximum depth to traverse in the entity. This is not protection against circular objects so setting this to Infinity will work (it'll just be really slow for large objects).

Considerations

It's dirty

This module is designed to create a very dirty etag as fast as possible. Due to this, higher priority is given to performance than collision avoidance. As with any hash function, there are collisions. Though there will be many more collisions than with a stronger solution like JSON.stringify (which still has collisions but significantly less). However, it will outperform the native JSON stringify.

It's really fast

To see up-to-date benchmark results, check out the travis log.

Larger objects = larger etags

Makes sense, right?

Using in-browser

When packing with webpack, make sure you disable the Buffer builtin to save some bundle space. Instead, ziptag will make use of the browser's btoa helper.

License

Copyright © 2017-present Foko Inc. All rights reserved.

Licensed under the MIT license.

Package Sidebar

Install

npm i ziptag

Weekly Downloads

0

Version

0.0.8

License

MIT

Unpacked Size

15.3 kB

Total Files

17

Last publish

Collaborators

  • fokodeploy
  • cmcdonald
  • vinnyfoko
  • zketchum-foko
  • fokopratik
  • mbaroni
  • arbourd
  • karimsa