fetch-css 3.1.12 → 4.0.1

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.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  npm i fetch-css
9
9
  ```
10
10
  ```js
11
- const fetchCss = require("fetch-css");
11
+ import fetchCss from "fetch-css";
12
12
 
13
13
  // retrieve CSS of a website
14
14
  const [{css}] = await fetchCss([{url: "https://example.com"}]);
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,15 @@
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 crxToZip from "./crx-to-zip.js";
8
+ import nodeFetch from "node-fetch";
9
+ import fetchEnhanced from "fetch-enhanced";
10
+
11
+ const fetch = fetchEnhanced(nodeFetch);
12
+ const clone = cloner();
12
13
 
13
14
  async function extract(res) {
14
15
  const styleUrls = [];
@@ -31,24 +32,25 @@ function validateStatus(res, url, strict) {
31
32
  if (strict) {
32
33
  throw new Error(msg);
33
34
  } else {
34
- console.warn(`(${name}) Warning: ${msg}`);
35
+ console.warn(`(fetch-css) Warning: ${msg}`);
35
36
  }
36
37
  }
37
38
 
38
39
  function extractStyleHrefs(html) {
39
40
  return (html.match(/<link.+?>/g) || []).map(link => {
40
41
  const attrs = {};
41
- for (const attr of parse5.parseFragment(link).childNodes[0].attrs) {
42
+ for (const attr of parseFragment(link).childNodes[0].attrs) {
42
43
  attrs[attr.name] = attr.value;
43
44
  }
44
45
  if (attrs.href && attrs.rel === "stylesheet") return attrs.href;
45
46
  if (attrs.href && /\.css$/i.test(attrs.href.replace(/\?.+/))) return attrs.href;
46
- }).filter(link => !!link);
47
+ return null;
48
+ }).filter(Boolean);
47
49
  }
48
50
 
49
51
  function extractStyleTags(html) {
50
52
  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);
53
+ return matches.map(match => match[1]).map(css => css.trim()).filter(Boolean);
52
54
  }
53
55
 
54
56
  function isValidCSS(string) {
@@ -147,7 +149,7 @@ async function extensionCss({crx, contentScriptsOnly, strict}) {
147
149
  return css;
148
150
  }
149
151
 
150
- module.exports = async function fetchCss(sources) {
152
+ export default async function fetchCss(sources) { // eslint-disable-line import/no-unused-modules
151
153
  sources = clone(sources);
152
154
 
153
155
  const expandedSources = [];
@@ -203,4 +205,4 @@ module.exports = async function fetchCss(sources) {
203
205
  }
204
206
 
205
207
  return sources;
206
- };
208
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fetch-css",
3
- "version": "3.1.12",
3
+ "version": "4.0.1",
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.4",
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.15",
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.26.0",
36
- "eslint-config-silverwind": "33.0.0",
37
- "updates": "12.1.0",
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
  }