fetch-css 3.1.11 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/crx-to-zip.js +5 -5
  2. package/index.js +19 -16
  3. package/package.json +12 -12
package/crx-to-zip.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // based on https://github.com/Rob--W/crxviewer/blob/master/src/lib/crx-to-zip.js
2
2
  // (c) 2013 Rob Wu <rob@robwu.nl>
3
- "use strict";
4
3
 
5
- const encLatin1 = require("crypto-js/enc-latin1");
6
- const sha256 = require("crypto-js/sha256");
4
+ import encLatin1 from "crypto-js/enc-latin1";
5
+ import sha256 from "crypto-js/sha256";
6
+
7
7
  const btoa = require("base-64").encode;
8
8
 
9
9
  function calcLength(a, b, c, d) {
@@ -23,7 +23,7 @@ function getBinaryString(bytesView, startOffset, endOffset) {
23
23
  }
24
24
 
25
25
  // Strips CRX headers from zip
26
- module.exports = function CRXtoZIP(arraybuffer) {
26
+ export default function CRXtoZIP(arraybuffer) {
27
27
  // Definition of crx format: http://developer.chrome.com/extensions/crx.html
28
28
  const view = new Uint8Array(arraybuffer);
29
29
 
@@ -66,7 +66,7 @@ module.exports = function CRXtoZIP(arraybuffer) {
66
66
  }
67
67
 
68
68
  return arraybuffer.slice(zipStartOffset);
69
- };
69
+ }
70
70
 
71
71
  function getPublicKeyFromProtoBuf(bytesView, startOffset, endOffset) {
72
72
  // Protobuf definition: https://cs.chromium.org/chromium/src/components/crx_file/crx3.proto
package/index.js CHANGED
@@ -1,14 +1,16 @@
1
- "use strict";
2
-
3
- const acorn = require("acorn");
4
- const clone = require("rfdc")();
5
- const postcss = require("postcss");
6
- const fetch = require("fetch-enhanced")(require("node-fetch"));
7
- const parse5 = require("parse5");
8
- const unzipper = require("unzipper");
9
- const urlToolkit = require("url-toolkit");
10
- const {name} = require("./package.json");
11
- const crxToZip = require("./crx-to-zip");
1
+ import acorn from "acorn";
2
+ import cloner from "rfdc";
3
+ import postcss from "postcss";
4
+ import {parseFragment} from "parse5";
5
+ import unzipper from "unzipper";
6
+ import urlToolkit from "url-toolkit";
7
+ import {name} from "./package.json";
8
+ import crxToZip from "./crx-to-zip.js";
9
+ import nodeFetch from "node-fetch";
10
+ import fetchEnhanced from "fetch-enhanced";
11
+
12
+ const fetch = fetchEnhanced(nodeFetch);
13
+ const clone = cloner();
12
14
 
13
15
  async function extract(res) {
14
16
  const styleUrls = [];
@@ -38,17 +40,18 @@ function validateStatus(res, url, strict) {
38
40
  function extractStyleHrefs(html) {
39
41
  return (html.match(/<link.+?>/g) || []).map(link => {
40
42
  const attrs = {};
41
- for (const attr of parse5.parseFragment(link).childNodes[0].attrs) {
43
+ for (const attr of parseFragment(link).childNodes[0].attrs) {
42
44
  attrs[attr.name] = attr.value;
43
45
  }
44
46
  if (attrs.href && attrs.rel === "stylesheet") return attrs.href;
45
47
  if (attrs.href && /\.css$/i.test(attrs.href.replace(/\?.+/))) return attrs.href;
46
- }).filter(link => !!link);
48
+ return null;
49
+ }).filter(Boolean);
47
50
  }
48
51
 
49
52
  function extractStyleTags(html) {
50
53
  const matches = Array.from((html || "").matchAll(/<style.*?>([\s\S]*?)<\/style>/g) || []);
51
- return matches.map(match => match[1]).map(css => css.trim()).filter(css => !!css);
54
+ return matches.map(match => match[1]).map(css => css.trim()).filter(Boolean);
52
55
  }
53
56
 
54
57
  function isValidCSS(string) {
@@ -147,7 +150,7 @@ async function extensionCss({crx, contentScriptsOnly, strict}) {
147
150
  return css;
148
151
  }
149
152
 
150
- module.exports = async function fetchCss(sources) {
153
+ export default async function fetchCss(sources) { // eslint-disable-line import/no-unused-modules
151
154
  sources = clone(sources);
152
155
 
153
156
  const expandedSources = [];
@@ -203,4 +206,4 @@ module.exports = async function fetchCss(sources) {
203
206
  }
204
207
 
205
208
  return sources;
206
- };
209
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fetch-css",
3
- "version": "3.1.11",
3
+ "version": "4.0.0",
4
4
  "description": "Extract CSS from websites and browser extensions",
5
5
  "author": "silverwind",
6
6
  "repository": "silverwind/fetch-css",
@@ -20,21 +20,21 @@
20
20
  "crx-to-zip.js"
21
21
  ],
22
22
  "dependencies": {
23
- "acorn": "8.2.1",
23
+ "acorn": "8.8.1",
24
24
  "base-64": "1.0.0",
25
- "crypto-js": "4.0.0",
26
- "fetch-enhanced": "6.0.0",
27
- "node-fetch": "2.6.1",
28
- "parse5": "6.0.1",
29
- "postcss": "8.2.13",
25
+ "crypto-js": "4.1.1",
26
+ "fetch-enhanced": "10.1.0",
27
+ "node-fetch": "3.3.0",
28
+ "parse5": "7.1.1",
29
+ "postcss": "8.4.19",
30
30
  "rfdc": "1.3.0",
31
31
  "unzipper": "0.10.11",
32
- "url-toolkit": "2.2.2"
32
+ "url-toolkit": "2.2.5"
33
33
  },
34
34
  "devDependencies": {
35
- "eslint": "7.25.0",
36
- "eslint-config-silverwind": "32.3.3",
37
- "updates": "12.0.2",
38
- "versions": "8.4.7"
35
+ "eslint": "8.28.0",
36
+ "eslint-config-silverwind": "62.0.1",
37
+ "updates": "13.2.1",
38
+ "versions": "10.2.4"
39
39
  }
40
40
  }