string-extract-sass-vars 3.0.2 → 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.
package/CHANGELOG.md CHANGED
@@ -3,12 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 3.0.1 (2021-09-13)
7
-
8
- ### Bug Fixes
9
-
10
- - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
11
-
12
6
  ## 3.0.0 (2021-09-09)
13
7
 
14
8
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-%YEAR% Roy Revelt and other contributors
3
+ Copyright (c) 2010-2021 Roy Revelt and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -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.2
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.2";
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.2
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.2",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})}));
@@ -4,7 +4,7 @@ import { strict as assert } from "assert";
4
4
  import { extractVars } from "../dist/string-extract-sass-vars.esm.js";
5
5
  // import "color-shorthand-hex-to-six-digit" to convert three-digit colour hex
6
6
  // codes to six-digit:
7
- import { conv } from "../../color-shorthand-hex-to-six-digit";
7
+ import { conv } from "../../color-shorthand-hex-to-six-digit/dist/color-shorthand-hex-to-six-digit.esm.js";
8
8
 
9
9
  assert.deepEqual(
10
10
  extractVars("$blue: #2af;", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-extract-sass-vars",
3
- "version": "3.0.2",
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,9 +36,10 @@
36
36
  "types": "types/index.d.ts",
37
37
  "scripts": {
38
38
  "build": "rollup -c",
39
- "esbuild": "node '../../scripts/esbuild.js'",
40
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
41
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
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",
42
+ "clean_types": "../../scripts/cleanTypes.js",
42
43
  "dev": "rollup -c --dev",
43
44
  "devunittest": "npm run dev && tap --only -R 'base'",
44
45
  "format": "npm run lect && npm run prettier && npm run lint",
@@ -48,20 +49,15 @@
48
49
  "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
49
50
  "republish": "npm publish || :",
50
51
  "tap": "tap",
51
- "tsc": "tsc",
52
52
  "pretest": "npm run build",
53
- "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",
54
55
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
55
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf",
56
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
57
- "clean_types": "../../scripts/cleanTypes.js"
56
+ "tsc": "tsc",
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,47 +77,47 @@
81
77
  }
82
78
  },
83
79
  "dependencies": {
84
- "@babel/runtime": "^7.15.4"
80
+ "@babel/runtime": "^7.16.3"
85
81
  },
86
82
  "devDependencies": {
87
- "@babel/cli": "^7.15.4",
88
- "@babel/core": "^7.15.5",
89
- "@babel/node": "^7.15.4",
90
- "@babel/plugin-external-helpers": "^7.14.5",
91
- "@babel/plugin-proposal-class-properties": "^7.14.5",
92
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
93
- "@babel/plugin-proposal-object-rest-spread": "^7.15.6",
94
- "@babel/plugin-proposal-optional-chaining": "^7.14.5",
95
- "@babel/plugin-transform-runtime": "^7.15.0",
96
- "@babel/preset-env": "^7.15.6",
97
- "@babel/preset-typescript": "^7.15.0",
98
- "@babel/register": "^7.15.3",
83
+ "@babel/cli": "^7.16.0",
84
+ "@babel/core": "^7.16.0",
85
+ "@babel/node": "^7.16.0",
86
+ "@babel/plugin-external-helpers": "^7.16.0",
87
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
88
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
89
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
90
+ "@babel/plugin-proposal-optional-chaining": "^7.16.0",
91
+ "@babel/plugin-transform-runtime": "^7.16.4",
92
+ "@babel/preset-env": "^7.16.4",
93
+ "@babel/preset-typescript": "^7.16.0",
94
+ "@babel/register": "^7.16.0",
99
95
  "@istanbuljs/esm-loader-hook": "^0.1.2",
100
96
  "@rollup/plugin-babel": "^5.3.0",
101
- "@rollup/plugin-commonjs": "^20.0.0",
97
+ "@rollup/plugin-commonjs": "^21.0.1",
102
98
  "@rollup/plugin-json": "^4.1.0",
103
- "@rollup/plugin-node-resolve": "^13.0.4",
99
+ "@rollup/plugin-node-resolve": "^13.0.6",
104
100
  "@rollup/plugin-strip": "^2.1.0",
105
- "@rollup/plugin-typescript": "^8.2.5",
106
- "@types/node": "^16.9.1",
101
+ "@rollup/plugin-typescript": "^8.3.0",
102
+ "@types/node": "^16.11.9",
107
103
  "@types/tap": "^15.0.5",
108
- "@typescript-eslint/eslint-plugin": "^4.31.0",
109
- "@typescript-eslint/parser": "^4.31.0",
110
- "core-js": "^3.17.3",
104
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
105
+ "@typescript-eslint/parser": "^5.4.0",
106
+ "core-js": "^3.19.1",
111
107
  "cross-env": "^7.0.3",
112
- "eslint": "^7.32.0",
113
- "lect": "^0.18.2",
114
- "rollup": "^2.56.3",
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
- "rollup-plugin-dts": "^4.0.0",
114
+ "rollup-plugin-dts": "^4.0.1",
119
115
  "rollup-plugin-terser": "^7.0.2",
120
- "tap": "^15.0.9",
116
+ "tap": "^15.1.2",
121
117
  "tslib": "^2.3.1",
122
- "typescript": "^4.4.3"
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
  }