diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a501a14..f8c9a1d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,14 +3,14 @@ name: Build on: pull_request: branches: - - main + - main push: branches: - - main + - main jobs: build: - name: Lint and tests + name: Checks and tests runs-on: ubuntu-latest strategy: fail-fast: false @@ -20,13 +20,13 @@ jobs: - 22.14.0 - 22 - 24.0.0 - - lts/* # currently 24 + - lts/* # currently 24 - latest steps: - - uses: actions/checkout@v7 - - uses: actions/setup-node@v7 - with: - node-version: ${{ matrix.node-version }} - - run: npm ci - - run: npm run lint - - run: npm test + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run check + - run: npm test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 51a08fb..095d4d5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ name: Publish on: push: tags: - - 'v*' + - "v*" permissions: id-token: write @@ -19,6 +19,6 @@ jobs: node-version: lts/* registry-url: https://registry.npmjs.org - run: npm ci - - run: npm run lint + - run: npm run check - run: npm test - run: npm publish diff --git a/.oxfmtrc.json b/.oxfmtrc.json new file mode 100644 index 0000000..b0cf798 --- /dev/null +++ b/.oxfmtrc.json @@ -0,0 +1,4 @@ +{ + "sortImports": true, + "ignorePatterns": ["**/*.html"] +} diff --git a/README.md b/README.md index 9ff1cc1..8553168 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,20 @@ 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); // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ] +console.log(textExample.body); // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ] const htmlExample = parseDataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E"); console.log(htmlExample.mimeType.toString()); // "text/html" -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(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); // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ] +console.log(pngExample.body); // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ] ``` ## API diff --git a/eslint.config.mjs b/eslint.config.mjs index 558aed6..1290039 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,16 +7,16 @@ export default [ files: ["**/*.js"], languageOptions: { sourceType: "commonjs", - globals: globals.node - } + globals: globals.node, + }, }, { files: ["**/*.mjs"], languageOptions: { sourceType: "module", - globals: globals.node - } + globals: globals.node, + }, }, ...domenicConfig, - ...domenicStylisticConfig + ...domenicStylisticConfig, ]; diff --git a/lib/parser.js b/lib/parser.js index f3f708f..04579d5 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,9 +1,13 @@ "use strict"; const { MIMEType } = require("whatwg-mimetype"); const { parseURL, serializeURL, percentDecodeString } = require("whatwg-url"); -const { stripLeadingAndTrailingASCIIWhitespace, isomorphicDecode, forgivingBase64Decode } = require("./utils.js"); +const { + stripLeadingAndTrailingASCIIWhitespace, + isomorphicDecode, + forgivingBase64Decode, +} = require("./utils.js"); -module.exports = stringInput => { +module.exports = (stringInput) => { const urlRecord = parseURL(stringInput); if (urlRecord === null) { @@ -13,7 +17,7 @@ module.exports = stringInput => { return module.exports.fromURLRecord(urlRecord); }; -module.exports.fromURLRecord = urlRecord => { +module.exports.fromURLRecord = (urlRecord) => { if (urlRecord.scheme !== "data") { return null; } @@ -64,6 +68,6 @@ module.exports.fromURLRecord = urlRecord => { return { mimeType: mimeTypeRecord, - body + body, }; }; diff --git a/lib/utils.js b/lib/utils.js index 8f5a424..6fe8355 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,14 +1,14 @@ "use strict"; -exports.stripLeadingAndTrailingASCIIWhitespace = string => { +exports.stripLeadingAndTrailingASCIIWhitespace = (string) => { return string.replace(/^[ \t\n\f\r]+/u, "").replace(/[ \t\n\f\r]+$/u, ""); }; -exports.isomorphicDecode = input => { - return Array.from(input, byte => String.fromCodePoint(byte)).join(""); +exports.isomorphicDecode = (input) => { + return Array.from(input, (byte) => String.fromCodePoint(byte)).join(""); }; -exports.forgivingBase64Decode = data => { +exports.forgivingBase64Decode = (data) => { let asString; try { asString = atob(data); @@ -16,5 +16,5 @@ exports.forgivingBase64Decode = data => { return null; } - return Uint8Array.from(asString, c => c.codePointAt(0)); + return Uint8Array.from(asString, (c) => c.codePointAt(0)); }; diff --git a/package-lock.json b/package-lock.json index b35588f..5608941 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,11 +13,12 @@ "whatwg-url": "^17.1.2" }, "devDependencies": { - "@domenic/eslint-config": "^5.1.0", + "@domenic/eslint-config": "^6.0.0", "@stylistic/eslint-plugin": "^5.10.0", "c8": "^12.0.0", - "eslint": "^10.12.0", - "globals": "^17.13.0" + "eslint": "^10.13.0", + "globals": "^17.13.0", + "oxfmt": "0.75.0" }, "engines": { "node": "^22.14.0 || >=24.0.0" @@ -58,14 +59,14 @@ } }, "node_modules/@domenic/eslint-config": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@domenic/eslint-config/-/eslint-config-5.1.0.tgz", - "integrity": "sha512-RaBVEY4KD1c6I+K0dmShWB4AspSDzDpQAp/XElETz/TqDlW5253kHjYRHe16gTboyEA/IBHqoIy+sbQKC2+tXA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@domenic/eslint-config/-/eslint-config-6.0.0.tgz", + "integrity": "sha512-eBV6L5JvT31O/h0ihxJoSajtCjquAK+PdgGYfawM4f0JblZT2t7/ItcQ4NnGDlNyR+hq+oZmK23OMgZYozgXNA==", "dev": true, "license": "Apache-2.0", "peerDependencies": { "@stylistic/eslint-plugin": "^5.10.0", - "eslint": "^10.0.3" + "eslint": "^10.13.0" }, "peerDependenciesMeta": { "@stylistic/eslint-plugin": { @@ -325,6 +326,353 @@ "dev": true, "license": "MIT" }, + "node_modules/@oxfmt/binding-android-arm-eabi": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-android-arm-eabi/-/binding-android-arm-eabi-0.75.0.tgz", + "integrity": "sha512-zHJ7LcTN46/5mtoLxsUu14pdF9ixFwDURtmxZ0CeNwqom5qB5NRVqU6o2GRZ7QPdNBW8G6j9UTJzQ+EDevMH0w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-android-arm64": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-android-arm64/-/binding-android-arm64-0.75.0.tgz", + "integrity": "sha512-IdxsKZJvHZUvI7q6kLmzXdEFpFiBEDQw/WJtSp1QlzNXBw1JlLN3tY50WwWd4doPnq86XW4P+7BsQwu6meCW+w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-darwin-arm64": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-darwin-arm64/-/binding-darwin-arm64-0.75.0.tgz", + "integrity": "sha512-vyiqZilO5jal/nXZ0143NyKcP6TkzjaQdVEWU/kwgyWqugAgIRgAbrnO3MOF+e6LkQu3CrtrkPoc3mrsZZY6cA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-darwin-x64": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-darwin-x64/-/binding-darwin-x64-0.75.0.tgz", + "integrity": "sha512-oua7eVqVe769mDam6ORcavygxTzG3ovo5QRQ1kJCPaEbnWXPYhtAiYDj8pajVmFjO7j8Elf3gInnWpTX0LLYtg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-freebsd-x64": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-freebsd-x64/-/binding-freebsd-x64-0.75.0.tgz", + "integrity": "sha512-NWkbezhg7mx2Ep94g/TysR3c1bsISsU4lQ6t5xI4841PAk0Kqcn1+UEe+BoFH2/UK2YegPXq+OF+0bUcSvUalA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-arm-gnueabihf": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-0.75.0.tgz", + "integrity": "sha512-CAHX87kJplTq2E0OWP7opG8gEVlHc7CeLEi4nMJOyx3psuqBKf84HZ3UIkX2guWEJ5UljU2zJF0o46XylywVVA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-arm-musleabihf": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-arm-musleabihf/-/binding-linux-arm-musleabihf-0.75.0.tgz", + "integrity": "sha512-jmxYOiQzx2fp+OwQb7717K1zI8AMKEykw04sfr95/mU8SIL/oKgQq8nXH42sEznEquBL2RU7nLY36eBnYFT+vg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-arm64-gnu": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-0.75.0.tgz", + "integrity": "sha512-eimaiAhx08dbOg12Fj3PYhymXY8vRbaiJB505vDXMy6ohne3Y1qTS0e5KEwFMq3LmDjEO+16BX38c/oXFI/SAQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-arm64-musl": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-arm64-musl/-/binding-linux-arm64-musl-0.75.0.tgz", + "integrity": "sha512-bjSONIG1ba2xugr9oHQau0E6oPFYOMjPaa5hK/wpVC/Q1pcgf2BZMKwbuA8/cWzhWX5QV/UdPzD+rw1kQHpikQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-ppc64-gnu": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-0.75.0.tgz", + "integrity": "sha512-wDksWQXC/KZucISyqlhBtvpW+pyHh8z0Cjm6Qxiv22XlllM2Bx5gJGDnPYjV+H0lL+o1iqLlEli8jmBuRCLcjw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-riscv64-gnu": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-0.75.0.tgz", + "integrity": "sha512-5JkNwViqaVuk4I+9+zgVrEYiHOAPXFxgDgP6iDnpdOBjm7XAHAOjSvolHZZAokWPx7CGOw8tKteXmn4WPIInaQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-riscv64-musl": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-0.75.0.tgz", + "integrity": "sha512-1EVqRIE0eZLB08j3ZCVN47Ors7LCXGmOI+3xJYgyoFUKUerD3Glxb+Q1Bp3lK8NeT5R3ZdS9uhX/wobNBYZ6jw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-s390x-gnu": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-0.75.0.tgz", + "integrity": "sha512-UJWRVNT6Yuw4ssLv2BwaBUWU1GWtByE+EnoHu8I+P1t8Kn+WozYU5WYOqb5aj8gbXJJ8gGZt+w40Hi/7L6iVLw==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-x64-gnu": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-x64-gnu/-/binding-linux-x64-gnu-0.75.0.tgz", + "integrity": "sha512-FHdvHhyz8ChBctBUvVGti49kSEwANd1PZQwlXUEoF9Ed4plxXxk/wWc0mfZmrze2lRgmME7ytDmVIOixYauQhg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-linux-x64-musl": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-linux-x64-musl/-/binding-linux-x64-musl-0.75.0.tgz", + "integrity": "sha512-6MjtsF96s9mSBV0GEwUe4pOFPP2Mz7ahcHPAit0DSKL5fM6oMM7RG1zvYxwB7+SBkIxsWBRhhxuqmy7pibNwsA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-openharmony-arm64": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-openharmony-arm64/-/binding-openharmony-arm64-0.75.0.tgz", + "integrity": "sha512-1D6T6aL1Pj+U5GLxqwV1fKjUJ5+FFm+bn7UrqNDMveZmWs0jo/3vc+dzzuV/jF/FdVo12gowODk3SnAO2YOwLg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-win32-arm64-msvc": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-0.75.0.tgz", + "integrity": "sha512-RX2eUmy7J/nM8+tnM3nzR8t1eqkwj1q8Kgo7beA+4DVgKYYHHyrEa3qEmthxw7Z+HqpCCEOWuoqa+jelo9/w2Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-win32-ia32-msvc": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-0.75.0.tgz", + "integrity": "sha512-UpKta0iSZmPLII0dYXYdbzdBTsGREUbSHLqgLdtKcqBvs40qjmUz+cgUcaU1smPx13DfbEG4XqnaSn5MoFN0og==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxfmt/binding-win32-x64-msvc": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/@oxfmt/binding-win32-x64-msvc/-/binding-win32-x64-msvc-0.75.0.tgz", + "integrity": "sha512-pjiLiCk0QMCWxs0n5XiNU85YLAKA+wJxPjxlDVygmr4bP4glcfTU2nOpso5nR4Rdi2Pxv5YwakD4UE+eh7M0BQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, "node_modules/@stylistic/eslint-plugin": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-5.10.0.tgz", @@ -636,9 +984,9 @@ } }, "node_modules/eslint": { - "version": "10.12.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.12.0.tgz", - "integrity": "sha512-npHjrHb2o4ehH3mE+YuxABR+0gyb0aVWCIolgJDArwCiHEIsonBm3ZKjel5b0U5+a+MbEvIyRCGCzD3eKKK2NA==", + "version": "10.13.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.13.0.tgz", + "integrity": "sha512-UohDjD4zSzEwhf58M3O7vc/ycc8O1I7dNlhtD0WxE8Px8EHNJKtUwzBqrzeGhisRuv2ag4sAYswszCJRgKXYUg==", "dev": true, "license": "MIT", "workspaces": [ @@ -1236,6 +1584,62 @@ "node": ">= 0.8.0" } }, + "node_modules/oxfmt": { + "version": "0.75.0", + "resolved": "https://registry.npmjs.org/oxfmt/-/oxfmt-0.75.0.tgz", + "integrity": "sha512-/ZKvY5asfsVi9hdkOmRIumqOPu6kxlTgiJSZf54uq29kKew+Gu1FFAnEkGePyvLVW+MAYu41D6XggnzoElQzPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinypool": "2.2.0" + }, + "bin": { + "oxfmt": "bin/oxfmt" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/sponsors/oxc-project" + }, + "optionalDependencies": { + "@oxfmt/binding-android-arm-eabi": "0.75.0", + "@oxfmt/binding-android-arm64": "0.75.0", + "@oxfmt/binding-darwin-arm64": "0.75.0", + "@oxfmt/binding-darwin-x64": "0.75.0", + "@oxfmt/binding-freebsd-x64": "0.75.0", + "@oxfmt/binding-linux-arm-gnueabihf": "0.75.0", + "@oxfmt/binding-linux-arm-musleabihf": "0.75.0", + "@oxfmt/binding-linux-arm64-gnu": "0.75.0", + "@oxfmt/binding-linux-arm64-musl": "0.75.0", + "@oxfmt/binding-linux-ppc64-gnu": "0.75.0", + "@oxfmt/binding-linux-riscv64-gnu": "0.75.0", + "@oxfmt/binding-linux-riscv64-musl": "0.75.0", + "@oxfmt/binding-linux-s390x-gnu": "0.75.0", + "@oxfmt/binding-linux-x64-gnu": "0.75.0", + "@oxfmt/binding-linux-x64-musl": "0.75.0", + "@oxfmt/binding-openharmony-arm64": "0.75.0", + "@oxfmt/binding-win32-arm64-msvc": "0.75.0", + "@oxfmt/binding-win32-ia32-msvc": "0.75.0", + "@oxfmt/binding-win32-x64-msvc": "0.75.0" + }, + "peerDependencies": { + "@astrojs/compiler-rs": "^0.5.0", + "svelte": "^5.0.0", + "vite-plus": "*" + }, + "peerDependenciesMeta": { + "@astrojs/compiler-rs": { + "optional": true + }, + "svelte": { + "optional": true + }, + "vite-plus": { + "optional": true + } + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -1467,6 +1871,16 @@ "node": "20 || >=22" } }, + "node_modules/tinypool": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-2.2.0.tgz", + "integrity": "sha512-jBrmx4lYmaC9k/mgPbylxs7kBUxHtD8256up+HjLaDFfXScKJQyil+SWXSvhAtT7XHo+yTVlpB81PGmHP8oLSQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.0.0 || >=22.0.0" + } + }, "node_modules/tr46": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-6.0.0.tgz", diff --git a/package.json b/package.json index 570ede8..44f5f24 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,33 @@ { "name": "data-urls", + "version": "8.0.0", "description": "Parses data: URLs", "keywords": [ - "data url", "data uri", + "data url", "data:", - "http", "fetch", + "http", "whatwg" ], - "version": "8.0.0", - "author": "Domenic Denicola (https://domenic.me/)", "license": "MIT", + "author": "Domenic Denicola (https://domenic.me/)", "repository": { "type": "git", "url": "git+https://github.com/jsdom/data-urls.git" }, - "main": "lib/parser.js", "files": [ "lib/" ], + "main": "lib/parser.js", "scripts": { "test": "node --test", "coverage": "c8 node --test --experimental-test-coverage", + "check": "npm run lint && npm run fmt:check", "lint": "eslint", + "lint:fix": "eslint --fix", + "fmt": "oxfmt", + "fmt:check": "oxfmt --check", "pretest": "node scripts/get-latest-platform-tests.mjs" }, "dependencies": { @@ -31,22 +35,23 @@ "whatwg-url": "^17.1.2" }, "devDependencies": { - "@domenic/eslint-config": "^5.1.0", + "@domenic/eslint-config": "^6.0.0", "@stylistic/eslint-plugin": "^5.10.0", "c8": "^12.0.0", - "eslint": "^10.12.0", - "globals": "^17.13.0" - }, - "engines": { - "node": "^22.14.0 || >=24.0.0" + "eslint": "^10.13.0", + "globals": "^17.13.0", + "oxfmt": "0.75.0" }, "c8": { - "reporter": [ - "html" - ], "exclude": [ "scripts/", "test/" + ], + "reporter": [ + "html" ] + }, + "engines": { + "node": "^22.14.0 || >=24.0.0" } } diff --git a/scripts/get-latest-platform-tests.mjs b/scripts/get-latest-platform-tests.mjs index 1259dfd..09243b5 100644 --- a/scripts/get-latest-platform-tests.mjs +++ b/scripts/get-latest-platform-tests.mjs @@ -13,15 +13,18 @@ if (process.env.NO_UPDATE) { // 3. Copy the commit hash const commitHash = "2dc0ad4f330f0b5647d11b00ae7437b668cb8df3"; -const urlPrefix = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}` + - `/fetch/data-urls/resources/`; +const urlPrefix = + `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}` + + `/fetch/data-urls/resources/`; const files = ["base64.json", "data-urls.json"]; -await Promise.all(files.map(async file => { - const url = urlPrefix + file; - const targetFile = path.resolve(import.meta.dirname, "..", "test", "web-platform-tests", file); +await Promise.all( + files.map(async (file) => { + const url = urlPrefix + file; + const targetFile = path.resolve(import.meta.dirname, "..", "test", "web-platform-tests", file); - const res = await fetch(url); - await fs.writeFile(targetFile, res.body); -})); + const res = await fetch(url); + await fs.writeFile(targetFile, res.body); + }), +); diff --git a/test/api.js b/test/api.js index 29b8247..71f79eb 100644 --- a/test/api.js +++ b/test/api.js @@ -13,7 +13,10 @@ describe("Smoke tests via README examples", () => { const textExample = parseDataURL("data:,Hello%2C%20World!"); assert.equal(textExample.mimeType.toString(), "text/plain;charset=US-ASCII"); assert.equal(textExample.body.constructor, Uint8Array); - assert.deepEqual(textExample.body, new Uint8Array([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33])); + assert.deepEqual( + textExample.body, + new Uint8Array([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]), + ); }); it("should round-trip no-type as expected", () => { @@ -37,28 +40,33 @@ describe("Smoke tests via README examples", () => { const htmlExample = parseDataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E"); assert.equal(htmlExample.mimeType.toString(), "text/html"); assert.equal(htmlExample.body.constructor, Uint8Array); - assert.deepEqual(htmlExample.body, new Uint8Array([ - 60, 104, 49, 62, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 60, 47, 104, 49, 62 - ])); + assert.deepEqual( + htmlExample.body, + new Uint8Array([ + 60, 104, 49, 62, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 60, 47, 104, + 49, 62, + ]), + ); }); it("should parse img/png base64 as expected", () => { - const pngExample = parseDataURL("data:image/png;base64,iVBORw0KGgoAAA" + - "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" + - "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" + - "5ErkJggg=="); + const pngExample = parseDataURL( + "data:image/png;base64,iVBORw0KGgoAAA" + + "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" + + "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" + + "5ErkJggg==", + ); assert.equal(pngExample.mimeType.toString(), "image/png"); assert.equal(pngExample.body.constructor, Uint8Array); - assert.deepEqual(pngExample.body, new Uint8Array([ - 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, - 73, 72, 68, 82, 0, 0, 0, 5, 0, 0, 0, 5, - 8, 6, 0, 0, 0, 141, 111, 38, 229, 0, 0, 0, - 28, 73, 68, 65, 84, 8, 215, 99, 248, 255, 255, 63, - 195, 127, 6, 32, 5, 195, 32, 18, 132, 208, 49, 241, - 130, 88, 205, 4, 0, 14, 245, 53, 203, 209, 142, 14, - 31, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, - 130 - ])); + assert.deepEqual( + pngExample.body, + new Uint8Array([ + 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 5, 0, 0, 0, 5, 8, 6, + 0, 0, 0, 141, 111, 38, 229, 0, 0, 0, 28, 73, 68, 65, 84, 8, 215, 99, 248, 255, 255, 63, 195, + 127, 6, 32, 5, 195, 32, 18, 132, 208, 49, 241, 130, 88, 205, 4, 0, 14, 245, 53, 203, 209, + 142, 14, 31, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, + ]), + ); }); });