Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-prefixwrap

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-prefixwrap - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

CONTRIBUTING.md

12

CHANGELOG.md

@@ -6,2 +6,14 @@

## 1.2.0 [![Build Status](https://travis-ci.org/dbtedman/postcss-prefixwrap.svg?branch=1.1.4)](https://travis-ci.org/dbtedman/postcss-prefixwrap)
### Features and Improvements
* Add code coverage reporting to ensure all parts of the code are being exercised by the tests.
* Additional test coverage to exercise error condition handling for invalid css.
* Introduction of integration testing suite.
### Bug Fixes
* Keyframe percentages are incorrectly prefixed. [#17](https://github.com/dbtedman/postcss-prefixwrap/issues/17)
## 1.1.3 [![Build Status](https://travis-ci.org/dbtedman/postcss-prefixwrap.svg?branch=1.1.3)](https://travis-ci.org/dbtedman/postcss-prefixwrap)

@@ -8,0 +20,0 @@

20

package.json
{
"name": "postcss-prefixwrap",
"version": "1.1.3",
"version": "1.2.0",
"description": "A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.",
"main": "./src/main.js",
"scripts": {
"test": "npm run test:lint && npm run test:unit",
"test:lint": "eslint --color ./src ./test",
"test:unit": "mocha --colors"
"test": "npm run test:lint && npm run test:unit && npm run test:integration",
"test:lint": "eslint --color ./src ./test-unit",
"test:unit": "nyc --reporter=text --reporter=lcov mocha --colors ./test-unit",
"test:integration": "npm run test:integration:prep && mocha --colors ./test-integration",
"test:integration:prep": "gulp --gulpfile=./test-integration/fixtures/gulpfile.js css"
},

@@ -18,9 +20,13 @@ "authors": [

"dependencies": {
"postcss": "5.2.2"
"postcss": "6.0.14"
},
"devDependencies": {
"eslint": "3.6.1",
"eslint": "4.14.0",
"eslint-config-defaults": "9.0.0",
"mocha": "3.1.0"
"fs-extra": "5.0.0",
"gulp": "3.9.1",
"gulp-postcss": "7.0.1",
"mocha": "4.1.0",
"nyc": "11.4.1"
}
}
# [PostCSS Prefix Wrap](https://github.com/dbtedman/postcss-prefixwrap)
[![Build Status](https://travis-ci.org/dbtedman/postcss-prefixwrap.svg?branch=master)](https://travis-ci.org/dbtedman/postcss-prefixwrap) [![NPM Version](https://img.shields.io/npm/v/postcss-prefixwrap.svg)](https://www.npmjs.com/package/postcss-prefixwrap) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
[![Build Status](https://travis-ci.org/dbtedman/postcss-prefixwrap.svg?branch=master)](https://travis-ci.org/dbtedman/postcss-prefixwrap)
[![NPM Version](https://img.shields.io/npm/v/postcss-prefixwrap.svg)](https://www.npmjs.com/package/postcss-prefixwrap)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
[![Maintainability](https://api.codeclimate.com/v1/badges/fa0627fb4cfdc2a6dd04/maintainability)](https://codeclimate.com/github/dbtedman/postcss-prefixwrap/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/fa0627fb4cfdc2a6dd04/test_coverage)](https://codeclimate.com/github/dbtedman/postcss-prefixwrap/test_coverage)

@@ -14,3 +18,11 @@ A [PostCSS](http://postcss.org) plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.

**[Yarn](https://yarnpkg.com/en/package/postcss-prefixwrap):**
```bash
yarn add --dev postcss-prefixwrap
```
**[NPM](https://www.npmjs.com/package/postcss-prefixwrap):**
```bash
npm install --save-dev postcss-prefixwrap

@@ -74,34 +86,10 @@ ```

## Testing
## Want to lean more?
See [https://travis-ci.org/dbtedman/postcss-prefixwrap](https://travis-ci.org/dbtedman/postcss-prefixwrap) for CI results, run on each commit.
See our [Contributing Guide](CONTRIBUTING.md) for details on how the sausage is made.
### Static Analysis
## Who built it?
Linting support provided by [ESLint](http://eslint.org/) based on rules defined in `.eslintrc.yml`.
```bash
npm run test:lint
```
### Unit Tests
Code is unit tested using [MochaJS](https://mochajs.org).
```bash
npm run test:unit
```
## Releasing
Based on the [NPM Publishing Guide](https://docs.npmjs.com/getting-started/publishing-npm-packages), after updating the current version, run the following command:
```bash
npm publish
```
---
Created [Down Under](https://en.wikipedia.org/wiki/Australia) by [Daniel Tedman](https://danieltedman.com) and [Jeff Teng](https://jafoteng.co) with [contributions from around the web](https://github.com/dbtedman/postcss-prefixwrap/graphs/contributors).
[![Australia](https://danieltedman.com/images/Australia.png)](https://en.wikipedia.org/wiki/Australia)
var postcss = require("postcss");
module.exports = postcss.plugin("postcss-prefixwrap", function (prefixSelector, options) {
(function () {
"use strict";
options = options || {};
function PostCSSPrefixWrap(prefixSelector, options) {
this.anyWhitespaceAtBeginningOrEnd = /(^\s*|\s*$)/g;
this.isPrefixSelector = new RegExp("^\s*" + prefixSelector + ".*$");
this.isRootTag = /^(body|html).*$/;
this.prefixRootTags = options !== undefined && options.hasOwnProperty("prefixRootTags") ? options.prefixRootTags : false;
this.prefixSelector = prefixSelector;
this.isKeyframePercentage = /\d+%/;
}
var isRootTag = /^(body|html).*$/;
var isPrefixSelector = new RegExp("^\s*" + prefixSelector + ".*$");
var anyWhitespaceAtBeginningOrEnd = /(^\s*|\s*$)/g;
PostCSSPrefixWrap.prototype.invalidCSSSelectors = function (cssSelector) {
return cssSelector !== null;
};
return function (css) {
css.walkRules(function (rule) {
// We have found our prefix selector, we just want to leave it as it is already.
if (!rule.selector.match(isPrefixSelector)) {
rule.selector = rule.selector
.split(",")
.map(function (sel) {
// Remove any whitespace characters before or after our selector.
var cleanSelector = sel.replace(anyWhitespaceAtBeginningOrEnd, "");
PostCSSPrefixWrap.prototype.prefixWrapCSSSelector = function (cssSelector) {
var that = this;
// Selector part may just be a blank line, in this case bail out.
if (cleanSelector === "") {
return null;
}
var cleanSelector = cssSelector.replace(that.anyWhitespaceAtBeginningOrEnd, "");
// Anything other than a root tag is always prefixed.
if (!cleanSelector.match(isRootTag)) {
return prefixSelector + " " + cleanSelector;
}
if (cleanSelector === "") {
return null;
}
// Handle special case where root tags should be converted into classes rather than being replaced.
if (options.prefixRootTags) {
return prefixSelector + " ." + cleanSelector;
}
if (cleanSelector.match(that.isKeyframePercentage)) {
return cleanSelector;
}
// HTML and Body elements cannot be contained within our container so lets extract their styles.
return cleanSelector.replace(/^(body|html)/, prefixSelector);
})
.filter(function (sel) {
return sel !== null;
})
.join(", ");
}
});
// Anything other than a root tag is always prefixed.
if (!cleanSelector.match(that.isRootTag)) {
return that.prefixSelector + " " + cleanSelector;
}
// Handle special case where root tags should be converted into classes rather than being replaced.
if (that.prefixRootTags) {
return that.prefixSelector + " ." + cleanSelector;
}
// HTML and Body elements cannot be contained within our container so lets extract their styles.
return cleanSelector.replace(/^(body|html)/, that.prefixSelector);
};
});
PostCSSPrefixWrap.prototype.prefixWrapCSSRule = function (cssRule) {
var that = this;
// We have found our prefix selector, we just want to leave it as it is already.
if (!cssRule.selector.match(that.isPrefixSelector)) {
cssRule.selector = cssRule.selector
.split(",")
.map(function (cssSelector) {
return that.prefixWrapCSSSelector(cssSelector);
})
.filter(that.invalidCSSSelectors)
.join(", ");
}
};
PostCSSPrefixWrap.prototype.asPlugin = function () {
var that = this;
return function (css) {
css.walkRules(function (cssRule) {
that.prefixWrapCSSRule(cssRule);
});
};
};
module.exports = postcss.plugin("postcss-prefixwrap", function (prefixSelector, options) {
return new PostCSSPrefixWrap(prefixSelector, options).asPlugin();
});
}());

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc