@schukai/monster 3.33.0 → 3.35.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Copyright schukai GmbH and contributors 2023. All Rights Reserved.
3
+ * Node module: @schukai/monster
4
+ * This file is licensed under the AGPLv3 License.
5
+ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
+ */
7
+
8
+ import { getWindow } from "./util.mjs";
9
+
10
+ export { convertToPixels, getDeviceDPI };
11
+
12
+ /**
13
+ * Stores the DPI of the device.
14
+ *
15
+ * @private
16
+ * @returns {number}
17
+ * @since 3.34.0
18
+ * @type {number|function}
19
+ */
20
+ let CURRENT_DEVICE_DPI = function () {
21
+ let i = 0;
22
+ for (i = 56; i < 2000; i++) {
23
+ if (getWindow().matchMedia(`(max-resolution: ${i}dpi)`).matches === true) {
24
+ return i;
25
+ }
26
+ }
27
+ return i;
28
+ };
29
+
30
+ /**
31
+ * Returns the DPI of the device.
32
+ *
33
+ * @since 3.34.0
34
+ * @memberOf Monster.DOM
35
+ * @returns {number}
36
+ */
37
+ function getDeviceDPI() {
38
+ // only call the function once
39
+ if (typeof CURRENT_DEVICE_DPI === "function") {
40
+ CURRENT_DEVICE_DPI = CURRENT_DEVICE_DPI();
41
+ }
42
+
43
+ return getWindow().devicePixelRatio * CURRENT_DEVICE_DPI;
44
+ }
45
+
46
+ /**
47
+ * Converts a CSS value to pixels.
48
+ *
49
+ * As Example:
50
+ *
51
+ * ```js
52
+ * convertToPixels('1em') // returns the current font size in pixels
53
+ * convertToPixels('1rem') // returns the current root font size in pixels
54
+ * convertToPixels('1px') // returns 1
55
+ * convertToPixels('100%') // returns the current width of the parent element in pixels
56
+ * ```
57
+ *
58
+ * Following units are supported:
59
+ * - px
60
+ * - em
61
+ * - rem
62
+ * - %
63
+ *
64
+ * @param {string} value
65
+ * @param {HTMLElement} [parentElement=document.documentElement]
66
+ * @param {HTMLElement} [fontSizeElement=document.documentElement]
67
+ * @returns {number}
68
+ * @license AGPLv3
69
+ * @since 3.34.0
70
+ * @copyright schukai GmbH
71
+ * @throws {Error} Unsupported unit
72
+ * @memberOf Monster.DOM
73
+ */
74
+
75
+ function convertToPixels(value, parentElement = document.documentElement, fontSizeElement = document.documentElement) {
76
+ const regex = /^([\d.]+)(.*)$/;
77
+ const [, num, unit] = value.match(regex);
78
+ const number = parseFloat(num);
79
+ const dpi = getDeviceDPI();
80
+
81
+ if (unit === "px") {
82
+ return number;
83
+ } else if (unit === "em") {
84
+ const fontSize = parseFloat(window.getComputedStyle(fontSizeElement).fontSize);
85
+ return number * fontSize;
86
+ } else if (unit === "rem") {
87
+ const rootFontSize = parseFloat(window.getComputedStyle(parentElement).fontSize);
88
+ return number * rootFontSize;
89
+ } else if (unit === "%") {
90
+ const parentWidth = parseFloat(window.getComputedStyle(parentElement).width);
91
+ return (number * parentWidth) / 100;
92
+ } else if (unit === "in") {
93
+ return number * dpi;
94
+ } else if (unit === "cm") {
95
+ return (number * dpi) / 2.54;
96
+ } else if (unit === "mm") {
97
+ return (number * dpi) / 25.4;
98
+ } else if (unit === "pt") {
99
+ return (number * dpi) / 72;
100
+ } else if (unit === "pc") {
101
+ return (number * dpi) / 6;
102
+ } else {
103
+ throw new Error(`Unsupported unit: ${unit}`);
104
+ }
105
+ }
@@ -8,7 +8,7 @@
8
8
  import { extend } from "../data/extend.mjs";
9
9
  import { Base } from "../types/base.mjs";
10
10
  import { getGlobalObject } from "../types/global.mjs";
11
- import {equipWithInternal} from "../types/internal.mjs";
11
+ import { equipWithInternal } from "../types/internal.mjs";
12
12
  import { isArray } from "../types/is.mjs";
13
13
  import { ATTRIBUTE_HREF, ATTRIBUTE_SRC } from "./constants.mjs";
14
14
  import { Resource } from "./resource.mjs";
@@ -74,14 +74,17 @@ class ResourceManager extends Base {
74
74
  * @property {Array} resources.data=[] array with {@link Monster.DOM.Resource.Data} objects
75
75
  */
76
76
  get internalDefaults() {
77
- return Object.assign({}, {
78
- document: getGlobalObject("document"),
79
- resources: {
80
- scripts: [],
81
- stylesheets: [],
82
- data: [],
77
+ return Object.assign(
78
+ {},
79
+ {
80
+ document: getGlobalObject("document"),
81
+ resources: {
82
+ scripts: [],
83
+ stylesheets: [],
84
+ data: [],
85
+ },
83
86
  },
84
- });
87
+ );
85
88
  }
86
89
 
87
90
  /**
@@ -1,7 +1,7 @@
1
- import {isString} from "../types/is.mjs";
2
- import {validateString} from "../types/validate.mjs";
1
+ import { isString } from "../types/is.mjs";
2
+ import { validateString } from "../types/validate.mjs";
3
3
 
4
- export {getSlottedElements, getSlottedNodes};
4
+ export { getSlottedElements, getSlottedNodes };
5
5
 
6
6
  /**
7
7
  * @private
@@ -16,7 +16,7 @@ export {getSlottedElements, getSlottedNodes};
16
16
  function getSlottedNodes(query, name) {
17
17
  const self = this;
18
18
  const result = new Set();
19
-
19
+
20
20
  if (!self.shadowRoot) {
21
21
  return result;
22
22
  }
@@ -57,7 +57,6 @@ function getSlottedNodes(query, name) {
57
57
  return result;
58
58
  }
59
59
 
60
-
61
60
  /**
62
61
  * @private
63
62
  * @param {String|undefined} query
@@ -5,10 +5,10 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {internalSymbol} from "../constants.mjs";
9
- import {diff} from "../data/diff.mjs";
10
- import {Pathfinder} from "../data/pathfinder.mjs";
11
- import {Pipe} from "../data/pipe.mjs";
8
+ import { internalSymbol } from "../constants.mjs";
9
+ import { diff } from "../data/diff.mjs";
10
+ import { Pathfinder } from "../data/pathfinder.mjs";
11
+ import { Pipe } from "../data/pipe.mjs";
12
12
  import {
13
13
  ATTRIBUTE_ERRORMESSAGE,
14
14
  ATTRIBUTE_UPDATER_ATTRIBUTES,
@@ -17,21 +17,21 @@ import {
17
17
  ATTRIBUTE_UPDATER_INSERT_REFERENCE,
18
18
  ATTRIBUTE_UPDATER_REMOVE,
19
19
  ATTRIBUTE_UPDATER_REPLACE,
20
- ATTRIBUTE_UPDATER_SELECT_THIS
20
+ ATTRIBUTE_UPDATER_SELECT_THIS,
21
21
  } from "../dom/constants.mjs";
22
22
 
23
- import {Base} from "../types/base.mjs";
24
- import {isArray, isInstance, isIterable} from "../types/is.mjs";
25
- import {Observer} from "../types/observer.mjs";
26
- import {ProxyObserver} from "../types/proxyobserver.mjs";
27
- import {validateArray, validateInstance} from "../types/validate.mjs";
28
- import {clone} from "../util/clone.mjs";
29
- import {trimSpaces} from "../util/trimspaces.mjs";
30
- import {addToObjectLink} from "./attributes.mjs";
31
- import {findTargetElementFromEvent} from "./events.mjs";
32
- import {findDocumentTemplate} from "./template.mjs";
23
+ import { Base } from "../types/base.mjs";
24
+ import { isArray, isInstance, isIterable } from "../types/is.mjs";
25
+ import { Observer } from "../types/observer.mjs";
26
+ import { ProxyObserver } from "../types/proxyobserver.mjs";
27
+ import { validateArray, validateInstance } from "../types/validate.mjs";
28
+ import { clone } from "../util/clone.mjs";
29
+ import { trimSpaces } from "../util/trimspaces.mjs";
30
+ import { addToObjectLink } from "./attributes.mjs";
31
+ import { findTargetElementFromEvent } from "./events.mjs";
32
+ import { findDocumentTemplate } from "./template.mjs";
33
33
 
34
- export {Updater, addObjectWithUpdaterToElement};
34
+ export { Updater, addObjectWithUpdaterToElement };
35
35
 
36
36
  /**
37
37
  * The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
@@ -172,7 +172,7 @@ class Updater extends Base {
172
172
  run() {
173
173
  // the key __init__has no further meaning and is only
174
174
  // used to create the diff for empty objects.
175
- this[internalSymbol].last = {__init__: true};
175
+ this[internalSymbol].last = { __init__: true };
176
176
  return this[internalSymbol].subject.notifyObservers();
177
177
  }
178
178
 
@@ -322,7 +322,7 @@ function retrieveAndSetValue(element) {
322
322
 
323
323
  let options = element?.selectedOptions;
324
324
  if (options === undefined) options = element.querySelectorAll(":scope option:checked");
325
- value = Array.from(options).map(({value}) => value);
325
+ value = Array.from(options).map(({ value }) => value);
326
326
 
327
327
  break;
328
328
  }
@@ -436,7 +436,7 @@ function insertElement(change) {
436
436
 
437
437
  const attributes = containerElement.getAttribute(ATTRIBUTE_UPDATER_INSERT);
438
438
  if (attributes === null) continue;
439
-
439
+
440
440
  let def = trimSpaces(attributes);
441
441
  let i = def.indexOf(" ");
442
442
  let key = trimSpaces(def.substr(0, i));
@@ -492,7 +492,7 @@ function insertElement(change) {
492
492
  let nodes = containerElement.querySelectorAll(
493
493
  `[${ATTRIBUTE_UPDATER_INSERT_REFERENCE}*="${refPrefix}"]`,
494
494
  );
495
-
495
+
496
496
  for (const [, node] of Object.entries(nodes)) {
497
497
  if (!available.has(node.getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE))) {
498
498
  try {
@@ -719,7 +719,7 @@ function runUpdateAttributes(container, parts, subject) {
719
719
  if (mem.has(element)) return;
720
720
  mem.add(element);
721
721
 
722
- // this case occurs when the ATTRIBUTE_UPDATER_SELECT_THIS attribute is set
722
+ // this case occurs when the ATTRIBUTE_UPDATER_SELECT_THIS attribute is set
723
723
  if (!element.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) {
724
724
  continue;
725
725
  }
@@ -152,7 +152,6 @@ function getDocumentFragmentFromString(html) {
152
152
  return template.content;
153
153
  }
154
154
 
155
-
156
155
  /**
157
156
  * Recursively searches upwards from a given element to find an ancestor element
158
157
  * with a specified ID, considering both normal DOM and shadow DOM.
@@ -199,4 +198,4 @@ function findElementWithIdUpwards(element, targetId) {
199
198
 
200
199
  // Otherwise, search the current element's parent
201
200
  return findElementWithIdUpwards(element.parentElement, targetId);
202
- }
201
+ }
@@ -5,14 +5,14 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {instanceSymbol, internalSymbol} from "../constants.mjs";
9
- import {extend} from "../data/extend.mjs";
8
+ import { instanceSymbol, internalSymbol } from "../constants.mjs";
9
+ import { extend } from "../data/extend.mjs";
10
10
 
11
- import {Formatter as TextFormatter} from "../text/formatter.mjs";
12
- import {validateInstance, validateString} from "../types/validate.mjs";
13
- import {Translations} from "./translations.mjs";
11
+ import { Formatter as TextFormatter } from "../text/formatter.mjs";
12
+ import { validateInstance, validateString } from "../types/validate.mjs";
13
+ import { Translations } from "./translations.mjs";
14
14
 
15
- export {Formatter};
15
+ export { Formatter };
16
16
 
17
17
  /**
18
18
  * @private
@@ -5,7 +5,7 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {instanceSymbol} from "../constants.mjs";
8
+ import { instanceSymbol } from "../constants.mjs";
9
9
  import { Base } from "../types/base.mjs";
10
10
  import { validateString } from "../types/validate.mjs";
11
11
  import { clone } from "../util/clone.mjs";
@@ -5,14 +5,14 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {instanceSymbol} from "../constants.mjs";
9
- import {hasObjectLink, getLinkedObjects,addToObjectLink} from "../dom/attributes.mjs";
10
- import {getLocaleOfDocument} from "../dom/locale.mjs";
11
- import {BaseWithOptions} from "../types/basewithoptions.mjs";
12
- import {Locale} from "./locale.mjs";
13
- import {Translations} from "./translations.mjs";
8
+ import { instanceSymbol } from "../constants.mjs";
9
+ import { hasObjectLink, getLinkedObjects, addToObjectLink } from "../dom/attributes.mjs";
10
+ import { getLocaleOfDocument } from "../dom/locale.mjs";
11
+ import { BaseWithOptions } from "../types/basewithoptions.mjs";
12
+ import { Locale } from "./locale.mjs";
13
+ import { Translations } from "./translations.mjs";
14
14
 
15
- export {Provider, translationsLinkSymbol};
15
+ export { Provider, translationsLinkSymbol };
16
16
 
17
17
  /**
18
18
  * @memberOf Monster.I18n
@@ -33,7 +33,6 @@ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@l
33
33
  * @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
34
34
  */
35
35
  class Provider extends BaseWithOptions {
36
-
37
36
  /**
38
37
  * This method is called by the `instanceof` operator.
39
38
  * @returns {symbol}
@@ -41,14 +40,13 @@ class Provider extends BaseWithOptions {
41
40
  */
42
41
  static get [instanceSymbol]() {
43
42
  return Symbol.for("@schukai/monster/i18n/provider@@instance");
44
- }
45
-
43
+ }
44
+
46
45
  /**
47
46
  * @param {Locale|string} locale
48
47
  * @return {Promise}
49
48
  */
50
49
  getTranslations(locale) {
51
-
52
50
  if (locale === undefined) {
53
51
  locale = getLocaleOfDocument();
54
52
  }
@@ -68,7 +66,6 @@ class Provider extends BaseWithOptions {
68
66
  * @return {Provider}
69
67
  */
70
68
  assignToElement(locale, element) {
71
-
72
69
  if (locale === undefined) {
73
70
  locale = getLocaleOfDocument();
74
71
  }
@@ -86,7 +83,6 @@ class Provider extends BaseWithOptions {
86
83
  }
87
84
 
88
85
  return this.getTranslations(locale).then((obj) => {
89
-
90
86
  let translations = null;
91
87
  if (hasObjectLink(element, translationsLinkSymbol)) {
92
88
  const objects = getLinkedObjects(element, translationsLinkSymbol);
@@ -96,21 +92,17 @@ class Provider extends BaseWithOptions {
96
92
  break;
97
93
  }
98
94
  }
99
-
95
+
100
96
  if (!(translations instanceof Translations)) {
101
97
  throw new Error("Object is not an instance of Translations");
102
98
  }
103
-
99
+
104
100
  translations.assignTranslations(obj);
105
-
106
101
  } else {
107
102
  addToObjectLink(element, translationsLinkSymbol, obj);
108
103
  }
109
104
 
110
-
111
105
  return obj;
112
106
  });
113
-
114
107
  }
115
-
116
108
  }
@@ -5,16 +5,16 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {internalSymbol} from "../../constants.mjs";
9
- import {extend} from "../../data/extend.mjs";
10
- import {getDocument} from "../../dom/util.mjs";
11
- import {isString} from "../../types/is.mjs";
12
- import {validateObject, validateString} from "../../types/validate.mjs";
13
- import {parseLocale} from "../locale.mjs";
14
- import {Provider} from "../provider.mjs";
15
- import {Translations} from "../translations.mjs";
8
+ import { internalSymbol } from "../../constants.mjs";
9
+ import { extend } from "../../data/extend.mjs";
10
+ import { getDocument } from "../../dom/util.mjs";
11
+ import { isString } from "../../types/is.mjs";
12
+ import { validateObject, validateString } from "../../types/validate.mjs";
13
+ import { parseLocale } from "../locale.mjs";
14
+ import { Provider } from "../provider.mjs";
15
+ import { Translations } from "../translations.mjs";
16
16
 
17
- export {Embed};
17
+ export { Embed };
18
18
 
19
19
  /**
20
20
  * The Embed provider retrieves a JSON file from the given Script Tag.
@@ -91,7 +91,6 @@ class Embed extends Provider {
91
91
  }
92
92
 
93
93
  return new Promise((resolve, reject) => {
94
-
95
94
  if (this.translateElement === null) {
96
95
  reject(new Error("Text not found"));
97
96
  return;
@@ -127,7 +126,6 @@ class Embed extends Provider {
127
126
  });
128
127
  }
129
128
 
130
-
131
129
  /**
132
130
  * Initializes the translations for the current document.
133
131
  *
@@ -137,7 +135,7 @@ class Embed extends Provider {
137
135
  * @returns {Promise<unknown[]>}
138
136
  */
139
137
  static assignTranslationsToElement(element) {
140
- const d = getDocument()
138
+ const d = getDocument();
141
139
 
142
140
  if (!(element instanceof HTMLElement)) {
143
141
  element = d.querySelector("body");
@@ -149,7 +147,7 @@ class Embed extends Provider {
149
147
  }
150
148
 
151
149
  const promises = [];
152
-
150
+
153
151
  list.forEach((translationElement) => {
154
152
  const p = new Embed(translationElement);
155
153
  promises.push(p.assignToElement(undefined, element));
@@ -157,5 +155,4 @@ class Embed extends Provider {
157
155
 
158
156
  return Promise.all(promises);
159
157
  }
160
-
161
158
  }
@@ -5,18 +5,17 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {instanceSymbol} from "../constants.mjs";
9
- import {getLinkedObjects, hasObjectLink} from "../dom/attributes.mjs";
10
- import {ATTRIBUTE_OBJECTLINK} from "../dom/constants.mjs";
11
- import {getDocument} from "../dom/util.mjs";
12
- import {Base} from "../types/base.mjs";
13
- import {isObject, isString} from "../types/is.mjs";
14
- import {validateInteger, validateObject, validateString} from "../types/validate.mjs";
15
- import {Locale, parseLocale} from "./locale.mjs";
16
- import {translationsLinkSymbol} from "./provider.mjs";
17
-
18
-
19
- export {Translations, getDocumentTranslations};
8
+ import { instanceSymbol } from "../constants.mjs";
9
+ import { getLinkedObjects, hasObjectLink } from "../dom/attributes.mjs";
10
+ import { ATTRIBUTE_OBJECTLINK } from "../dom/constants.mjs";
11
+ import { getDocument } from "../dom/util.mjs";
12
+ import { Base } from "../types/base.mjs";
13
+ import { isObject, isString } from "../types/is.mjs";
14
+ import { validateInteger, validateObject, validateString } from "../types/validate.mjs";
15
+ import { Locale, parseLocale } from "./locale.mjs";
16
+ import { translationsLinkSymbol } from "./provider.mjs";
17
+
18
+ export { Translations, getDocumentTranslations };
20
19
 
21
20
  /**
22
21
  * With this class you can manage translations and access the keys.
@@ -208,13 +207,13 @@ class Translations extends Base {
208
207
  * @throws {Error} Cannot find element with translations. Add a translations object to the document.
209
208
  * @throws {Error} This element has no translations.
210
209
  * @throws {Error} Missing translations.
210
+ * @memberOf Monster.I18n
211
211
  */
212
212
  function getDocumentTranslations(element) {
213
-
214
- const d = getDocument()
213
+ const d = getDocument();
215
214
 
216
215
  if (!(element instanceof HTMLElement)) {
217
- element = d.querySelector('[' + ATTRIBUTE_OBJECTLINK + '~="' + translationsLinkSymbol.toString() + '"]');
216
+ element = d.querySelector(`[${ATTRIBUTE_OBJECTLINK}~="${translationsLinkSymbol.toString()}"]`);
218
217
  if (element === null) {
219
218
  throw new Error("Cannot find element with translations. Add a translations object to the document.");
220
219
  }
@@ -237,7 +236,4 @@ function getDocumentTranslations(element) {
237
236
  }
238
237
 
239
238
  throw new Error("Missing translations.");
240
-
241
239
  }
242
-
243
-
@@ -1,7 +1,40 @@
1
- export {generateRangeComparisonExpression}
1
+ export { generateRangeComparisonExpression };
2
2
 
3
3
  /**
4
- * Generates a comparison expression for a comma-separated string of ranges and single values.
4
+ * The `generateRangeComparisonExpression()` function is function that generates a string representation
5
+ * of a comparison expression based on a range of values. It takes three arguments:
6
+ *
7
+ * - expression (required): a string representation of a range of values in the format of start1-end1,start2-end2,value3....
8
+ * - valueName (required): a string representing the name of the value that is being compared to the range of values.
9
+ * - options (optional): an object containing additional options to customize the comparison expression.
10
+ *
11
+ * The generateRangeComparisonExpression() function returns a string representation of the comparison expression.
12
+ *
13
+ * ## Options
14
+ * The options parameter is an object that can have the following properties:
15
+ *
16
+ * urlEncode (boolean, default: false): if set to true, URL encodes the comparison operators.
17
+ * andOp (string, default: '&&'): the logical AND operator to use in the expression.
18
+ * orOp (string, default: '||'): the logical OR operator to use in the expression.
19
+ * eqOp (string, default: '=='): the equality operator to use in the expression.
20
+ * geOp (string, default: '>='): the greater than or equal to operator to use in the expression.
21
+ * leOp (string, default: '<='): the less than or equal to operator to use in the expression.
22
+ *
23
+ * Examples
24
+ *
25
+ * ```javascript
26
+ * const expression = '0-10,20-30';
27
+ * const valueName = 'age';
28
+ * const options = { urlEncode: true, andOp: 'and', orOp: 'or', eqOp: '=', geOp: '>=', leOp: '<=' };
29
+ * const comparisonExpression = generateRangeComparisonExpression(expression, valueName, options);
30
+ *
31
+ * console.log(comparisonExpression); // age%3E%3D0%20and%20age%3C%3D10%20or%20age%3E%3D20%20and%20age%3C%3D30
32
+ * ```
33
+ *
34
+ * In this example, the generateRangeComparisonExpression() function generates a string representation of the comparison
35
+ * expression for the expression and valueName parameters with the specified options. The resulting comparison
36
+ * expression is 'age>=0 and age<=10 or age>=20 and age<=30', URL encoded according to the urlEncode option.
37
+ *
5
38
  * @param {string} expression - The string expression to generate the comparison for.
6
39
  * @param {string} valueName - The name of the value to compare against.
7
40
  * @param {Object} [options] - The optional parameters.
@@ -13,33 +46,29 @@ export {generateRangeComparisonExpression}
13
46
  * @param {string} [options.leOp='<='] - The comparison operator for less than or equal to to use.
14
47
  * @returns {string} The generated comparison expression.
15
48
  * @throws {Error} If the input is invalid.
49
+ * @memberOf Monster.Text
50
+ * @summary Generates a comparison expression based on a range of values.
16
51
  */
17
52
  function generateRangeComparisonExpression(expression, valueName, options = {}) {
18
- const {
19
- urlEncode = false,
20
- andOp = '&&',
21
- orOp = '||',
22
- eqOp = '==',
23
- geOp = '>=',
24
- leOp = '<=',
25
- } = options;
26
- const ranges = expression.split(',');
27
- let comparison = '';
53
+ const { urlEncode = false, andOp = "&&", orOp = "||", eqOp = "==", geOp = ">=", leOp = "<=" } = options;
54
+ const ranges = expression.split(",");
55
+ let comparison = "";
28
56
  for (let i = 0; i < ranges.length; i++) {
29
57
  const range = ranges[i].trim();
30
- if (range === '') {
58
+ if (range === "") {
31
59
  throw new Error(`Invalid range '${range}'`);
32
- } else if (range.includes('-')) {
33
- const [start, end] = range.split('-').map(s => (s === '' ? null : parseFloat(s)));
60
+ } else if (range.includes("-")) {
61
+ const [start, end] = range.split("-").map((s) => (s === "" ? null : parseFloat(s)));
34
62
  if ((start !== null && isNaN(start)) || (end !== null && isNaN(end))) {
35
63
  throw new Error(`Invalid value in range '${range}'`);
36
64
  }
37
65
  if (start !== null && end !== null && start > end) {
38
66
  throw new Error(`Invalid range '${range}'`);
39
67
  }
40
- const compStart = start !== null ? `${valueName}${urlEncode ? encodeURIComponent(geOp) : geOp}${start}` : '';
41
- const compEnd = end !== null ? `${valueName}${urlEncode ? encodeURIComponent(leOp) : leOp}${end}` : '';
42
- const compRange = `${compStart}${compStart && compEnd ? ` ${andOp} ` : ''}${compEnd}`;
68
+ const compStart =
69
+ start !== null ? `${valueName}${urlEncode ? encodeURIComponent(geOp) : geOp}${start}` : "";
70
+ const compEnd = end !== null ? `${valueName}${urlEncode ? encodeURIComponent(leOp) : leOp}${end}` : "";
71
+ const compRange = `${compStart}${compStart && compEnd ? ` ${andOp} ` : ""}${compEnd}`;
43
72
  comparison += ranges.length > 1 ? `(${compRange})` : compRange;
44
73
  } else {
45
74
  const value = parseFloat(range);
@@ -17,7 +17,7 @@ export { Base };
17
17
  *
18
18
  * Therefor the class has a static method ` [Symbol.hasInstance](that)` which returns true if the object
19
19
  * is an instance of the class.
20
- *
20
+ *
21
21
  * @see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
22
22
  *
23
23
  * Derived classes should implement a static getter `instanceSymbol` which returns a unique symbol.