Skip to content

Commit

Permalink
Update to es6+.
Browse files Browse the repository at this point in the history
Remove support for node 8.

Update dependencies.

Update eslint config.
  • Loading branch information
jonkemp committed Jan 20, 2020
1 parent 8c608f7 commit 5144bf7
Show file tree
Hide file tree
Showing 18 changed files with 1,839 additions and 1,150 deletions.
25 changes: 16 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
},
"globals": {},
"extends": "eslint:recommended",

// Stop ESLint from looking for a configuration file in parent folders
"root": true,

"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "script",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
"block-scoped-var": 2,
"complexity": [
Expand Down Expand Up @@ -43,11 +55,6 @@
"never"
],

"strict": [
2,
"global"
],

"no-shadow": 2,
"no-use-before-define": 2,

Expand Down Expand Up @@ -125,9 +132,10 @@
],
"new-cap": 2,
"new-parens": 2,
"newline-after-var": [
1,
"always"
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*"},
{ "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"]}
],
"no-array-constructor": 2,
"no-bitwise": 1,
Expand All @@ -141,7 +149,6 @@
1,
"always"
],
"one-var": 1,
"operator-assignment": [
1,
"always"
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- '12'
- '10'
- '8'
before_script:
- npm install -g gulp
- gulp lint
Expand Down
31 changes: 13 additions & 18 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
/* eslint-disable */
'use strict';
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const eslint = require('gulp-eslint');

var gulp = require('gulp'),
mocha = require('gulp-mocha'),
eslint = require('gulp-eslint'),
paths = {
scripts: ['./*.js', './lib/*.js', '!./gulpfile.js']
};
const paths = {
scripts: ['./*.js', './lib/*.js', '!./gulpfile.js']
};

gulp.task('lint', function () {
return gulp.src(paths.scripts)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint', () => gulp.src(paths.scripts)
.pipe(eslint({fix: true}))
.pipe(eslint.format())
.pipe(eslint.failAfterError()));

gulp.task('test', function () {
return gulp.src('./test/*.js')
.pipe(mocha({ reporter: 'spec' }));
});
gulp.task('test', () => gulp.src('./test/*.js')
.pipe(mocha({ reporter: 'spec' })));

gulp.task('watch', function () {
gulp.task('watch', () => {
gulp.watch(paths.scripts, gulp.parallel('lint', 'test'));
});

Expand Down
68 changes: 32 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
'use strict';
const extend = require('extend');
const inlineContent = require('./lib/inlineContent');

var extend = require('extend'),
inlineContent = require('./lib/inlineContent');
module.exports = (html, options) => new Promise((resolve, reject) => {
const opt = extend(true, {
extraCss: '',
applyStyleTags: true,
removeStyleTags: true,
applyLinkTags: true,
removeLinkTags: true,
preserveMediaQueries: false,
removeHtmlSelectors: false,
applyWidthAttributes: false,
applyTableAttributes: false,
codeBlocks: {
EJS: { start: '<%', end: '%>' },
HBS: { start: '{{', end: '}}' }
},
xmlMode: false,
decodeEntities: false,
lowerCaseTags: true,
lowerCaseAttributeNames: false,
recognizeCDATA: false,
recognizeSelfClosing: false
}, options);

module.exports = function (html, options) {
return new Promise(function (resolve, reject) {
var opt = extend(true, {
extraCss: '',
applyStyleTags: true,
removeStyleTags: true,
applyLinkTags: true,
removeLinkTags: true,
preserveMediaQueries: false,
removeHtmlSelectors: false,
applyWidthAttributes: false,
applyTableAttributes: false,
codeBlocks: {
EJS: { start: '<%', end: '%>' },
HBS: { start: '{{', end: '}}' }
},
xmlMode: false,
decodeEntities: false,
lowerCaseTags: true,
lowerCaseAttributeNames: false,
recognizeCDATA: false,
recognizeSelfClosing: false
}, options);

inlineContent(String(html), opt)
.then(function (data) {
resolve(data);
})
.catch(function (err) {
reject(err);
});
});
};
inlineContent(String(html), opt)
.then(data => {
resolve(data);
})
.catch(err => {
reject(err);
});
});
32 changes: 15 additions & 17 deletions lib/addProps.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
'use strict';

var cssSelector = require('./styleSelector'),
importantSelector = cssSelector('<!important>', [ 2, 0, 0, 0 ]),
property = require('./cssProperty');
const cssSelector = require('./styleSelector');
const importantSelector = cssSelector('<!important>', [ 2, 0, 0, 0 ]);
const property = require('./cssProperty');

function getProperty(style, name, selector) {
var value = style[name],
sel = style._importants[name] ? importantSelector : selector;
const value = style[name];
const sel = style._importants[name] ? importantSelector : selector;

return property(name, value, sel);
}

// go through the properties
module.exports = function (el, style, selector) {
var i,
l = style.length,
name,
prop,
existing,
winner;
module.exports = ({ styleProps }, style, selector) => {
let i;
const l = style.length;
let name;
let prop;
let existing;
let winner;

for (i = 0; i < l; i++) {
name = style[i];
prop = getProperty(style, name, selector);
existing = el.styleProps[name];
existing = styleProps[name];

if (existing) {
winner = existing.compare(prop);

if (winner === prop) {
el.styleProps[name] = prop;
styleProps[name] = prop;
}
} else {
el.styleProps[name] = prop;
styleProps[name] = prop;
}
}
};
44 changes: 21 additions & 23 deletions lib/cssProperty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* Compares two specificity vectors, returning the winning one.
*
Expand All @@ -10,7 +8,7 @@
*/

function compareSpecificity(a, b) {
var i;
let i;

for (i = 0; i < 4; i++) {
if (a[i] === b[i]) {
Expand All @@ -34,31 +32,31 @@ function compareSpecificity(a, b) {
* @api public
*/

module.exports = function (prop, value, selector) {
var o = {},
module.exports = (prop, value, selector) => {
let o = {};

/**
* Compares with another Property based on Selector#specificity.
*
* @api public
*/
/**
* Compares with another Property based on Selector#specificity.
*
* @api public
*/

compare = function (property) {
var a = selector.specificity(),
b = property.selector.specificity(),
winner = compareSpecificity(a, b);
const compare = property => {
const a = selector.specificity();
const b = property.selector.specificity();
const winner = compareSpecificity(a, b);

if (winner === a && a !== b) {
return o;
}
return property;
};
if (winner === a && a !== b) {
return o;
}
return property;
};

o = {
prop: prop,
value: value,
selector: selector,
compare: compare
prop,
value,
selector,
compare
};

return o;
Expand Down
26 changes: 12 additions & 14 deletions lib/handleRule.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
'use strict';
const cssSelector = require('./styleSelector');
const parseCSS = require('css-rules');
const styleSelector = cssSelector('<style attribute>', [ 1, 0, 0, 0 ]);
const addProps = require('./addProps');

var cssSelector = require('./styleSelector'),
parseCSS = require('css-rules'),
styleSelector = cssSelector('<style attribute>', [ 1, 0, 0, 0 ]),
addProps = require('./addProps');
module.exports = (rule, $) => {
const sel = rule[0];
const style = rule[1];
const selector = cssSelector(sel);
const editedElements = [];

module.exports = function (rule, $) {
var sel = rule[0],
style = rule[1],
selector = cssSelector(sel),
editedElements = [];

$(sel).each(function (index, el) {
var cssText;
$(sel).each((index, el) => {
let cssText;

if (!el.styleProps) {
el.styleProps = {};

// if the element has inline styles, fake selector with topmost specificity
if ($(el).attr('style')) {
cssText = '* { ' + $(el).attr('style') + ' } ';
cssText = `* { ${$(el).attr('style')} } `;

addProps(el, parseCSS(cssText)[0][1], styleSelector);
}
Expand Down
Loading

0 comments on commit 5144bf7

Please sign in to comment.