🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

ziptag

Package Overview
Dependencies
Maintainers
4
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.

Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
17
1600%
Maintainers
4
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.

The code is written in ES6. If you are not using the ES6 import, then you must use the default method that is exported.

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

Examples:

const ziptag = require('ziptag').default

// 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?

License

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

Licensed under the MIT license.

Keywords

etag

FAQs

Package last updated on 30 Nov 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