Skip to content

Use PostCSS 6 and Node 4 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
language: node_js
node_js:
- 4
72 changes: 36 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var postcss = require("postcss");
"use strict";

const postcss = require("postcss");

/**
* font variant convertion map
*
* @type {Object}
*/
var fontVariantProperties = {
const fontVariantProperties = {
"font-variant-ligatures": {
"common-ligatures": "\"liga\", \"clig\"",
"no-common-ligatures": "\"liga\", \"clig off\"",
Expand Down Expand Up @@ -55,9 +57,9 @@ var fontVariantProperties = {
}

// The `font-variant` property is a shorthand for all the others.
for (var prop in fontVariantProperties) {
var keys = fontVariantProperties[prop]
for (var key in keys) {
for (let prop in fontVariantProperties) {
let keys = fontVariantProperties[prop]
for (let key in keys) {
if (!(key in fontVariantProperties["font-variant"])) {
fontVariantProperties["font-variant"][key] = keys[key]
}
Expand All @@ -67,8 +69,8 @@ for (var prop in fontVariantProperties) {
// Find font-feature-settings declaration before given declaration,
// create if does not exist
function getFontFeatureSettingsPrevTo(decl) {
var fontFeatureSettings = null;
decl.parent.walkDecls(function(decl) {
let fontFeatureSettings = null;
decl.parent.walkDecls((decl) => {
if (decl.prop === "font-feature-settings") {
fontFeatureSettings = decl;
}
Expand All @@ -86,36 +88,34 @@ function getFontFeatureSettingsPrevTo(decl) {
/**
* Expose the font-variant plugin.
*/
module.exports = postcss.plugin("postcss-font-variant", function() {
return function(styles) {
styles.walkRules(function(rule) {
var fontFeatureSettings = null
// read custom media queries
rule.walkDecls(function(decl) {
if (!fontVariantProperties[decl.prop]) {
return null
}
module.exports = postcss.plugin("postcss-font-variant", () => (styles) => {
styles.walkRules((rule) => {
let fontFeatureSettings = null
// read custom media queries
rule.walkDecls((decl) => {
if (!fontVariantProperties[decl.prop]) {
return null
}

var newValue = decl.value
if (decl.prop === "font-variant") {
newValue = decl.value.split(/\s+/g).map(function(val) {
return fontVariantProperties["font-variant"][val]
}).join(", ")
}
else if (fontVariantProperties[decl.prop][decl.value]) {
newValue = fontVariantProperties[decl.prop][decl.value]
}
let newValue = decl.value
if (decl.prop === "font-variant") {
newValue = decl.value.split(/\s+/g).map(
(val) => fontVariantProperties["font-variant"][val]
).join(", ")
}
else if (fontVariantProperties[decl.prop][decl.value]) {
newValue = fontVariantProperties[decl.prop][decl.value]
}

if (fontFeatureSettings === null) {
fontFeatureSettings = getFontFeatureSettingsPrevTo(decl);
}
if (fontFeatureSettings.value && fontFeatureSettings.value !== newValue) {
fontFeatureSettings.value += ", " + newValue;
}
else {
fontFeatureSettings.value = newValue;
}
})
if (fontFeatureSettings === null) {
fontFeatureSettings = getFontFeatureSettingsPrevTo(decl);
}
if (fontFeatureSettings.value && fontFeatureSettings.value !== newValue) {
fontFeatureSettings.value += ", " + newValue;
}
else {
fontFeatureSettings.value = newValue;
}
})
}
})
})
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"index.js"
],
"dependencies": {
"postcss": "^5.0.4"
"postcss": "^6.0.1"
},
"devDependencies": {
"jscs": "^2.1.0",
"jshint": "^2.8.0",
"jscs": "^3.0.7",
"jshint": "^2.9.4",
"npmpub": "^3.1.0",
"tape": "^4.0.3"
"tape": "^4.6.3"
},
"scripts": {
"lint": "npm run jscs && npm run jshint",
Expand Down