Skip to content

Commit

Permalink
- Linting (ESLint): Simplify regexes
Browse files Browse the repository at this point in the history
- npm: Update scripts to reflect removal of `all_tests.html`;
  remove `browser-test` script
- npm: Update devDeps
  • Loading branch information
brettz9 committed Nov 30, 2019
1 parent 3200e0a commit a59170f
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 293 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ module.exports = {
}
],
rules: {
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/453
"unicorn/regex-shorthand": 0,
// The Babel transform seems to have a problem converting these
"prefer-named-capture-group": "off",
// Override these `ash-nazg/sauron` rules which are difficult for us
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
## ?

- Fix (Accessibility): Avoid duplicate IDs
- Linting (ESLint): Simplify regexes
- Testing: Switch to Cypress with code coverage for UI testing;
use ESM version for faster debugging
- Testing: Add map file for underscore
- npm: Add peerDeps
- npm: Update scripts to reflect removal of `all_tests.html`;
remove `browser-test` script
- npm: Update devDeps, peerDeps

## 5.1.0

Expand Down
12 changes: 6 additions & 6 deletions dist/canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ var canvg = (function (exports) {
});
}
}, {
re: /^(\w{1})(\w{1})(\w{1})$/,
re: /^(\w)(\w)(\w)$/,
// re: /^(?<r>\w{1})(?<g>\w{1})(?<b>\w{1})$/,
example: ['#fb0', 'f0f'],
process: function process(_) {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ var canvg = (function (exports) {


svg.compressSpaces = function (s) {
return s.replace(/[\s\r\t\n]+/gm, ' ');
return s.replace(/\s+/gm, ' ');
}; // ajax
// Todo: Replace with `fetch` and polyfill

Expand Down Expand Up @@ -1211,7 +1211,7 @@ var canvg = (function (exports) {
}, {
key: "getUnits",
value: function getUnits() {
return String(this.value).replace(/[0-9.-]/g, '');
return String(this.value).replace(/[\d.-]/g, '');
} // get the length as pixels

}, {
Expand Down Expand Up @@ -2528,8 +2528,8 @@ var canvg = (function (exports) {
.replace(/,/gm, ' ') // get rid of all commas
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm, '$1 $2') // separate commands from points
.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/([MmZzLlHhVvCcSsQqTtAa])(\S)/gm, '$1 $2') // separate commands from points
.replace(/(\S)([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/(\d)([+-])/gm, '$1 $2') // separate digits when no comma
.replace(/(\.\d*)(\.)/gm, '$1 $2') // separate digits when no comma
.replace(/([Aa](\s+\d+)(\s+\d+)(\s+\d+))\s+([01])\s*([01])/gm, '$1 $5 $6 '); // shorthand elliptical arc path syntax
Expand Down Expand Up @@ -4002,7 +4002,7 @@ var canvg = (function (exports) {
}); // remove comments


css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^\s*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
// replace whitespace

css = svg.compressSpaces(css);
Expand Down
12 changes: 6 additions & 6 deletions dist/extensions/ext-server_moinsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ var svgEditorExtension_server_moinsave = (function () {
});
}
}, {
re: /^(\w{1})(\w{1})(\w{1})$/,
re: /^(\w)(\w)(\w)$/,
// re: /^(?<r>\w{1})(?<g>\w{1})(?<b>\w{1})$/,
example: ['#fb0', 'f0f'],
process: function process(_) {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ var svgEditorExtension_server_moinsave = (function () {


svg.compressSpaces = function (s) {
return s.replace(/[\s\r\t\n]+/gm, ' ');
return s.replace(/\s+/gm, ' ');
}; // ajax
// Todo: Replace with `fetch` and polyfill

Expand Down Expand Up @@ -1211,7 +1211,7 @@ var svgEditorExtension_server_moinsave = (function () {
}, {
key: "getUnits",
value: function getUnits() {
return String(this.value).replace(/[0-9.-]/g, '');
return String(this.value).replace(/[\d.-]/g, '');
} // get the length as pixels

}, {
Expand Down Expand Up @@ -2528,8 +2528,8 @@ var svgEditorExtension_server_moinsave = (function () {
.replace(/,/gm, ' ') // get rid of all commas
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm, '$1 $2') // separate commands from points
.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/([MmZzLlHhVvCcSsQqTtAa])(\S)/gm, '$1 $2') // separate commands from points
.replace(/(\S)([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/(\d)([+-])/gm, '$1 $2') // separate digits when no comma
.replace(/(\.\d*)(\.)/gm, '$1 $2') // separate digits when no comma
.replace(/([Aa](\s+\d+)(\s+\d+)(\s+\d+))\s+([01])\s*([01])/gm, '$1 $5 $6 '); // shorthand elliptical arc path syntax
Expand Down Expand Up @@ -4002,7 +4002,7 @@ var svgEditorExtension_server_moinsave = (function () {
}); // remove comments


css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^\s*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
// replace whitespace

css = svg.compressSpaces(css);
Expand Down
12 changes: 6 additions & 6 deletions dist/extensions/ext-server_opensave.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ var svgEditorExtension_server_opensave = (function () {
});
}
}, {
re: /^(\w{1})(\w{1})(\w{1})$/,
re: /^(\w)(\w)(\w)$/,
// re: /^(?<r>\w{1})(?<g>\w{1})(?<b>\w{1})$/,
example: ['#fb0', 'f0f'],
process: function process(_) {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ var svgEditorExtension_server_opensave = (function () {


svg.compressSpaces = function (s) {
return s.replace(/[\s\r\t\n]+/gm, ' ');
return s.replace(/\s+/gm, ' ');
}; // ajax
// Todo: Replace with `fetch` and polyfill

Expand Down Expand Up @@ -1211,7 +1211,7 @@ var svgEditorExtension_server_opensave = (function () {
}, {
key: "getUnits",
value: function getUnits() {
return String(this.value).replace(/[0-9.-]/g, '');
return String(this.value).replace(/[\d.-]/g, '');
} // get the length as pixels

}, {
Expand Down Expand Up @@ -2528,8 +2528,8 @@ var svgEditorExtension_server_opensave = (function () {
.replace(/,/gm, ' ') // get rid of all commas
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm, '$1 $2') // separate commands from points
.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/([MmZzLlHhVvCcSsQqTtAa])(\S)/gm, '$1 $2') // separate commands from points
.replace(/(\S)([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/(\d)([+-])/gm, '$1 $2') // separate digits when no comma
.replace(/(\.\d*)(\.)/gm, '$1 $2') // separate digits when no comma
.replace(/([Aa](\s+\d+)(\s+\d+)(\s+\d+))\s+([01])\s*([01])/gm, '$1 $5 $6 '); // shorthand elliptical arc path syntax
Expand Down Expand Up @@ -4002,7 +4002,7 @@ var svgEditorExtension_server_opensave = (function () {
}); // remove comments


css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^\s*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
// replace whitespace

css = svg.compressSpaces(css);
Expand Down
16 changes: 8 additions & 8 deletions dist/index-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7934,7 +7934,7 @@ var init$2 = function init(editorContext) {
*/

var dropXMLInteralSubset = function dropXMLInteralSubset(str) {
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?\]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
};
/**
* Converts characters in a string to XML-friendly entities.
Expand Down Expand Up @@ -8014,7 +8014,7 @@ function decode64(input) {
} // remove all characters that are not A-Z, a-z, 0-9, +, /, or =


input = input.replace(/[^A-Za-z0-9+/=]/g, '');
input = input.replace(/[^A-Za-z\d+/=]/g, '');
var output = '';
var i = 0;

Expand Down Expand Up @@ -17101,8 +17101,8 @@ function SvgCanvas(container, config) {
var pt = screenToPt(mouseX, mouseY);
var index = getIndexFromPoint(pt.x, pt.y);
var str = curtext.textContent;
var first = str.substr(0, index).replace(/[a-z0-9]+$/i, '').length;
var m = str.substr(index).match(/^[a-z0-9]+/i);
var first = str.substr(0, index).replace(/[a-z\d]+$/i, '').length;
var m = str.substr(index).match(/^[a-z\d]+/i);
var last = (m ? m[0].length : 0) + index;
setSelection(first, last); // Set tripleclick

Expand Down Expand Up @@ -25470,19 +25470,19 @@ var jPicker = function jPicker($) {
break;

case hex.get(0):
hex.val(hex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6));
hex.val(hex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 6));
bindedHex && bindedHex.val(hex.val());
color.val('hex', hex.val() !== '' ? hex.val() : null, e.target);
break;

case bindedHex && bindedHex.get(0):
bindedHex.val(bindedHex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6));
bindedHex.val(bindedHex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 6));
hex.val(bindedHex.val());
color.val('hex', bindedHex.val() !== '' ? bindedHex.val() : null, e.target);
break;

case ahex && ahex.get(0):
ahex.val(ahex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 2));
ahex.val(ahex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 2));
color.val('a', !isNullish$1(ahex.val()) ? parseInt(ahex.val(), 16) : null, e.target);
break;
}
Expand Down Expand Up @@ -26121,7 +26121,7 @@ var jPicker = function jPicker($) {
*/
validateHex: function validateHex(hex) {
// if (typeof hex === 'object') return '';
hex = hex.toLowerCase().replace(/[^a-f0-9]/g, '');
hex = hex.toLowerCase().replace(/[^a-f\d]/g, '');
if (hex.length > 8) hex = hex.substring(0, 8);
return hex;
},
Expand Down
2 changes: 1 addition & 1 deletion dist/index-es.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-es.min.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/index-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7940,7 +7940,7 @@
*/

var dropXMLInteralSubset = function dropXMLInteralSubset(str) {
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?\]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
};
/**
* Converts characters in a string to XML-friendly entities.
Expand Down Expand Up @@ -8020,7 +8020,7 @@
} // remove all characters that are not A-Z, a-z, 0-9, +, /, or =


input = input.replace(/[^A-Za-z0-9+/=]/g, '');
input = input.replace(/[^A-Za-z\d+/=]/g, '');
var output = '';
var i = 0;

Expand Down Expand Up @@ -17107,8 +17107,8 @@
var pt = screenToPt(mouseX, mouseY);
var index = getIndexFromPoint(pt.x, pt.y);
var str = curtext.textContent;
var first = str.substr(0, index).replace(/[a-z0-9]+$/i, '').length;
var m = str.substr(index).match(/^[a-z0-9]+/i);
var first = str.substr(0, index).replace(/[a-z\d]+$/i, '').length;
var m = str.substr(index).match(/^[a-z\d]+/i);
var last = (m ? m[0].length : 0) + index;
setSelection(first, last); // Set tripleclick

Expand Down Expand Up @@ -25476,19 +25476,19 @@
break;

case hex.get(0):
hex.val(hex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6));
hex.val(hex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 6));
bindedHex && bindedHex.val(hex.val());
color.val('hex', hex.val() !== '' ? hex.val() : null, e.target);
break;

case bindedHex && bindedHex.get(0):
bindedHex.val(bindedHex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 6));
bindedHex.val(bindedHex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 6));
hex.val(bindedHex.val());
color.val('hex', bindedHex.val() !== '' ? bindedHex.val() : null, e.target);
break;

case ahex && ahex.get(0):
ahex.val(ahex.val().replace(/[^a-fA-F0-9]/g, '').toLowerCase().substring(0, 2));
ahex.val(ahex.val().replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 2));
color.val('a', !isNullish$1(ahex.val()) ? parseInt(ahex.val(), 16) : null, e.target);
break;
}
Expand Down Expand Up @@ -26127,7 +26127,7 @@
*/
validateHex: function validateHex(hex) {
// if (typeof hex === 'object') return '';
hex = hex.toLowerCase().replace(/[^a-f0-9]/g, '');
hex = hex.toLowerCase().replace(/[^a-f\d]/g, '');
if (hex.length > 8) hex = hex.substring(0, 8);
return hex;
},
Expand Down
2 changes: 1 addition & 1 deletion dist/index-umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-umd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jspdf.plugin.svgToPdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
});
}
}, {
re: /^(\w{1})(\w{1})(\w{1})$/,
re: /^(\w)(\w)(\w)$/,
// re: /^(?<r>\w{1})(?<g>\w{1})(?<b>\w{1})$/,
example: ['#fb0', 'f0f'],
process: function process(_) {
Expand Down
8 changes: 4 additions & 4 deletions dist/svgcanvas-iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -8006,7 +8006,7 @@ var SvgCanvas = (function () {
*/

var dropXMLInteralSubset = function dropXMLInteralSubset(str) {
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?\]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
return str.replace(/(<!DOCTYPE\s+\w*\s*\[).*(\?]>)/, '$1$2'); // return str.replace(/(?<doctypeOpen><!DOCTYPE\s+\w*\s*\[).*(?<doctypeClose>\?\]>)/, '$<doctypeOpen>$<doctypeClose>');
};
/**
* Converts characters in a string to XML-friendly entities.
Expand Down Expand Up @@ -8086,7 +8086,7 @@ var SvgCanvas = (function () {
} // remove all characters that are not A-Z, a-z, 0-9, +, /, or =


input = input.replace(/[^A-Za-z0-9+/=]/g, '');
input = input.replace(/[^A-Za-z\d+/=]/g, '');
var output = '';
var i = 0;

Expand Down Expand Up @@ -16879,8 +16879,8 @@ var SvgCanvas = (function () {
var pt = screenToPt(mouseX, mouseY);
var index = getIndexFromPoint(pt.x, pt.y);
var str = curtext.textContent;
var first = str.substr(0, index).replace(/[a-z0-9]+$/i, '').length;
var m = str.substr(index).match(/^[a-z0-9]+/i);
var first = str.substr(0, index).replace(/[a-z\d]+$/i, '').length;
var m = str.substr(index).match(/^[a-z\d]+/i);
var last = (m ? m[0].length : 0) + index;
setSelection(first, last); // Set tripleclick

Expand Down
2 changes: 1 addition & 1 deletion dist/svgcanvas-iife.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/svgcanvas-iife.min.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions editor/canvg/canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function build (opts) {

// compress spaces
svg.compressSpaces = function (s) {
return s.replace(/[\s\r\t\n]+/gm, ' ');
return s.replace(/\s+/gm, ' ');
};

// ajax
Expand Down Expand Up @@ -302,7 +302,7 @@ function build (opts) {
}

getUnits () {
return String(this.value).replace(/[0-9.-]/g, '');
return String(this.value).replace(/[\d.-]/g, '');
}

// get the length as pixels
Expand Down Expand Up @@ -1254,8 +1254,8 @@ function build (opts) {
.replace(/,/gm, ' ') // get rid of all commas
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from commands
.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm, '$1 $2') // separate commands from points
.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/([MmZzLlHhVvCcSsQqTtAa])(\S)/gm, '$1 $2') // separate commands from points
.replace(/(\S)([MmZzLlHhVvCcSsQqTtAa])/gm, '$1 $2') // separate commands from points
.replace(/(\d)([+-])/gm, '$1 $2') // separate digits when no comma
.replace(/(\.\d*)(\.)/gm, '$1 $2') // separate digits when no comma
.replace(/([Aa](\s+\d+)(\s+\d+)(\s+\d+))\s+([01])\s*([01])/gm, '$1 $5 $6 '); // shorthand elliptical arc path syntax
Expand Down Expand Up @@ -2367,7 +2367,7 @@ function build (opts) {
css += nodeValue;
});
// remove comments
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^\s*\/\/.*)/gm, ''); // eslint-disable-line unicorn/no-unsafe-regex
// replace whitespace
css = svg.compressSpaces(css);
const cssDefs = css.split('}');
Expand Down
2 changes: 1 addition & 1 deletion editor/canvg/rgbcolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const colorDefs = [
}
},
{
re: /^(\w{1})(\w{1})(\w{1})$/,
re: /^(\w)(\w)(\w)$/,
// re: /^(?<r>\w{1})(?<g>\w{1})(?<b>\w{1})$/,
example: ['#fb0', 'f0f'],
process (_, ...bits) {
Expand Down
Loading

0 comments on commit a59170f

Please sign in to comment.