Socket
Socket
Sign inDemoInstall

@tinyhttp/etag

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/etag - npm Package Compare versions

Comparing version 0.1.26 to 0.2.0

CHANGELOG.md

2

dist/index.d.ts

@@ -6,2 +6,2 @@ /// <reference types="node" />

}) => string;
export { etag as default };
export default etag;

@@ -1,1 +0,33 @@

import{createHash as t}from"crypto";import{Stats as e}from"fs";export default(r,n)=>{if(null==r)throw new TypeError("argument entity is required");const i=(null==n?void 0:n.weak)||r instanceof e,o=r instanceof e?(({mtime:t,size:e})=>'"'+t.getTime().toString(16)+"-"+e.toString(16)+'"')(r):(e=>{if(0===e.length)return'"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"';{const r=t("sha1").update(e,"utf8").digest("base64").substring(0,27);return'"'+("string"==typeof e?Buffer.byteLength(e,"utf8"):e.length).toString(16)+"-"+r+'"'}})(r);return i?"W/"+o:o};
import { createHash } from 'crypto';
import { Stats } from 'fs';
// Original module: https://github.com/jshttp/etag/blob/master/index.js
const entityTag = (entity) => {
if (entity.length === 0) {
// fast-path empty
return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"';
}
else {
// generate hash
const hash = createHash('sha1')
.update(entity, 'utf8')
.digest('base64')
.substring(0, 27);
const len = typeof entity === 'string' ? Buffer.byteLength(entity, 'utf8') : entity.length;
return '"' + len.toString(16) + '-' + hash + '"';
}
};
const statTag = ({ mtime, size }) => {
return '"' + mtime.getTime().toString(16) + '-' + size.toString(16) + '"';
};
const etag = (entity, options) => {
if (entity == null) {
throw new TypeError('argument entity is required');
}
const weak = (options === null || options === void 0 ? void 0 : options.weak) || entity instanceof Stats;
// generate entity tag
const tag = entity instanceof Stats ? statTag(entity) : entityTag(entity);
return weak ? 'W/' + tag : tag;
};
export default etag;
{
"name": "@tinyhttp/etag",
"version": "0.1.26",
"version": "0.2.0",
"type": "module",

@@ -35,3 +35,11 @@ "description": "entity tag module",

"author": "v1rtl",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"rollup": "^2.21.0",
"rollup-plugin-typescript2": "^0.27.1",
"typescript": "^3.9.6"
},
"scripts": {
"build": "rollup -c"
}
}

Sorry, the diff of this file is not supported yet

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