Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

ziptag

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ziptag

Fast etags for JSON.

latest
Source
npmnpm
Version
0.0.8
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
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

etag

FAQs

Package last updated on 10 Jun 2018

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