mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 04:10:04 +02:00
update packages to latest version
This commit is contained in:
2
node_modules/data-urls/LICENSE.txt
generated
vendored
2
node_modules/data-urls/LICENSE.txt
generated
vendored
@@ -1,4 +1,4 @@
|
||||
Copyright © 2017–2020 Domenic Denicola <d@domenic.me>
|
||||
Copyright © Domenic Denicola <d@domenic.me>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
26
node_modules/data-urls/README.md
generated
vendored
26
node_modules/data-urls/README.md
generated
vendored
@@ -7,18 +7,18 @@ const parseDataURL = require("data-urls");
|
||||
|
||||
const textExample = parseDataURL("data:,Hello%2C%20World!");
|
||||
console.log(textExample.mimeType.toString()); // "text/plain;charset=US-ASCII"
|
||||
console.log(textExample.body.toString()); // "Hello, World!"
|
||||
console.log(textExample.body); // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ]
|
||||
|
||||
const htmlExample = dataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E");
|
||||
const htmlExample = parseDataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E");
|
||||
console.log(htmlExample.mimeType.toString()); // "text/html"
|
||||
console.log(htmlExample.body.toString()); // <h1>Hello, World!</h1>
|
||||
console.log(htmlExample.body); // Uint8Array(22) [ 60, 104, 49, 62, 72, 101, … ]
|
||||
|
||||
const pngExample = parseDataURL("data:image/png;base64,iVBORw0KGgoAAA" +
|
||||
"ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
|
||||
"//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
|
||||
"5ErkJggg==");
|
||||
console.log(pngExample.mimeType.toString()); // "image/png"
|
||||
console.log(pngExample.body); // <Buffer 89 50 4e 47 0d ... >
|
||||
console.log(pngExample.body); // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ]
|
||||
```
|
||||
|
||||
## API
|
||||
@@ -26,28 +26,26 @@ console.log(pngExample.body); // <Buffer 89 50 4e 47 0d ... >
|
||||
This package's main module's default export is a function that accepts a string and returns a `{ mimeType, body }` object, or `null` if the result cannot be parsed as a `data:` URL.
|
||||
|
||||
- The `mimeType` property is an instance of [whatwg-mimetype](https://www.npmjs.com/package/whatwg-mimetype)'s `MIMEType` class.
|
||||
- The `body` property is a Node.js [`Buffer`](https://nodejs.org/docs/latest/api/buffer.html) instance.
|
||||
- The `body` property is a `Uint8Array` instance.
|
||||
|
||||
As shown in the examples above, both of these have useful `toString()` methods for manipulating them as string values. However…
|
||||
As shown in the examples above, you can easily get a stringified version of the MIME type using its `toString()` method. Read on for more on getting the stringified version of the body.
|
||||
|
||||
### A word of caution on string decoding
|
||||
### Decoding the body
|
||||
|
||||
Because Node.js's `Buffer.prototype.toString()` assumes a UTF-8 encoding, simply doing `dataURL.body.toString()` may not work correctly if the `data:` URL's contents were not originally written in UTF-8. This includes if the encoding is "US-ASCII", [aka windows-1252](https://encoding.spec.whatwg.org/#names-and-labels), which is notable for being the default in many cases.
|
||||
|
||||
A more complete decoding example would use the [whatwg-encoding](https://www.npmjs.com/package/whatwg-encoding) package as follows:
|
||||
To decode the body bytes of a parsed data URL, you'll need to use the `charset` parameter of the MIME type, if any. This contains an encoding [label](https://encoding.spec.whatwg.org/#label); there are [various possible labels](https://encoding.spec.whatwg.org/#names-and-labels) for a given encoding. We suggest using the [whatwg-encoding](https://www.npmjs.com/package/whatwg-encoding) package as follows:
|
||||
|
||||
```js
|
||||
const parseDataURL = require("data-urls");
|
||||
const { labelToName, decode } = require("whatwg-encoding");
|
||||
|
||||
const dataURL = parseDataURL(arbitraryString);
|
||||
const encodingName = labelToName(dataURL.mimeType.parameters.get("charset"));
|
||||
|
||||
// If there's no charset parameter, let's just hope it's UTF-8; that seems like a good guess.
|
||||
const encodingName = labelToName(dataURL.mimeType.parameters.get("charset") || "utf-8");
|
||||
const bodyDecoded = decode(dataURL.body, encodingName);
|
||||
```
|
||||
|
||||
For example, given an `arbitraryString` of `data:,Hello!`, this will produce a `bodyDecoded` of `"Hello!"`, as expected. But given an `arbitraryString` of `"data:,Héllo!"`, this will correctly produce a `bodyDecoded` of `"Héllo!"`, whereas just doing `dataURL.body.toString()` will give back `"Héllo!"`.
|
||||
|
||||
In summary, only use `dataURL.body.toString()` when you are very certain your data is inside the ASCII range (i.e. code points within the range U+0000 to U+007F).
|
||||
This is especially important since the default, if no parseable MIME type is given, is "US-ASCII", [aka windows-1252](https://encoding.spec.whatwg.org/#names-and-labels), not UTF-8 like you might asume. So for example given an `arbitraryString` of `"data:,Héllo!"`, the above code snippet will correctly produce a `bodyDecoded` of `"Héllo!"` by using the windows-1252 decoder, whereas if you used a UTF-8 decoder you'd get back `"Héllo!"`.
|
||||
|
||||
### Advanced functionality: parsing from a URL record
|
||||
|
||||
|
15
node_modules/data-urls/lib/parser.js
generated
vendored
15
node_modules/data-urls/lib/parser.js
generated
vendored
@@ -1,12 +1,7 @@
|
||||
"use strict";
|
||||
const MIMEType = require("whatwg-mimetype");
|
||||
const { parseURL, serializeURL } = require("whatwg-url");
|
||||
const {
|
||||
stripLeadingAndTrailingASCIIWhitespace,
|
||||
stringPercentDecode,
|
||||
isomorphicDecode,
|
||||
forgivingBase64Decode
|
||||
} = require("./utils.js");
|
||||
const { parseURL, serializeURL, percentDecodeString } = require("whatwg-url");
|
||||
const { stripLeadingAndTrailingASCIIWhitespace, isomorphicDecode, forgivingBase64Decode } = require("./utils.js");
|
||||
|
||||
module.exports = stringInput => {
|
||||
const urlRecord = parseURL(stringInput);
|
||||
@@ -42,10 +37,10 @@ module.exports.fromURLRecord = urlRecord => {
|
||||
|
||||
const encodedBody = input.substring(position);
|
||||
|
||||
let body = stringPercentDecode(encodedBody);
|
||||
let body = percentDecodeString(encodedBody);
|
||||
|
||||
// Can't use /i regexp flag because it isn't restricted to ASCII.
|
||||
const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/.exec(mimeType);
|
||||
const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/u.exec(mimeType);
|
||||
if (mimeTypeBase64MatchResult) {
|
||||
const stringBody = isomorphicDecode(body);
|
||||
body = forgivingBase64Decode(stringBody);
|
||||
@@ -57,7 +52,7 @@ module.exports.fromURLRecord = urlRecord => {
|
||||
}
|
||||
|
||||
if (mimeType.startsWith(";")) {
|
||||
mimeType = "text/plain" + mimeType;
|
||||
mimeType = `text/plain${mimeType}`;
|
||||
}
|
||||
|
||||
let mimeTypeRecord;
|
||||
|
11
node_modules/data-urls/lib/utils.js
generated
vendored
11
node_modules/data-urls/lib/utils.js
generated
vendored
@@ -1,17 +1,12 @@
|
||||
"use strict";
|
||||
const { percentDecode } = require("whatwg-url");
|
||||
const { atob } = require("abab");
|
||||
|
||||
exports.stripLeadingAndTrailingASCIIWhitespace = string => {
|
||||
return string.replace(/^[ \t\n\f\r]+/, "").replace(/[ \t\n\f\r]+$/, "");
|
||||
};
|
||||
|
||||
exports.stringPercentDecode = input => {
|
||||
return percentDecode(Buffer.from(input, "utf-8"));
|
||||
return string.replace(/^[ \t\n\f\r]+/u, "").replace(/[ \t\n\f\r]+$/u, "");
|
||||
};
|
||||
|
||||
exports.isomorphicDecode = input => {
|
||||
return input.toString("binary");
|
||||
return Array.from(input, byte => String.fromCodePoint(byte)).join("");
|
||||
};
|
||||
|
||||
exports.forgivingBase64Decode = data => {
|
||||
@@ -19,5 +14,5 @@ exports.forgivingBase64Decode = data => {
|
||||
if (asString === null) {
|
||||
return null;
|
||||
}
|
||||
return Buffer.from(asString, "binary");
|
||||
return Uint8Array.from(asString, c => c.codePointAt(0));
|
||||
};
|
||||
|
35
node_modules/data-urls/package.json
generated
vendored
35
node_modules/data-urls/package.json
generated
vendored
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"_from": "data-urls@^2.0.0",
|
||||
"_id": "data-urls@2.0.0",
|
||||
"_from": "data-urls@^3.0.2",
|
||||
"_id": "data-urls@3.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-X5eWTSXO/BJmpdIKCRuKUgSCgAN0OwliVK3yPKbwIWU1Tdw5BRajxlzMidvh+gwko9AfQ9zIj52pzF91Q3YAvQ==",
|
||||
"_integrity": "sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==",
|
||||
"_location": "/data-urls",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "data-urls@^2.0.0",
|
||||
"raw": "data-urls@^3.0.2",
|
||||
"name": "data-urls",
|
||||
"escapedName": "data-urls",
|
||||
"rawSpec": "^2.0.0",
|
||||
"rawSpec": "^3.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.0"
|
||||
"fetchSpec": "^3.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/jsdom"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/data-urls/-/data-urls-2.0.0.tgz",
|
||||
"_shasum": "156485a72963a970f5d5821aaf642bef2bf2db9b",
|
||||
"_spec": "data-urls@^2.0.0",
|
||||
"_resolved": "https://registry.npmjs.org/data-urls/-/data-urls-3.0.2.tgz",
|
||||
"_shasum": "9cf24a477ae22bcef5cd5f6f0bfbc1d2d3be9143",
|
||||
"_spec": "data-urls@^3.0.2",
|
||||
"_where": "D:\\Projects\\minifyfromhtml\\node_modules\\jsdom",
|
||||
"author": {
|
||||
"name": "Domenic Denicola",
|
||||
@@ -32,19 +32,20 @@
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"abab": "^2.0.3",
|
||||
"whatwg-mimetype": "^2.3.0",
|
||||
"whatwg-url": "^8.0.0"
|
||||
"abab": "^2.0.6",
|
||||
"whatwg-mimetype": "^3.0.0",
|
||||
"whatwg-url": "^11.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Parses data: URLs",
|
||||
"devDependencies": {
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^24.9.0",
|
||||
"request": "^2.88.0"
|
||||
"@domenic/eslint-config": "^2.0.0",
|
||||
"eslint": "^8.14.0",
|
||||
"jest": "^27.5.1",
|
||||
"minipass-fetch": "^2.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=12"
|
||||
},
|
||||
"files": [
|
||||
"lib/"
|
||||
@@ -85,5 +86,5 @@
|
||||
"pretest": "node scripts/get-latest-platform-tests.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"version": "2.0.0"
|
||||
"version": "3.0.2"
|
||||
}
|
||||
|
Reference in New Issue
Block a user