From 34e7c2095c5fefb4bc08a72babc4a71162be9f9e Mon Sep 17 00:00:00 2001 From: Aaron Barker Date: Fri, 19 Mar 2021 20:10:41 -0600 Subject: [PATCH] v1.2 - Update findSetters regex and add external test https://regex101.com/r/kWwUmp/3 (some day I will learn to write test cases) - `let` to `var` for better old browser support --- README.md | 4 ++++ css-var-polyfill.js | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf85bc4..0ec78d1 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ This is an attempt at a very basic [CSS variables (custom properties)](https://d According to [caniuse.com](https://caniuse.com/#feat=css-variables), of current browsers only IE, Edge and Opera Mini do not support CSS variables. This polyfill appears to work on all three really well. I don't see why this wouldn't work on older browsers as well, but I haven't been able to test it on them yet. # Changelog +## 1.2 - 2021-03-19 +- Update findSetters regex and add external test https://regex101.com/r/kWwUmp/3 (some day I will learn to write test cases) +- `let` to `var` for better old browser support + ## 1.1.2 - 2019-03-23 - Update findSetters and replaceGetters (thanks @CodeZeno) diff --git a/css-var-polyfill.js b/css-var-polyfill.js index 454f2c5..9f1fc8c 100644 --- a/css-var-polyfill.js +++ b/css-var-polyfill.js @@ -1,10 +1,10 @@ /*! - * css-var-polyfill.js - v1.1.2 + * css-var-polyfill.js - v1.2 * * Copyright (c) 2019 Aaron Barker * Released under the MIT license * - * Date: 2019-03-23 + * Date: 2021-03-19 */ let cssVarPoly = { init: function() { @@ -63,7 +63,8 @@ let cssVarPoly = { // find all the "--variable: value" matches in a provided block of CSS and add them to the master list findSetters: function(theCSS, counter) { // console.log(theCSS); - cssVarPoly.varsByBlock[counter] = theCSS.match(/(--[^:)]+:[\s]*[^;}]+)/g) || []; + // tests for the following at https://regex101.com/r/kWwUmp/3 + cssVarPoly.varsByBlock[counter] = theCSS.match(/(--[\w-]+:[\s]*[^;\n}]+)/g) || []; }, // run through all the CSS blocks to update the variables and then inject on the page