Skip to content

Commit

Permalink
chore(regex): port regex fixes from 4.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bhough committed May 31, 2021
1 parent a09f484 commit 62b4042
Show file tree
Hide file tree
Showing 6 changed files with 778 additions and 575 deletions.
30 changes: 30 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
32 changes: 8 additions & 24 deletions docs/assets/polished.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@
};
}

function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

Expand Down Expand Up @@ -1168,7 +1168,7 @@
}

function isDataURI(fontFilePath) {
return !!fontFilePath.match(dataURIRegex);
return !!fontFilePath.replace(/\s+/g, ' ').match(dataURIRegex);
}

function generateFileReferences(fontFilePath, fileFormats, formatHint) {
Expand Down Expand Up @@ -1418,15 +1418,7 @@
return template.trim();
}

function _templateObject() {
var data = _taggedTemplateLiteralLoose__default['default'](["linear-gradient(", "", ")"]);

_templateObject = function _templateObject() {
return data;
};

return data;
}
var _templateObject;

/**
* CSS for declaring a linear gradient, including a fallback background-color. The fallback is either the first color-stop or an explicitly passed fallback color.
Expand Down Expand Up @@ -1469,7 +1461,7 @@

return {
backgroundColor: fallback || colorStops[0].replace(/,\s+/g, ',').split(' ')[0].replace(/,(?=\S)/g, ', '),
backgroundImage: constructGradientValue(_templateObject(), toDirection, colorStops.join(', ').replace(/,(?=\S)/g, ', '))
backgroundImage: constructGradientValue(_templateObject || (_templateObject = _taggedTemplateLiteralLoose__default['default'](["linear-gradient(", "", ")"])), toDirection, colorStops.join(', ').replace(/,(?=\S)/g, ', '))
};
}

Expand Down Expand Up @@ -1601,15 +1593,7 @@
}];
}

function _templateObject$1() {
var data = _taggedTemplateLiteralLoose__default['default'](["radial-gradient(", "", "", "", ")"]);

_templateObject$1 = function _templateObject() {
return data;
};

return data;
}
var _templateObject$1;

/**
* CSS for declaring a radial gradient, including a fallback background-color. The fallback is either the first color-stop or an explicitly passed fallback color.
Expand Down Expand Up @@ -1658,7 +1642,7 @@

return {
backgroundColor: fallback || colorStops[0].split(' ')[0],
backgroundImage: constructGradientValue(_templateObject$1(), position, shape, extent, colorStops.join(', '))
backgroundImage: constructGradientValue(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteralLoose__default['default'](["radial-gradient(", "", "", "", ")"])), position, shape, extent, colorStops.join(', '))
};
}

Expand Down Expand Up @@ -2214,7 +2198,7 @@
};
}

var rgbaMatched = rgbaRegex.exec(normalizedColor);
var rgbaMatched = rgbaRegex.exec(normalizedColor.substring(0, 50));

if (rgbaMatched) {
return {
Expand Down Expand Up @@ -2245,7 +2229,7 @@
};
}

var hslaMatched = hslaRegex.exec(normalizedColor);
var hslaMatched = hslaRegex.exec(normalizedColor.substring(0, 50));

if (hslaMatched) {
var _hue = parseInt("" + hslaMatched[1], 10);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polished",
"version": "3.7.1",
"version": "3.7.2",
"description": "A lightweight toolset for writing styles in Javascript.",
"license": "MIT",
"author": "Brian Hough <hello@brianhough.net> (https://polished.js.org)",
Expand Down
8 changes: 4 additions & 4 deletions src/color/parseToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function parseToRgb(color: string): RgbColor | RgbaColor {
}
if (normalizedColor.match(hexRgbaRegex)) {
const alpha = parseFloat(
(parseInt(`${normalizedColor[7]}${normalizedColor[8]}`, 16) / 255).toFixed(2),
(parseInt(`${normalizedColor[7]}${normalizedColor[8]}`, 16) / 255).toFixed(2)
)
return {
red: parseInt(`${normalizedColor[1]}${normalizedColor[2]}`, 16),
Expand All @@ -57,7 +57,7 @@ export default function parseToRgb(color: string): RgbColor | RgbaColor {
}
if (normalizedColor.match(reducedRgbaHexRegex)) {
const alpha = parseFloat(
(parseInt(`${normalizedColor[4]}${normalizedColor[4]}`, 16) / 255).toFixed(2),
(parseInt(`${normalizedColor[4]}${normalizedColor[4]}`, 16) / 255).toFixed(2)
)
return {
red: parseInt(`${normalizedColor[1]}${normalizedColor[1]}`, 16),
Expand All @@ -74,7 +74,7 @@ export default function parseToRgb(color: string): RgbColor | RgbaColor {
blue: parseInt(`${rgbMatched[3]}`, 10),
}
}
const rgbaMatched = rgbaRegex.exec(normalizedColor)
const rgbaMatched = rgbaRegex.exec(normalizedColor.substring(0, 50))
if (rgbaMatched) {
return {
red: parseInt(`${rgbaMatched[1]}`, 10),
Expand All @@ -99,7 +99,7 @@ export default function parseToRgb(color: string): RgbColor | RgbaColor {
blue: parseInt(`${hslRgbMatched[3]}`, 10),
}
}
const hslaMatched = hslaRegex.exec(normalizedColor)
const hslaMatched = hslaRegex.exec(normalizedColor.substring(0, 50))
if (hslaMatched) {
const hue = parseInt(`${hslaMatched[1]}`, 10)
const saturation = parseInt(`${hslaMatched[2]}`, 10) / 100
Expand Down
8 changes: 4 additions & 4 deletions src/mixins/fontFace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ function generateFormatHint(format: string, formatHint: boolean): string {
}

function isDataURI(fontFilePath: string): boolean {
return !!fontFilePath.match(dataURIRegex)
return !!fontFilePath.replace(/\s+/g, ' ').match(dataURIRegex)
}

function generateFileReferences(
fontFilePath: string,
fileFormats: Array<string>,
formatHint: boolean,
formatHint: boolean
): string {
if (isDataURI(fontFilePath)) {
return `url("${fontFilePath}")${generateFormatHint(fileFormats[0], formatHint)}`
}

const fileFontReferences = fileFormats.map(
format => `url("${fontFilePath}.${format}")${generateFormatHint(format, formatHint)}`,
format => `url("${fontFilePath}.${format}")${generateFormatHint(format, formatHint)}`
)
return fileFontReferences.join(', ')
}
Expand All @@ -49,7 +49,7 @@ function generateSources(
fontFilePath?: string,
localFonts?: Array<string>,
fileFormats: Array<string>,
formatHint: boolean,
formatHint: boolean
): string {
const fontReferences = []
if (localFonts) fontReferences.push(generateLocalReferences(localFonts))
Expand Down
Loading

0 comments on commit 62b4042

Please sign in to comment.