Skip to content
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

Solve a problem: postcss-px-to-viewport: postcss.plugin was deprecated. #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var defaults = {
minPixelValue: 1,
mediaQuery: false,
replace: true,
exclude: undefined,
include: undefined,
landscape: false,
landscapeUnit: 'vw',
landscapeWidth: 568
Expand All @@ -25,7 +27,7 @@ var defaults = {
var ignoreNextComment = 'px-to-viewport-ignore-next';
var ignorePrevComment = 'px-to-viewport-ignore';

module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {
module.exports = (options = {}) => {
var opts = objectAssign({}, defaults, options);

checkRegExpOrArray(opts, 'exclude');
Expand Down Expand Up @@ -142,7 +144,7 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {
css.append(landscapeRoot);
}
};
});
};

function getUnit(prop, opts) {
return prop.indexOf('font') === -1 ? opts.viewportUnit : opts.fontViewportUnit;
Expand All @@ -158,10 +160,6 @@ function createPxReplace(opts, viewportUnit, viewportSize) {
};
}

function error(decl, message) {
throw decl.error(message, { plugin: 'postcss-px-to-viewport' });
}

function checkRegExpOrArray(options, optionName) {
var option = options[optionName];
if (!option) return;
Expand All @@ -176,7 +174,7 @@ function checkRegExpOrArray(options, optionName) {
}
if (!bad) return;
}
throw new Error('options.' + optionName + ' should be RegExp or Array of RegExp.');
throw new Error('options.' + optionName + ' type is' + Object.prototype.toString.call(option) + ', should be RegExp or Array of RegExp.');
}

function toFixed(number, precision) {
Expand All @@ -193,6 +191,13 @@ function blacklistedSelector(blacklist, selector) {
});
}

function isExclude(reg, file) {
if (Object.prototype.toString.call(reg) !== '[object RegExp]') {
throw new Error('options.exclude should be RegExp.');
}
return file.match(reg) !== null;
}

function declarationExists(decls, prop, value) {
return decls.some(function (decl) {
return (decl.prop === prop && decl.value === value);
Expand Down