Socket
Socket
Sign inDemoInstall

ziptag

Package Overview
Dependencies
0
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ziptag

Fast etags for JSON.


Version published
Weekly downloads
9
decreased by-25%
Maintainers
2
Install size
15.7 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 10 Jun 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc