@tinyhttp/etag
Advanced tools
Comparing version 0.2.1 to 0.2.2
# @tinyhttp/etag | ||
## 0.2.2 | ||
### Patch Changes | ||
- Return compression back | ||
## 0.2.1 | ||
@@ -4,0 +10,0 @@ |
@@ -1,33 +0,1 @@ | ||
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; | ||
import{createHash as r}from"crypto";import{Stats as t}from"fs";export default(e,n)=>{if(null==e)throw new TypeError("argument entity is required");const o=(null==n?void 0:n.t)||e instanceof t,f=e instanceof t?(({o:r,size:t})=>'"'+r.getTime().toString(16)+"-"+t.toString(16)+'"')(e):(t=>{if(0===t.length)return'"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"';else{const e=r("sha1").update(t,"utf8").digest("base64").substring(0,27);return'"'+("string"==typeof t?Buffer.byteLength(t,"utf8"):t.length).toString(16)+"-"+e+'"'}})(e);return o?"W/"+f:f}; |
{ | ||
"name": "@tinyhttp/etag", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "entity tag module", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5799
9
45
2