]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Cache the lineheight regex (#8240)
authorEvert Timberg <evert.timberg+github@gmail.com>
Mon, 28 Dec 2020 08:19:16 +0000 (03:19 -0500)
committerGitHub <noreply@github.com>
Mon, 28 Dec 2020 08:19:16 +0000 (10:19 +0200)
src/helpers/helpers.options.js

index 8a445f6e950b33dbef1007874d81dfdcd16311ef..2b01d518e98ba62bc66e4749769c37981733ea12 100644 (file)
@@ -2,6 +2,8 @@ import defaults from '../core/core.defaults';
 import {isArray, isObject, valueOrDefault} from './helpers.core';
 import {toFontString} from './helpers.canvas';
 
+const LINE_HEIGHT = new RegExp(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
+
 /**
  * @alias Chart.helpers.options
  * @namespace
@@ -15,7 +17,7 @@ import {toFontString} from './helpers.canvas';
  * @since 2.7.0
  */
 export function toLineHeight(value, size) {
-       const matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
+       const matches = ('' + value).match(LINE_HEIGHT);
        if (!matches || matches[1] === 'normal') {
                return size * 1.2;
        }