diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /alarm/node_modules/data-urls | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'alarm/node_modules/data-urls')
-rw-r--r-- | alarm/node_modules/data-urls/LICENSE.txt | 7 | ||||
-rw-r--r-- | alarm/node_modules/data-urls/README.md | 64 | ||||
-rw-r--r-- | alarm/node_modules/data-urls/lib/parser.js | 74 | ||||
-rw-r--r-- | alarm/node_modules/data-urls/lib/utils.js | 23 | ||||
-rw-r--r-- | alarm/node_modules/data-urls/package.json | 53 |
5 files changed, 0 insertions, 221 deletions
diff --git a/alarm/node_modules/data-urls/LICENSE.txt b/alarm/node_modules/data-urls/LICENSE.txt deleted file mode 100644 index d394616..0000000 --- a/alarm/node_modules/data-urls/LICENSE.txt +++ /dev/null @@ -1,7 +0,0 @@ -Copyright © 2017–2020 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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/alarm/node_modules/data-urls/README.md b/alarm/node_modules/data-urls/README.md deleted file mode 100644 index 2e7fac7..0000000 --- a/alarm/node_modules/data-urls/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# Parse `data:` URLs - -This package helps you parse `data:` URLs [according to the WHATWG Fetch Standard](https://fetch.spec.whatwg.org/#data-urls): - -```js -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!" - -const htmlExample = dataURL("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> - -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 ... > -``` - -## API - -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. - -As shown in the examples above, both of these have useful `toString()` methods for manipulating them as string values. However… - -### A word of caution on string decoding - -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: - -```js -const parseDataURL = require("data-urls"); -const { labelToName, decode } = require("whatwg-encoding"); - -const dataURL = parseDataURL(arbitraryString); -const encodingName = labelToName(dataURL.mimeType.parameters.get("charset")); -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). - -### Advanced functionality: parsing from a URL record - -If you are using the [whatwg-url](https://github.com/jsdom/whatwg-url) package, you may already have a "URL record" object on hand, as produced by that package's `parseURL` export. In that case, you can use this package's `fromURLRecord` export to save a bit of work: - -```js -const { parseURL } = require("whatwg-url"); -const dataURLFromURLRecord = require("data-urls").fromURLRecord; - -const urlRecord = parseURL("data:,Hello%2C%20World!"); -const dataURL = dataURLFromURLRecord(urlRecord); -``` - -In practice, we expect this functionality only to be used by consumers like [jsdom](https://www.npmjs.com/package/jsdom), which are using these packages at a very low level. diff --git a/alarm/node_modules/data-urls/lib/parser.js b/alarm/node_modules/data-urls/lib/parser.js deleted file mode 100644 index 37be0ef..0000000 --- a/alarm/node_modules/data-urls/lib/parser.js +++ /dev/null @@ -1,74 +0,0 @@ -"use strict"; -const MIMEType = require("whatwg-mimetype"); -const { parseURL, serializeURL } = require("whatwg-url"); -const { - stripLeadingAndTrailingASCIIWhitespace, - stringPercentDecode, - isomorphicDecode, - forgivingBase64Decode -} = require("./utils.js"); - -module.exports = stringInput => { - const urlRecord = parseURL(stringInput); - - if (urlRecord === null) { - return null; - } - - return module.exports.fromURLRecord(urlRecord); -}; - -module.exports.fromURLRecord = urlRecord => { - if (urlRecord.scheme !== "data") { - return null; - } - - const input = serializeURL(urlRecord, true).substring("data:".length); - - let position = 0; - - let mimeType = ""; - while (position < input.length && input[position] !== ",") { - mimeType += input[position]; - ++position; - } - mimeType = stripLeadingAndTrailingASCIIWhitespace(mimeType); - - if (position === input.length) { - return null; - } - - ++position; - - const encodedBody = input.substring(position); - - let body = stringPercentDecode(encodedBody); - - // Can't use /i regexp flag because it isn't restricted to ASCII. - const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/.exec(mimeType); - if (mimeTypeBase64MatchResult) { - const stringBody = isomorphicDecode(body); - body = forgivingBase64Decode(stringBody); - - if (body === null) { - return null; - } - mimeType = mimeTypeBase64MatchResult[1]; - } - - if (mimeType.startsWith(";")) { - mimeType = "text/plain" + mimeType; - } - - let mimeTypeRecord; - try { - mimeTypeRecord = new MIMEType(mimeType); - } catch (e) { - mimeTypeRecord = new MIMEType("text/plain;charset=US-ASCII"); - } - - return { - mimeType: mimeTypeRecord, - body - }; -}; diff --git a/alarm/node_modules/data-urls/lib/utils.js b/alarm/node_modules/data-urls/lib/utils.js deleted file mode 100644 index 213029f..0000000 --- a/alarm/node_modules/data-urls/lib/utils.js +++ /dev/null @@ -1,23 +0,0 @@ -"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")); -}; - -exports.isomorphicDecode = input => { - return input.toString("binary"); -}; - -exports.forgivingBase64Decode = data => { - const asString = atob(data); - if (asString === null) { - return null; - } - return Buffer.from(asString, "binary"); -}; diff --git a/alarm/node_modules/data-urls/package.json b/alarm/node_modules/data-urls/package.json deleted file mode 100644 index 3e2d9d1..0000000 --- a/alarm/node_modules/data-urls/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "data-urls", - "description": "Parses data: URLs", - "keywords": [ - "data url", - "data uri", - "data:", - "http", - "fetch", - "whatwg" - ], - "version": "2.0.0", - "author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)", - "license": "MIT", - "repository": "jsdom/data-urls", - "main": "lib/parser.js", - "files": [ - "lib/" - ], - "scripts": { - "test": "jest", - "coverage": "jest --coverage", - "lint": "eslint .", - "pretest": "node scripts/get-latest-platform-tests.js" - }, - "dependencies": { - "abab": "^2.0.3", - "whatwg-mimetype": "^2.3.0", - "whatwg-url": "^8.0.0" - }, - "devDependencies": { - "eslint": "^6.8.0", - "jest": "^24.9.0", - "request": "^2.88.0" - }, - "engines": { - "node": ">=10" - }, - "jest": { - "coverageDirectory": "coverage", - "coverageReporters": [ - "lcov", - "text-summary" - ], - "testEnvironment": "node", - "testMatch": [ - "<rootDir>/test/**/*.js" - ], - "coveragePathIgnorePatterns": [ - "<rootDir>/node_modules/(?!(abab/lib/atob.js))" - ] - } -} |