string-extract-sass-vars 3.0.7 → 3.0.10
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 +4 -1
- package/dist/string-extract-sass-vars.esm.js +3 -103
- package/dist/string-extract-sass-vars.umd.js +3 -2
- package/examples/_quickTake.js +1 -0
- package/examples/opts-cb.js +2 -1
- package/examples/throw-if-empty.js +1 -0
- package/package.json +23 -74
- package/types/index.d.ts +0 -0
- package/examples/api.json +0 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 2.1.0
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
import { strict as assert } from "assert";
|
|
41
|
+
|
|
41
42
|
import { extractVars } from "string-extract-sass-vars";
|
|
42
43
|
|
|
43
44
|
assert.deepEqual(
|
|
@@ -70,7 +71,7 @@ $customValue3: 10;`),
|
|
|
70
71
|
|
|
71
72
|
## Documentation
|
|
72
73
|
|
|
73
|
-
Please [visit codsen.com](https://codsen.com/os/string-extract-sass-vars/) for a full description of the API
|
|
74
|
+
Please [visit codsen.com](https://codsen.com/os/string-extract-sass-vars/) for a full description of the API.
|
|
74
75
|
|
|
75
76
|
## Contributing
|
|
76
77
|
|
|
@@ -82,4 +83,6 @@ MIT License
|
|
|
82
83
|
|
|
83
84
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
84
85
|
|
|
86
|
+
|
|
85
87
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
88
|
+
|
|
@@ -1,111 +1,11 @@
|
|
|
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.10
|
|
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
|
|
11
|
-
|
|
12
|
-
const version = version$1;
|
|
13
|
-
const BACKSLASH = "\u005C";
|
|
14
|
-
const defaults = {
|
|
15
|
-
throwIfEmpty: false,
|
|
16
|
-
cb: null,
|
|
17
|
-
};
|
|
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, ...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})`);
|
|
28
|
-
}
|
|
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
|
-
}
|
|
104
|
-
}
|
|
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)`);
|
|
107
|
-
}
|
|
108
|
-
return res;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { defaults, extractVars, version };
|
|
10
|
+
var h="3.0.10";var v=h,S="\\",p={throwIfEmpty:!1,cb:null};function w(t,n){if(typeof t!="string")return{};if(n&&typeof n!="object")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})`);let o={...p,...n};if(o.cb&&typeof o.cb!="function")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})`);let g=t.length,$=null,l=null,a=null,i=null,u=null,c=null,s=!1,r=!1,m=!1,b={};for(let e=0;e<g;e++)!s&&u&&t[e]===u&&t[e-1]!==S?u=null:!u&&!s&&t[e-1]!==S&&`'"`.includes(t[e])&&(u=t[e]),r&&`\r
|
|
11
|
+
`.includes(t[e])&&(r=!1),!s&&t[e]==="/"&&t[e+1]==="/"&&(r=!0),m&&t[e-2]==="*"&&t[e-1]==="/"&&(m=!1),!s&&t[e]==="/"&&t[e+1]==="*"&&(m=!0),s=r||m,!s&&t[e]==="$"&&$===null&&($=e+1),!s&&l!==null&&!u&&t[e]===";"&&(i=t.slice(`"'`.includes(t[l])?l+1:l,(c||0)+1),/^-?\d*\.?\d*$/.test(i)&&(i=+i),b[a]=o.cb?o.cb(i):i,$=null,l=null,a=null,i=null),!s&&a!==null&&t[e]&&t[e].trim().length&&l===null&&(l=e),!s&&!a&&$!==null&&t[e]===":"&&!u&&(a=t.slice($,e)),`'"`.includes(t[e])||(c=e);if(!Object.keys(b).length&&o.throwIfEmpty)throw new Error("string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)");return b}export{p as defaults,w as extractVars,v as version};
|
|
@@ -1,10 +1,11 @@
|
|
|
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.10
|
|
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
|
-
|
|
10
|
+
var stringExtractSassVars=(()=>{var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var y=(e,t,s)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,S=(e,t)=>{for(var s in t||(t={}))p.call(t,s)&&y(e,s,t[s]);if(f)for(var s of f(t))N.call(t,s)&&y(e,s,t[s]);return e};var D=e=>c(e,"__esModule",{value:!0});var C=(e,t)=>{for(var s in t)c(e,s,{get:t[s],enumerable:!0})},A=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of V(t))!p.call(e,l)&&(s||l!=="default")&&c(e,l,{get:()=>t[l],enumerable:!(r=E(t,l))||r.enumerable});return e};var x=(e=>(t,s)=>e&&e.get(t)||(s=A(D({}),t,1),e&&e.set(t,s),s))(typeof WeakMap!="undefined"?new WeakMap:0);var j={};C(j,{defaults:()=>w,extractVars:()=>J,version:()=>k});var d="3.0.10";var k=d,v="\\",w={throwIfEmpty:!1,cb:null};function J(e,t){var T;if(typeof e!="string")return{};if(t&&typeof t!="object")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(t,null,4)} (type ${typeof t})`);let s=S(S({},w),t);if(s.cb&&typeof s.cb!="function")throw new Error(`string-extract-sass-vars: [THROW_ID_02] opts.cb should be function! But it was given as ${JSON.stringify(t,null,4)} (type ${typeof t})`);let r=e.length,l=null,u=null,a=null,o=null,$=null,g=null,i=!1,m=!1,b=!1,h={};for(let n=0;n<r;n++)!i&&$&&e[n]===$&&e[n-1]!==v?$=null:!$&&!i&&e[n-1]!==v&&`'"`.includes(e[n])&&($=e[n]),m&&`\r
|
|
11
|
+
`.includes(e[n])&&(m=!1),!i&&e[n]==="/"&&e[n+1]==="/"&&(m=!0),b&&e[n-2]==="*"&&e[n-1]==="/"&&(b=!1),!i&&e[n]==="/"&&e[n+1]==="*"&&(b=!0),i=m||b,!i&&e[n]==="$"&&l===null&&(l=n+1),!i&&u!==null&&!$&&e[n]===";"&&(o=e.slice(`"'`.includes(e[u])?u+1:u,(g||0)+1),/^-?\d*\.?\d*$/.test(o)&&(o=+o),h[a]=s.cb?s.cb(o):o,l=null,u=null,a=null,o=null),!i&&a!==null&&e[n]&&e[n].trim().length&&u===null&&(u=n),!i&&!a&&l!==null&&e[n]===":"&&!$&&(a=e.slice(l,n)),`'"`.includes(e[n])||(g=n);if(!Object.keys(h).length&&s.throwIfEmpty)throw new Error("string-extract-sass-vars: [THROW_ID_03] no keys extracted! (setting opts.originalOpts)");return h}return x(j);})();
|
package/examples/_quickTake.js
CHANGED
package/examples/opts-cb.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Convert 3-digit color hex codes to 6-digit
|
|
2
2
|
|
|
3
3
|
import { strict as assert } from "assert";
|
|
4
|
+
import { conv } from "color-shorthand-hex-to-six-digit";
|
|
5
|
+
|
|
4
6
|
import { extractVars } from "../dist/string-extract-sass-vars.esm.js";
|
|
5
7
|
// import "color-shorthand-hex-to-six-digit" to convert three-digit colour hex
|
|
6
8
|
// codes to six-digit:
|
|
7
|
-
import { conv } from "../../color-shorthand-hex-to-six-digit/dist/color-shorthand-hex-to-six-digit.esm.js";
|
|
8
9
|
|
|
9
10
|
assert.deepEqual(
|
|
10
11
|
extractVars("$blue: #2af;", {
|
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.10",
|
|
4
4
|
"description": "Parse SASS variables file into a plain object of CSS key-value pairs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -35,35 +35,28 @@
|
|
|
35
35
|
},
|
|
36
36
|
"types": "types/index.d.ts",
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"republish": "npm publish || :",
|
|
51
|
-
"tap": "tap",
|
|
52
|
-
"pretest": "npm run build",
|
|
53
|
-
"test": "npm run test:ci && npm run perf",
|
|
54
|
-
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
55
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
56
|
-
"tsc": "tsc",
|
|
57
|
-
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
38
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
39
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
40
|
+
"dts": "rollup -c",
|
|
41
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
42
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
43
|
+
"letspublish": "yarn publish || :",
|
|
44
|
+
"lint": "eslint . --fix",
|
|
45
|
+
"perf": "node perf/check.js",
|
|
46
|
+
"prepare": "echo 'ready'",
|
|
47
|
+
"pretest": "yarn run lect && yarn run build",
|
|
48
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
49
|
+
"unit": "uvu test"
|
|
58
50
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"c8": {
|
|
55
|
+
"check-coverage": true,
|
|
56
|
+
"exclude": [
|
|
57
|
+
"**/test/**/*.*"
|
|
65
58
|
],
|
|
66
|
-
"
|
|
59
|
+
"lines": 100
|
|
67
60
|
},
|
|
68
61
|
"lect": {
|
|
69
62
|
"licence": {
|
|
@@ -71,53 +64,9 @@
|
|
|
71
64
|
""
|
|
72
65
|
]
|
|
73
66
|
},
|
|
74
|
-
"
|
|
75
|
-
"various": {
|
|
76
|
-
"devDependencies": []
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"@babel/runtime": "^7.16.3"
|
|
67
|
+
"various": {}
|
|
81
68
|
},
|
|
82
69
|
"devDependencies": {
|
|
83
|
-
"
|
|
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",
|
|
95
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
96
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
97
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
98
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
99
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
100
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
101
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
102
|
-
"@types/node": "^16.11.10",
|
|
103
|
-
"@types/tap": "^15.0.5",
|
|
104
|
-
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
105
|
-
"@typescript-eslint/parser": "^5.5.0",
|
|
106
|
-
"core-js": "^3.19.2",
|
|
107
|
-
"cross-env": "^7.0.3",
|
|
108
|
-
"eslint": "^8.3.0",
|
|
109
|
-
"lect": "^0.18.7",
|
|
110
|
-
"rollup": "^2.60.1",
|
|
111
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
112
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
113
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
114
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
115
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
116
|
-
"tap": "^15.1.5",
|
|
117
|
-
"tslib": "^2.3.1",
|
|
118
|
-
"typescript": "^4.5.2"
|
|
119
|
-
},
|
|
120
|
-
"engines": {
|
|
121
|
-
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
70
|
+
"color-shorthand-hex-to-six-digit": "^4.0.10"
|
|
122
71
|
}
|
|
123
72
|
}
|
package/types/index.d.ts
CHANGED
|
File without changes
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { extractVars } from \"string-extract-sass-vars\";\n\nassert.deepEqual(\n extractVars(`// all variables are here!!!\n// ------------------------------------------\n$red: #ff6565; // this is red\n// $green: #63ffbd; // no green here\n$yellow: #ffff65; // this is yellow\n$blue: #08f0fd; // this is blue\n$fontfamily: Helvetica, sans-serif;\n$border: 1px solid #dedede;\n$borderroundedness: 3px;\n$customValue1: tralala;\n$customValue2: tralala;\n// don't mind this comment about #ff6565;\n$customValue3: 10;`),\n {\n red: \"#ff6565\",\n yellow: \"#ffff65\",\n blue: \"#08f0fd\",\n fontfamily: \"Helvetica, sans-serif\",\n border: \"1px solid #dedede\",\n borderroundedness: \"3px\",\n customValue1: \"tralala\",\n customValue2: \"tralala\",\n customValue3: 10,\n }\n);"},"opts-cb.js":{"title":"Convert 3-digit color hex codes to 6-digit","content":"import { strict as assert } from \"assert\";\nimport { extractVars } from \"string-extract-sass-vars\";\n// import \"color-shorthand-hex-to-six-digit\" to convert three-digit colour hex\n// codes to six-digit:\nimport { conv } from \"color-shorthand-hex-to-six-digit\";\n\nassert.deepEqual(\n extractVars(\"$blue: #2af;\", {\n throwIfEmpty: true,\n cb: (val) => conv(val), // converts hex codes only, bypasses the rest\n }),\n { blue: \"#22aaff\" }\n);"},"throw-if-empty.js":{"title":"Raises alarm if variables file has been wiped","content":"import { strict as assert } from \"assert\";\nimport { extractVars } from \"string-extract-sass-vars\";\n\nassert.throws(() =>\n extractVars(\"\", {\n throwIfEmpty: true,\n })\n);"}}
|