@tinyhttp/etag
Advanced tools
Comparing version
@@ -1,4 +0,3 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Stats } from 'node:fs'; | ||
export declare const eTag: (entity: string | Buffer | Stats, options?: { | ||
@@ -5,0 +4,0 @@ weak: boolean; |
@@ -6,17 +6,15 @@ import { createHash } from "node:crypto"; | ||
return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"'; | ||
} else { | ||
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 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) + '"'; | ||
return `"${mtime.getTime().toString(16)}-${size.toString(16)}"`; | ||
}; | ||
const eTag = (entity, options) => { | ||
if (entity == null) | ||
throw new TypeError("argument entity is required"); | ||
if (entity == null) throw new TypeError("argument entity is required"); | ||
const weak = (options == null ? void 0 : options.weak) || entity instanceof Stats; | ||
const tag = entity instanceof Stats ? statTag(entity) : entityTag(entity); | ||
return weak ? "W/" + tag : tag; | ||
return weak ? `W/${tag}` : tag; | ||
}; | ||
@@ -23,0 +21,0 @@ export { |
{ | ||
"name": "@tinyhttp/etag", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"type": "module", | ||
@@ -30,5 +30,3 @@ "description": "entity tag module", | ||
"license": "MIT", | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": {}, | ||
"scripts": { | ||
@@ -35,0 +33,0 @@ "dev": "vite", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8
14.29%6287
-0.66%30
-3.23%