Socket
Socket
Sign inDemoInstall

etag

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

etag

Create simple HTTP ETags


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created

What is etag?

The etag npm package is used to generate HTTP ETags, which are typically used for cache validation. It can generate ETags based on the contents of a file or a buffer, a string, or based on a specified entity and its attributes.

What are etag's main functionalities?

Generating ETags from a file

This code sample demonstrates how to generate an ETag for the contents of a file. It reads the file 'example.txt' and uses the etag function to create an ETag based on the file's contents.

const etag = require('etag');
const fs = require('fs');

fs.readFile('example.txt', function(err, data) {
  if (err) throw err;
  const eTagValue = etag(data);
  console.log(eTagValue);
});

Generating ETags from a string

This code sample shows how to generate an ETag from a string. The etag function is called with a string 'Hello, World!' to produce an ETag for that specific string.

const etag = require('etag');

const entity = 'Hello, World!';
const eTagValue = etag(entity);
console.log(eTagValue);

Generating ETags with options

This example illustrates how to generate a weak ETag by passing an options object to the etag function. The options object specifies that the ETag should be weak, which is indicated by a 'W/' prefix in the ETag value.

const etag = require('etag');

const entity = Buffer.from('Hello, World!');
const options = { weak: true };
const eTagValue = etag(entity, options);
console.log(eTagValue);

Other packages similar to etag

Keywords

FAQs

Package last updated on 13 Sep 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