summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/nth-check/lib/parse.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
committerRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
commit83354b2b88218090988dd6e526b0a2505b57e0f1 (patch)
treee3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/nth-check/lib/parse.js
parent47b8f2299a483024c4a6a8876af825a010954caa (diff)
downloadpluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/nth-check/lib/parse.js')
-rw-r--r--includes/external/addressbook/node_modules/nth-check/lib/parse.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/nth-check/lib/parse.js b/includes/external/addressbook/node_modules/nth-check/lib/parse.js
new file mode 100644
index 0000000..904244c
--- /dev/null
+++ b/includes/external/addressbook/node_modules/nth-check/lib/parse.js
@@ -0,0 +1,77 @@
+"use strict";
+// Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.parse = void 0;
+// Whitespace as per https://www.w3.org/TR/selectors-3/#lex is " \t\r\n\f"
+var whitespace = new Set([9, 10, 12, 13, 32]);
+var ZERO = "0".charCodeAt(0);
+var NINE = "9".charCodeAt(0);
+/**
+ * Parses an expression.
+ *
+ * @throws An `Error` if parsing fails.
+ * @returns An array containing the integer step size and the integer offset of the nth rule.
+ * @example nthCheck.parse("2n+3"); // returns [2, 3]
+ */
+function parse(formula) {
+ formula = formula.trim().toLowerCase();
+ if (formula === "even") {
+ return [2, 0];
+ }
+ else if (formula === "odd") {
+ return [2, 1];
+ }
+ // Parse [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
+ var idx = 0;
+ var a = 0;
+ var sign = readSign();
+ var number = readNumber();
+ if (idx < formula.length && formula.charAt(idx) === "n") {
+ idx++;
+ a = sign * (number !== null && number !== void 0 ? number : 1);
+ skipWhitespace();
+ if (idx < formula.length) {
+ sign = readSign();
+ skipWhitespace();
+ number = readNumber();
+ }
+ else {
+ sign = number = 0;
+ }
+ }
+ // Throw if there is anything else
+ if (number === null || idx < formula.length) {
+ throw new Error("n-th rule couldn't be parsed ('".concat(formula, "')"));
+ }
+ return [a, sign * number];
+ function readSign() {
+ if (formula.charAt(idx) === "-") {
+ idx++;
+ return -1;
+ }
+ if (formula.charAt(idx) === "+") {
+ idx++;
+ }
+ return 1;
+ }
+ function readNumber() {
+ var start = idx;
+ var value = 0;
+ while (idx < formula.length &&
+ formula.charCodeAt(idx) >= ZERO &&
+ formula.charCodeAt(idx) <= NINE) {
+ value = value * 10 + (formula.charCodeAt(idx) - ZERO);
+ idx++;
+ }
+ // Return `null` if we didn't read anything.
+ return idx === start ? null : value;
+ }
+ function skipWhitespace() {
+ while (idx < formula.length &&
+ whitespace.has(formula.charCodeAt(idx))) {
+ idx++;
+ }
+ }
+}
+exports.parse = parse;
+//# sourceMappingURL=parse.js.map \ No newline at end of file