postcss-nested-vars
Advanced tools
| import * as postcss from 'postcss'; | ||
| declare const PostCssNestedVars: postcss.Plugin<PostCssNestedVars.Options>; | ||
| declare namespace PostCssNestedVars { | ||
| interface Options { | ||
| /** | ||
| * Global variables that can be referenced from any context. | ||
| */ | ||
| globals?: { | ||
| [key: string]: any; | ||
| }; | ||
| /** | ||
| * If a variable cannot be resolved, this specifies how to handle it. | ||
| * Possible values: error, warn, silent. `warn` and `silent` modes will | ||
| * preserve the original values (e.g., `$foo` will remain `$foo`). | ||
| */ | ||
| logLevel?: string; | ||
| } | ||
| } | ||
| export = PostCssNestedVars; |
| "use strict"; | ||
| const postcss = require("postcss"); | ||
| const plugin = 'postcss-nested-vars'; | ||
| const PostCssNestedVars = postcss.plugin(plugin, (options = {}) => { | ||
| options.logLevel = options.logLevel || 'error'; | ||
| const errorContext = { plugin }; | ||
| const specialSearchValue = /\$\(([\w\d-_]+)\)/g; | ||
| const logMap = { | ||
| error(message, node) { | ||
| throw node.error(message, errorContext); | ||
| }, | ||
| warn(message, node, result) { | ||
| node.warn(result, message); | ||
| }, | ||
| silent() { | ||
| // noop | ||
| } | ||
| }; | ||
| const log = logMap[options.logLevel]; | ||
| if (!log) { | ||
| throw new Error(`Invalid logLevel: ${options.logLevel}`); | ||
| } | ||
| const globals = {}; | ||
| if (options.globals) { | ||
| Object.keys(options.globals).forEach(key => { | ||
| globals[key] = [options.globals[key]]; | ||
| }); | ||
| } | ||
| return (root, result) => { | ||
| walk(root, result, globals); | ||
| }; | ||
| function walk(container, result, vars) { | ||
| const containerVars = {}; | ||
| container.walk(node => { | ||
| if (node.type === 'rule') { | ||
| resolveContainer(node, 'selector'); | ||
| return; | ||
| } | ||
| if (node.type === 'atrule') { | ||
| resolveContainer(node, 'params'); | ||
| return; | ||
| } | ||
| if (node.type === 'decl') { | ||
| resolveDeclaration(node); | ||
| return; | ||
| } | ||
| }); | ||
| Object.keys(containerVars).forEach(varName => { | ||
| vars[varName].pop(); | ||
| }); | ||
| function resolveContainer(container2, prop) { | ||
| if (container2[prop].indexOf('$(') !== -1) { | ||
| replaceAllVars(container2, prop, specialSearchValue); | ||
| } | ||
| walk(container2, result, vars); | ||
| } | ||
| function resolveDeclaration(decl) { | ||
| if (decl.prop.indexOf('$(') !== -1) { | ||
| replaceAllVars(decl, 'prop', specialSearchValue); | ||
| } | ||
| if (/^\$(?!\()/.test(decl.prop)) { | ||
| const m = decl.prop.match(/^\$([\w\d-_]+)$/); | ||
| const varName = m && m[1]; | ||
| const stack = vars[varName]; | ||
| if (!stack) { | ||
| vars[varName] = []; | ||
| } | ||
| if (!containerVars[varName]) { | ||
| containerVars[varName] = true; | ||
| vars[varName].push(decl.value); | ||
| } | ||
| else { | ||
| stack[stack.length - 1] = decl.value; | ||
| } | ||
| decl.remove(); | ||
| return; | ||
| } | ||
| if (decl.value.indexOf('$') !== -1) { | ||
| replaceAllVars(decl, 'value', /\$([\w\d-_]+)/g); | ||
| } | ||
| } | ||
| function replaceAllVars(obj, prop, searchValue) { | ||
| obj[prop] = obj[prop].replace(searchValue, (m, varName) => { | ||
| const stack = vars[varName]; | ||
| if (!stack || !stack.length) { | ||
| log(`Undefined variable: ${varName}`, obj, result); | ||
| return `$${varName}`; | ||
| } | ||
| return stack[stack.length - 1]; | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| module.exports = PostCssNestedVars; | ||
| //# sourceMappingURL=plugin.js.map |
+3
-0
@@ -0,1 +1,4 @@ | ||
| ## 1.0.0 | ||
| - Upgrade to PostCSS 6. | ||
| ## 0.0.2 | ||
@@ -2,0 +5,0 @@ - Fix code coloring on npm readme. |
+47
-25
| { | ||
| "name": "postcss-nested-vars", | ||
| "version": "0.0.2", | ||
| "version": "1.0.0", | ||
| "description": "PostCSS plugin for nested variables.", | ||
| "main": "dist/lib/plugin.js", | ||
| "main": "dist/plugin.js", | ||
| "types": "dist/plugin.d.ts", | ||
| "scripts": { | ||
| "prepublish": "gulp && gulp copy && npm run babelify", | ||
| "babelify": "babel build/lib --out-dir dist/lib", | ||
| "test": "gulp && npm run cover && npm run check-coverage", | ||
| "cover": "isparta cover node_modules/mocha/bin/_mocha -i build/lib/plugin.js", | ||
| "check-coverage": "istanbul check-coverage", | ||
| "watch": "sh scripts/watch" | ||
| "clean": "rimraf coverage dist *.log", | ||
| "codecov": "codecov -f coverage/lcov.info", | ||
| "compile": "tsc", | ||
| "compile:watch": "tsc --watch", | ||
| "prepublish": "npm test", | ||
| "pretest": "npm run tslint && npm run clean && npm run compile", | ||
| "test": "nyc ava", | ||
| "test:watch": "ava --watch", | ||
| "tslint": "tslint --project tsconfig.json", | ||
| "watch": "npm run test:watch" | ||
| }, | ||
| "ava": { | ||
| "files": [ | ||
| "dist/**/*.spec.js" | ||
| ], | ||
| "source": [ | ||
| "dist/**/*.js" | ||
| ] | ||
| }, | ||
| "nyc": { | ||
| "lines": 100, | ||
| "statements": 100, | ||
| "functions": 100, | ||
| "branches": 100, | ||
| "include": [ | ||
| "dist/**/*.js" | ||
| ], | ||
| "exclude": [ | ||
| "dist/**/*.spec.js" | ||
| ], | ||
| "reporter": [ | ||
| "lcov", | ||
| "text" | ||
| ], | ||
| "cache": true, | ||
| "all": true, | ||
| "check-coverage": true | ||
| }, | ||
| "repository": { | ||
@@ -33,22 +65,12 @@ "type": "git", | ||
| "dependencies": { | ||
| "postcss": "^5.0.5" | ||
| "postcss": "^6.0.14" | ||
| }, | ||
| "devDependencies": { | ||
| "babel": "^5.8.23", | ||
| "babel-core": "^5.8.23", | ||
| "babel-eslint": "^4.1.1", | ||
| "chai": "^3.2.0", | ||
| "del": "^1.2.1", | ||
| "eslint": "^1.3.1", | ||
| "event-stream": "^3.3.1", | ||
| "gulp": "^3.9.0", | ||
| "gulp-eslint": "^1.0.0", | ||
| "gulp-filter": "^3.0.1", | ||
| "gulp-plumber": "^1.0.1", | ||
| "gulp-tslint": "^3.2.0", | ||
| "gulp-typescript": "^2.8.1", | ||
| "isparta": "3.0.3", | ||
| "istanbul": "^0.3.19", | ||
| "mocha": "^2.3.0" | ||
| "@types/node": "^8.0.47", | ||
| "ava": "^0.23.0", | ||
| "nyc": "^11.3.0", | ||
| "rimraf": "^2.6.2", | ||
| "tslint": "^5.8.0", | ||
| "typescript": "^2.6.1" | ||
| } | ||
| } |
+14
-14
@@ -9,4 +9,5 @@ # postcss-nested-vars | ||
| [](https://www.npmjs.org/package/postcss-nested-vars) | ||
| [](https://travis-ci.org/jedmao/postcss-nested-vars) | ||
| [](https://ci.appveyor.com/project/jedmao/postcss-nested-vars) | ||
| [](https://travis-ci.org/jedmao/postcss-nested-vars) | ||
| [](https://codecov.io/gh/jedmao/postcss-nested-vars) | ||
| [](https://gemnasium.com/github.com/jedmao/postcss-nested-vars) | ||
@@ -85,6 +86,3 @@ [](https://nodei.co/npm/postcss-nested-vars/) | ||
| ```js | ||
| postcss([ | ||
| require('postcss-nested-vars')(/* options */), | ||
| // more plugins... | ||
| ]) | ||
| postcss([ require('postcss-nested-vars')(/* options */) ]); | ||
| ``` | ||
@@ -95,9 +93,5 @@ | ||
| ```ts | ||
| ///<reference path="node_modules/postcss-nested-vars/.d.ts" /> | ||
| import postcssNestedVars from 'postcss-nested-vars'; | ||
| import * as postcssNestedVars from 'postcss-nested-vars'; | ||
| postcss([ | ||
| postcssNestedVars(/* options */), | ||
| // more plugins... | ||
| ]) | ||
| postcss([ postcssNestedVars(/* options */) ]); | ||
| ``` | ||
@@ -135,8 +129,14 @@ | ||
| For much faster development cycles, run the following command: | ||
| For much faster development cycles, run the following commands in 2 separate processes: | ||
| ``` | ||
| $ npm run build:watch | ||
| ``` | ||
| Compiles TypeScript source into the `./dist` folder and watches for changes. | ||
| ``` | ||
| $ npm run watch | ||
| ``` | ||
| This will build scripts, run tests and watch for changes. | ||
| Runs the tests in the `./dist` folder and watches for changes. |
-4
| declare module 'postcss-nested-vars' { | ||
| import plugin from 'dist/lib/plugin'; | ||
| export default plugin; | ||
| } |
| /// <reference path="../../node_modules/postcss/postcss.d.ts" /> | ||
| import postcss from 'postcss'; | ||
| declare var _default: postcss.Plugin<PostCssNestedVars.Options>; | ||
| export default _default; | ||
| export declare module PostCssNestedVars { | ||
| interface Options { | ||
| /** | ||
| * Global variables that can be referenced from any context. | ||
| */ | ||
| globals?: Object; | ||
| /** | ||
| * If a variable cannot be resolved, this specifies how to handle it. | ||
| * Possible values: error, warn, silent. `warn` and `silent` modes will | ||
| * preserve the original values (e.g., `$foo` will remain `$foo`). | ||
| */ | ||
| logLevel?: string; | ||
| } | ||
| } |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { | ||
| value: true | ||
| }); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
| var _postcss = require('postcss'); | ||
| var _postcss2 = _interopRequireDefault(_postcss); | ||
| var plugin = 'postcss-nested-vars'; | ||
| exports['default'] = _postcss2['default'].plugin(plugin, function () { | ||
| var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
| options.logLevel = options.logLevel || 'error'; | ||
| var errorContext = { plugin: plugin }; | ||
| var specialSearchValue = /\$\(([\w\d-_]+)\)/g; | ||
| var log = ({ | ||
| error: function error(message, node) { | ||
| throw node.error(message, errorContext); | ||
| }, | ||
| warn: function warn(message, node, result) { | ||
| node.warn(result, message); | ||
| }, | ||
| silent: function silent() { | ||
| // noop | ||
| } | ||
| })[options.logLevel]; | ||
| if (!log) { | ||
| throw new Error('Invalid logLevel: ' + options.logLevel); | ||
| } | ||
| var globals = {}; | ||
| if (options.globals) { | ||
| Object.keys(options.globals).forEach(function (key) { | ||
| globals[key] = [options.globals[key]]; | ||
| }); | ||
| } | ||
| return function (root, result) { | ||
| walk(root, result, globals); | ||
| }; | ||
| function walk(container, result, vars) { | ||
| var containerVars = {}; | ||
| container.walk(function (node) { | ||
| if (node.type === 'rule') { | ||
| resolveContainer(node, 'selector'); | ||
| return; | ||
| } | ||
| if (node.type === 'atrule') { | ||
| resolveContainer(node, 'params'); | ||
| return; | ||
| } | ||
| if (node.type === 'decl') { | ||
| resolveDeclaration(node); | ||
| return; | ||
| } | ||
| }); | ||
| Object.keys(containerVars).forEach(function (varName) { | ||
| vars[varName].pop(); | ||
| }); | ||
| function resolveContainer(container2, prop) { | ||
| if (container2[prop].indexOf('$(') !== -1) { | ||
| replaceAllVars(container2, prop, specialSearchValue); | ||
| } | ||
| walk(container2, result, vars); | ||
| } | ||
| function resolveDeclaration(decl) { | ||
| if (decl.prop.indexOf('$(') !== -1) { | ||
| replaceAllVars(decl, 'prop', specialSearchValue); | ||
| } | ||
| if (/^\$(?!\()/.test(decl.prop)) { | ||
| var m = decl.prop.match(/^\$([\w\d-_]+)$/); | ||
| var varName = m && m[1]; | ||
| var stack = vars[varName]; | ||
| if (!stack) { | ||
| vars[varName] = []; | ||
| } | ||
| if (!containerVars[varName]) { | ||
| containerVars[varName] = true; | ||
| vars[varName].push(decl.value); | ||
| } else { | ||
| stack[stack.length - 1] = decl.value; | ||
| } | ||
| decl.remove(); | ||
| return; | ||
| } | ||
| if (decl.value.indexOf('$') !== -1) { | ||
| replaceAllVars(decl, 'value', /\$([\w\d-_]+)/g); | ||
| } | ||
| } | ||
| function replaceAllVars(obj, prop, searchValue) { | ||
| obj[prop] = obj[prop].replace(searchValue, function (m, varName) { | ||
| var stack = vars[varName]; | ||
| if (!stack || !stack.length) { | ||
| log('Undefined variable: ' + varName, obj, result); | ||
| return '$' + varName; | ||
| } | ||
| return stack[stack.length - 1]; | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| module.exports = exports['default']; |
Sorry, the diff of this file is too big to display
| /// <reference path="node/node.d.ts" /> | ||
| /// <reference path="../node_modules/postcss/postcss.d.ts" /> | ||
| /// <reference path="mocha/mocha.d.ts" /> | ||
| /// <reference path="chai/chai.d.ts" /> | ||
| /// <reference path="sinon-chai/sinon-chai.d.ts" /> |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Network access
Supply chain riskThis module accesses the network.
Found 3 instances
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
6
-62.5%0
-100%0
-100%1
-83.33%10060
-89.65%6
-33.33%113
-94.54%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated