string-extract-sass-vars 3.0.3 → 3.0.7
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 +0 -20
- package/LICENSE +1 -1
- package/dist/string-extract-sass-vars.esm.js +89 -70
- package/dist/string-extract-sass-vars.umd.js +2 -2
- package/package.json +21 -25
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +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.3 (2021-11-02)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
-
|
|
16
|
-
### BREAKING CHANGES
|
|
17
|
-
|
|
18
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
-
|
|
20
|
-
## 3.0.1 (2021-09-13)
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
25
|
-
|
|
26
6
|
## 3.0.0 (2021-09-09)
|
|
27
7
|
|
|
28
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
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.
|
|
4
|
+
* @version 3.0.7
|
|
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.
|
|
10
|
+
var version$1 = "3.0.7";
|
|
11
11
|
|
|
12
12
|
const version = version$1;
|
|
13
13
|
const BACKSLASH = "\u005C";
|
|
14
14
|
const defaults = {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
throwIfEmpty: false,
|
|
16
|
+
cb: null,
|
|
17
17
|
};
|
|
18
18
|
function extractVars(str, originalOpts) {
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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 (
|
|
56
|
-
|
|
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
|
-
|
|
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.
|
|
4
|
+
* @version 3.0.7
|
|
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.
|
|
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.7",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.
|
|
3
|
+
"version": "3.0.7",
|
|
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
|
-
"
|
|
40
|
-
"
|
|
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
|
|
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 --
|
|
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.
|
|
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.
|
|
96
|
-
"@babel/preset-env": "^7.16.
|
|
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.
|
|
102
|
+
"@types/node": "^16.11.10",
|
|
107
103
|
"@types/tap": "^15.0.5",
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
109
|
-
"@typescript-eslint/parser": "^5.
|
|
110
|
-
"core-js": "^3.19.
|
|
104
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
105
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
106
|
+
"core-js": "^3.19.2",
|
|
111
107
|
"cross-env": "^7.0.3",
|
|
112
|
-
"eslint": "^8.
|
|
113
|
-
"lect": "^0.18.
|
|
114
|
-
"rollup": "^2.
|
|
108
|
+
"eslint": "^8.3.0",
|
|
109
|
+
"lect": "^0.18.7",
|
|
110
|
+
"rollup": "^2.60.1",
|
|
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.
|
|
114
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
119
115
|
"rollup-plugin-terser": "^7.0.2",
|
|
120
|
-
"tap": "^15.
|
|
116
|
+
"tap": "^15.1.5",
|
|
121
117
|
"tslib": "^2.3.1",
|
|
122
|
-
"typescript": "^4.
|
|
118
|
+
"typescript": "^4.5.2"
|
|
123
119
|
},
|
|
124
120
|
"engines": {
|
|
125
|
-
"node": ">=
|
|
121
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
126
122
|
}
|
|
127
123
|
}
|