string-extract-sass-vars 3.0.5 → 3.0.6

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.
@@ -1,92 +1,111 @@
1
1
  /**
2
2
  * @name string-extract-sass-vars
3
3
  * @fileoverview Parse SASS variables file into a plain object of CSS key-value pairs
4
- * @version 3.0.5
4
+ * @version 3.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-extract-sass-vars/}
8
8
  */
9
9
 
10
- var version$1 = "3.0.5";
10
+ var version$1 = "3.0.6";
11
11
 
12
12
  const version = version$1;
13
13
  const BACKSLASH = "\u005C";
14
14
  const defaults = {
15
- throwIfEmpty: false,
16
- cb: null
15
+ throwIfEmpty: false,
16
+ cb: null,
17
17
  };
18
18
  function extractVars(str, originalOpts) {
19
- if (typeof str !== "string") {
20
- return {};
21
- }
22
- if (originalOpts && typeof originalOpts !== "object") {
23
- throw new Error(`string-extract-sass-vars: [THROW_ID_01] the second input argument should be a plain object but it was given as ${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
24
- }
25
- const opts = { ...defaults,
26
- ...originalOpts
27
- };
28
- if (opts.cb && typeof opts.cb !== "function") {
29
- throw new Error(`string-extract-sass-vars: [THROW_ID_02] opts.cb should be function! But it was given as ${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
30
- }
31
- const len = str.length;
32
- let varNameStartsAt = null;
33
- let varValueStartsAt = null;
34
- let varName = null;
35
- let varValue = null;
36
- let withinQuotes = null;
37
- let lastNonQuoteCharAt = null;
38
- let withinComments = false;
39
- let withinSlashSlashComment = false;
40
- let withinSlashAsteriskComment = false;
41
- const res = {};
42
- for (let i = 0; i < len; i++) {
43
- if (!withinComments && withinQuotes && str[i] === withinQuotes && str[i - 1] !== BACKSLASH) {
44
- withinQuotes = null;
19
+ if (typeof str !== "string") {
20
+ return {};
45
21
  }
46
- else if (!withinQuotes && !withinComments && str[i - 1] !== BACKSLASH && `'"`.includes(str[i])) {
47
- withinQuotes = str[i];
22
+ if (originalOpts && typeof originalOpts !== "object") {
23
+ throw new Error(`string-extract-sass-vars: [THROW_ID_01] the second input argument should be a plain object but it was given as ${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
48
24
  }
49
- if (withinSlashSlashComment && `\r\n`.includes(str[i])) {
50
- withinSlashSlashComment = false;
25
+ const opts = { ...defaults, ...originalOpts };
26
+ if (opts.cb && typeof opts.cb !== "function") {
27
+ throw new Error(`string-extract-sass-vars: [THROW_ID_02] opts.cb should be function! But it was given as ${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
51
28
  }
52
- if (!withinComments && str[i] === "/" && str[i + 1] === "/") {
53
- withinSlashSlashComment = true;
29
+ const len = str.length;
30
+ let varNameStartsAt = null;
31
+ let varValueStartsAt = null;
32
+ let varName = null;
33
+ let varValue = null;
34
+ let withinQuotes = null;
35
+ let lastNonQuoteCharAt = null;
36
+ let withinComments = false;
37
+ let withinSlashSlashComment = false;
38
+ let withinSlashAsteriskComment = false;
39
+ const res = {};
40
+ for (let i = 0; i < len; i++) {
41
+ if (!withinComments &&
42
+ withinQuotes &&
43
+ str[i] === withinQuotes &&
44
+ str[i - 1] !== BACKSLASH) {
45
+ withinQuotes = null;
46
+ }
47
+ else if (!withinQuotes &&
48
+ !withinComments &&
49
+ str[i - 1] !== BACKSLASH &&
50
+ `'"`.includes(str[i])) {
51
+ withinQuotes = str[i];
52
+ }
53
+ if (withinSlashSlashComment && `\r\n`.includes(str[i])) {
54
+ withinSlashSlashComment = false;
55
+ }
56
+ if (!withinComments && str[i] === "/" && str[i + 1] === "/") {
57
+ withinSlashSlashComment = true;
58
+ }
59
+ if (withinSlashAsteriskComment &&
60
+ str[i - 2] === "*" &&
61
+ str[i - 1] === "/") {
62
+ withinSlashAsteriskComment = false;
63
+ }
64
+ if (!withinComments && str[i] === "/" && str[i + 1] === "*") {
65
+ withinSlashAsteriskComment = true;
66
+ }
67
+ withinComments = withinSlashSlashComment || withinSlashAsteriskComment;
68
+ if (!withinComments && str[i] === "$" && varNameStartsAt === null) {
69
+ varNameStartsAt = i + 1;
70
+ }
71
+ if (!withinComments &&
72
+ varValueStartsAt !== null &&
73
+ !withinQuotes &&
74
+ str[i] === ";") {
75
+ varValue = str.slice(!`"'`.includes(str[varValueStartsAt])
76
+ ? varValueStartsAt
77
+ : varValueStartsAt + 1, (lastNonQuoteCharAt || 0) + 1);
78
+ if (/^-?\d*\.?\d*$/.test(varValue)) {
79
+ varValue = +varValue;
80
+ }
81
+ res[varName] = opts.cb ? opts.cb(varValue) : varValue;
82
+ varNameStartsAt = null;
83
+ varValueStartsAt = null;
84
+ varName = null;
85
+ varValue = null;
86
+ }
87
+ if (!withinComments &&
88
+ varName !== null &&
89
+ str[i] &&
90
+ str[i].trim().length &&
91
+ varValueStartsAt === null) {
92
+ varValueStartsAt = i;
93
+ }
94
+ if (!withinComments &&
95
+ !varName &&
96
+ varNameStartsAt !== null &&
97
+ str[i] === ":" &&
98
+ !withinQuotes) {
99
+ varName = str.slice(varNameStartsAt, i);
100
+ }
101
+ if (!`'"`.includes(str[i])) {
102
+ lastNonQuoteCharAt = i;
103
+ }
54
104
  }
55
- if (withinSlashAsteriskComment && str[i - 2] === "*" && str[i - 1] === "/") {
56
- withinSlashAsteriskComment = false;
105
+ if (!Object.keys(res).length && opts.throwIfEmpty) {
106
+ throw new Error(`string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)`);
57
107
  }
58
- if (!withinComments && str[i] === "/" && str[i + 1] === "*") {
59
- withinSlashAsteriskComment = true;
60
- }
61
- withinComments = withinSlashSlashComment || withinSlashAsteriskComment;
62
- if (!withinComments && str[i] === "$" && varNameStartsAt === null) {
63
- varNameStartsAt = i + 1;
64
- }
65
- if (!withinComments && varValueStartsAt !== null && !withinQuotes && str[i] === ";") {
66
- varValue = str.slice(!`"'`.includes(str[varValueStartsAt]) ? varValueStartsAt : varValueStartsAt + 1, (lastNonQuoteCharAt || 0) + 1);
67
- if (/^-?\d*\.?\d*$/.test(varValue)) {
68
- varValue = +varValue;
69
- }
70
- res[varName] = opts.cb ? opts.cb(varValue) : varValue;
71
- varNameStartsAt = null;
72
- varValueStartsAt = null;
73
- varName = null;
74
- varValue = null;
75
- }
76
- if (!withinComments && varName !== null && str[i] && str[i].trim().length && varValueStartsAt === null) {
77
- varValueStartsAt = i;
78
- }
79
- if (!withinComments && !varName && varNameStartsAt !== null && str[i] === ":" && !withinQuotes) {
80
- varName = str.slice(varNameStartsAt, i);
81
- }
82
- if (!`'"`.includes(str[i])) {
83
- lastNonQuoteCharAt = i;
84
- }
85
- }
86
- if (!Object.keys(res).length && opts.throwIfEmpty) {
87
- throw new Error(`string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)`);
88
- }
89
- return res;
108
+ return res;
90
109
  }
91
110
 
92
111
  export { defaults, extractVars, version };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name string-extract-sass-vars
3
3
  * @fileoverview Parse SASS variables file into a plain object of CSS key-value pairs
4
- * @version 3.0.5
4
+ * @version 3.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-extract-sass-vars/}
8
8
  */
9
9
 
10
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).stringExtractSassVars={})}(this,(function(t){"use strict";const e={throwIfEmpty:!1,cb:null};t.defaults=e,t.extractVars=function(t,n){if("string"!=typeof t)return{};if(n&&"object"!=typeof n)throw new Error(`string-extract-sass-vars: [THROW_ID_01] the second input argument should be a plain object but it was given as ${JSON.stringify(n,null,4)} (type ${typeof n})`);const l={...e,...n};if(l.cb&&"function"!=typeof l.cb)throw new Error(`string-extract-sass-vars: [THROW_ID_02] opts.cb should be function! But it was given as ${JSON.stringify(n,null,4)} (type ${typeof n})`);const s=t.length;let r=null,o=null,i=null,u=null,c=null,f=null,a=!1,d=!1,p=!1;const y={};for(let e=0;e<s;e++)!a&&c&&t[e]===c&&"\\"!==t[e-1]?c=null:c||a||"\\"===t[e-1]||!"'\"".includes(t[e])||(c=t[e]),d&&"\r\n".includes(t[e])&&(d=!1),a||"/"!==t[e]||"/"!==t[e+1]||(d=!0),p&&"*"===t[e-2]&&"/"===t[e-1]&&(p=!1),a||"/"!==t[e]||"*"!==t[e+1]||(p=!0),a=d||p,a||"$"!==t[e]||null!==r||(r=e+1),a||null===o||c||";"!==t[e]||(u=t.slice("\"'".includes(t[o])?o+1:o,(f||0)+1),/^-?\d*\.?\d*$/.test(u)&&(u=+u),y[i]=l.cb?l.cb(u):u,r=null,o=null,i=null,u=null),!a&&null!==i&&t[e]&&t[e].trim().length&&null===o&&(o=e),a||i||null===r||":"!==t[e]||c||(i=t.slice(r,e)),"'\"".includes(t[e])||(f=e);if(!Object.keys(y).length&&l.throwIfEmpty)throw new Error("string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)");return y},t.version="3.0.5",Object.defineProperty(t,"__esModule",{value:!0})}));
10
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).stringExtractSassVars={})}(this,(function(t){"use strict";const e={throwIfEmpty:!1,cb:null};t.defaults=e,t.extractVars=function(t,n){if("string"!=typeof t)return{};if(n&&"object"!=typeof n)throw new Error(`string-extract-sass-vars: [THROW_ID_01] the second input argument should be a plain object but it was given as ${JSON.stringify(n,null,4)} (type ${typeof n})`);const l={...e,...n};if(l.cb&&"function"!=typeof l.cb)throw new Error(`string-extract-sass-vars: [THROW_ID_02] opts.cb should be function! But it was given as ${JSON.stringify(n,null,4)} (type ${typeof n})`);const s=t.length;let r=null,o=null,i=null,u=null,c=null,f=null,a=!1,d=!1,p=!1;const y={};for(let e=0;e<s;e++)!a&&c&&t[e]===c&&"\\"!==t[e-1]?c=null:c||a||"\\"===t[e-1]||!"'\"".includes(t[e])||(c=t[e]),d&&"\r\n".includes(t[e])&&(d=!1),a||"/"!==t[e]||"/"!==t[e+1]||(d=!0),p&&"*"===t[e-2]&&"/"===t[e-1]&&(p=!1),a||"/"!==t[e]||"*"!==t[e+1]||(p=!0),a=d||p,a||"$"!==t[e]||null!==r||(r=e+1),a||null===o||c||";"!==t[e]||(u=t.slice("\"'".includes(t[o])?o+1:o,(f||0)+1),/^-?\d*\.?\d*$/.test(u)&&(u=+u),y[i]=l.cb?l.cb(u):u,r=null,o=null,i=null,u=null),!a&&null!==i&&t[e]&&t[e].trim().length&&null===o&&(o=e),a||i||null===r||":"!==t[e]||c||(i=t.slice(r,e)),"'\"".includes(t[e])||(f=e);if(!Object.keys(y).length&&l.throwIfEmpty)throw new Error("string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)");return y},t.version="3.0.6",Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-extract-sass-vars",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Parse SASS variables file into a plain object of CSS key-value pairs",
5
5
  "keywords": [
6
6
  "css",
@@ -36,13 +36,12 @@
36
36
  "types": "types/index.d.ts",
37
37
  "scripts": {
38
38
  "build": "rollup -c",
39
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
40
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
39
+ "build:esbuild": "node '../../scripts/esbuild.js'",
40
+ "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
41
+ "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
41
42
  "clean_types": "../../scripts/cleanTypes.js",
42
43
  "dev": "rollup -c --dev",
43
44
  "devunittest": "npm run dev && tap --only -R 'base'",
44
- "esbuild": "node '../../scripts/esbuild.js'",
45
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
46
45
  "format": "npm run lect && npm run prettier && npm run lint",
47
46
  "lect": "lect",
48
47
  "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
@@ -51,17 +50,14 @@
51
50
  "republish": "npm publish || :",
52
51
  "tap": "tap",
53
52
  "pretest": "npm run build",
54
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
53
+ "test": "npm run test:ci && npm run perf",
54
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
55
55
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
56
56
  "tsc": "tsc",
57
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
57
+ "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
58
58
  },
59
59
  "tap": {
60
60
  "check-coverage": false,
61
- "coverage-report": [
62
- "json-summary",
63
- "text"
64
- ],
65
61
  "node-arg": [
66
62
  "--no-warnings",
67
63
  "--experimental-loader",
@@ -81,7 +77,7 @@
81
77
  }
82
78
  },
83
79
  "dependencies": {
84
- "@babel/runtime": "^7.16.0"
80
+ "@babel/runtime": "^7.16.3"
85
81
  },
86
82
  "devDependencies": {
87
83
  "@babel/cli": "^7.16.0",
@@ -92,8 +88,8 @@
92
88
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
93
89
  "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
94
90
  "@babel/plugin-proposal-optional-chaining": "^7.16.0",
95
- "@babel/plugin-transform-runtime": "^7.16.0",
96
- "@babel/preset-env": "^7.16.0",
91
+ "@babel/plugin-transform-runtime": "^7.16.4",
92
+ "@babel/preset-env": "^7.16.4",
97
93
  "@babel/preset-typescript": "^7.16.0",
98
94
  "@babel/register": "^7.16.0",
99
95
  "@istanbuljs/esm-loader-hook": "^0.1.2",
@@ -103,25 +99,25 @@
103
99
  "@rollup/plugin-node-resolve": "^13.0.6",
104
100
  "@rollup/plugin-strip": "^2.1.0",
105
101
  "@rollup/plugin-typescript": "^8.3.0",
106
- "@types/node": "^16.11.6",
102
+ "@types/node": "^16.11.9",
107
103
  "@types/tap": "^15.0.5",
108
- "@typescript-eslint/eslint-plugin": "^5.3.0",
109
- "@typescript-eslint/parser": "^5.3.0",
104
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
105
+ "@typescript-eslint/parser": "^5.4.0",
110
106
  "core-js": "^3.19.1",
111
107
  "cross-env": "^7.0.3",
112
- "eslint": "^8.2.0",
113
- "lect": "^0.18.5",
114
- "rollup": "^2.59.0",
108
+ "eslint": "^8.3.0",
109
+ "lect": "^0.18.6",
110
+ "rollup": "^2.60.0",
115
111
  "rollup-plugin-ascii": "^0.0.3",
116
112
  "rollup-plugin-banner": "^0.2.1",
117
113
  "rollup-plugin-cleanup": "^3.2.1",
118
114
  "rollup-plugin-dts": "^4.0.1",
119
115
  "rollup-plugin-terser": "^7.0.2",
120
- "tap": "^15.0.10",
116
+ "tap": "^15.1.2",
121
117
  "tslib": "^2.3.1",
122
- "typescript": "^4.4.4"
118
+ "typescript": "^4.5.2"
123
119
  },
124
120
  "engines": {
125
- "node": ">=12"
121
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
126
122
  }
127
123
  }