Skip to content

Commit

Permalink
chore(regex): clean up regex for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bhough committed May 31, 2021
1 parent 8cceac1 commit 7f551f1
Show file tree
Hide file tree
Showing 7 changed files with 1,236 additions and 898 deletions.
4 changes: 4 additions & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

validate-commit-msg
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
lint-staged --debug
4 changes: 2 additions & 2 deletions docs/assets/polished.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@
}

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

function generateFileReferences(fontFilePath, fileFormats, formatHint) {
Expand Down Expand Up @@ -2361,7 +2361,7 @@
};
}

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

if (rgbaMatched) {
return {
Expand Down
38 changes: 16 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polished",
"version": "4.1.2",
"version": "4.2.0",
"description": "A lightweight toolset for writing styles in Javascript.",
"license": "MIT",
"author": "Brian Hough <hello@brianhough.net> (https://polished.js.org)",
Expand Down Expand Up @@ -63,45 +63,45 @@
"build:lib": "src/**/*.js"
},
"dependencies": {
"@babel/runtime": "^7.13.17"
"@babel/runtime": "^7.14.0"
},
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/core": "^7.13.16",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.13.15",
"@babel/preset-env": "^7.14.4",
"@babel/preset-flow": "^7.13.13",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^2.4.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"babel-jest": "^27.0.2",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-preval": "5.0.0",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.1.0",
"documentation": "12.3.0",
"eslint": "^7.24.0",
"eslint": "^7.27.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-import": "^2.23.4",
"flow-bin": "^0.133.0",
"flow-copy-source": "^2.0.8",
"husky": "^6.0.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"jest": "^27.0.3",
"lint-staged": "^11.0.0",
"npm-watch": "^0.9.0",
"prettier": "^2.2.1",
"prettier": "^2.3.0",
"pushstate-server": "^3.1.0",
"ramda": "^0.27.0",
"rollup": "^2.45.2",
"rollup": "^2.50.5",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^17.4.2",
"semantic-release": "^17.4.3",
"shx": "^0.3.3",
"tsgen": "1.3.0",
"typescript": "4.2.4",
"typescript": "4.3.2",
"validate-commit-msg": "^2.14.0"
},
"config": {
Expand All @@ -119,12 +119,6 @@
"type": "opencollective",
"url": "https://opencollective.com/polished"
},
"husky": {
"hooks": {
"post-commit": "validate-commit-msg",
"pre-commit": "lint-staged --debug"
}
},
"engines": {
"node": ">=10"
}
Expand Down
2 changes: 1 addition & 1 deletion src/color/parseToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
2 changes: 1 addition & 1 deletion src/mixins/fontFace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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(
Expand Down
Loading

0 comments on commit 7f551f1

Please sign in to comment.