@domql/utils 2.5.154 → 2.5.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/object.js +1 -1
- package/dist/esm/array.js +122 -0
- package/dist/esm/component.js +241 -0
- package/dist/esm/cookie.js +60 -0
- package/dist/esm/env.js +12 -0
- package/dist/esm/function.js +61 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/key.js +13 -0
- package/dist/esm/log.js +15 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +687 -0
- package/dist/esm/string.js +124 -0
- package/dist/esm/tags.js +145 -0
- package/dist/esm/types.js +64 -0
- package/object.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const stringIncludesAny = (str, characters) => {
|
|
2
|
+
for (const char of characters) {
|
|
3
|
+
if (str.includes(char)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
};
|
|
9
|
+
const trimStringFromSymbols = (str, characters) => {
|
|
10
|
+
const pattern = new RegExp(`[${characters.join("\\")}]`, "g");
|
|
11
|
+
return str.replace(pattern, "");
|
|
12
|
+
};
|
|
13
|
+
const brackRegex = {
|
|
14
|
+
2: /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g,
|
|
15
|
+
3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
|
|
16
|
+
};
|
|
17
|
+
const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
|
|
18
|
+
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
|
|
19
|
+
return str;
|
|
20
|
+
const reg = brackRegex[options.bracketsLength || 2];
|
|
21
|
+
return str.replace(reg, (_, parentPath, variable) => {
|
|
22
|
+
if (parentPath) {
|
|
23
|
+
const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
|
|
24
|
+
let parentState = state;
|
|
25
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
26
|
+
parentState = parentState.parent;
|
|
27
|
+
if (!parentState) {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const value = parentState[variable.trim()];
|
|
32
|
+
return value !== void 0 ? `${value}` : "";
|
|
33
|
+
} else {
|
|
34
|
+
const value = state[variable.trim()];
|
|
35
|
+
return value !== void 0 ? `${value}` : "";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const lowercaseFirstLetter = (inputString) => {
|
|
40
|
+
return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
|
|
41
|
+
};
|
|
42
|
+
const findKeyPosition = (str, key) => {
|
|
43
|
+
const lines = str.split("\n");
|
|
44
|
+
let startLineNumber = -1;
|
|
45
|
+
let endLineNumber = -1;
|
|
46
|
+
let startColumn = -1;
|
|
47
|
+
let endColumn = -1;
|
|
48
|
+
const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`);
|
|
49
|
+
let braceCount = 0;
|
|
50
|
+
let foundKey = false;
|
|
51
|
+
for (let i = 0; i < lines.length; i++) {
|
|
52
|
+
if (keyPattern.test(lines[i]) && !foundKey) {
|
|
53
|
+
foundKey = true;
|
|
54
|
+
startLineNumber = i + 1;
|
|
55
|
+
startColumn = lines[i].indexOf(key) + 1;
|
|
56
|
+
if (lines[i].includes("{}")) {
|
|
57
|
+
endLineNumber = startLineNumber;
|
|
58
|
+
endColumn = lines[i].indexOf("{}") + 3;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const line = lines[i].slice(startColumn + key.length);
|
|
62
|
+
if (line.includes("{") || line.includes("[")) {
|
|
63
|
+
braceCount = 1;
|
|
64
|
+
} else {
|
|
65
|
+
endLineNumber = i + 1;
|
|
66
|
+
endColumn = lines[i].length + 1;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
} else if (foundKey) {
|
|
70
|
+
braceCount += (lines[i].match(/{/g) || []).length;
|
|
71
|
+
braceCount += (lines[i].match(/\[/g) || []).length;
|
|
72
|
+
braceCount -= (lines[i].match(/}/g) || []).length;
|
|
73
|
+
braceCount -= (lines[i].match(/]/g) || []).length;
|
|
74
|
+
if (braceCount === 0) {
|
|
75
|
+
endLineNumber = i + 1;
|
|
76
|
+
endColumn = lines[i].lastIndexOf("}") !== -1 ? lines[i].lastIndexOf("}") + 2 : lines[i].length + 1;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
startColumn,
|
|
83
|
+
endColumn,
|
|
84
|
+
startLineNumber,
|
|
85
|
+
endLineNumber
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const replaceOctalEscapeSequences = (str) => {
|
|
89
|
+
const octalRegex = /\\([0-7]{1,3})/g;
|
|
90
|
+
return str.replace(octalRegex, (match, p1) => {
|
|
91
|
+
const octalValue = parseInt(p1, 8);
|
|
92
|
+
const char = String.fromCharCode(octalValue);
|
|
93
|
+
return char;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const encodeNewlines = (str) => {
|
|
97
|
+
return str.split("\n").join("/////n").split("`").join("/////tilde").split("$").join("/////dlrsgn");
|
|
98
|
+
};
|
|
99
|
+
const decodeNewlines = (encodedStr) => {
|
|
100
|
+
return encodedStr.split("/////n").join("\n").split("/////tilde").join("`").split("/////dlrsgn").join("$");
|
|
101
|
+
};
|
|
102
|
+
const customEncodeURIComponent = (str) => {
|
|
103
|
+
return str.split("").map((char) => {
|
|
104
|
+
if (/[^a-zA-Z0-9\s]/.test(char)) {
|
|
105
|
+
return "%" + char.charCodeAt(0).toString(16).toUpperCase();
|
|
106
|
+
}
|
|
107
|
+
return char;
|
|
108
|
+
}).join("");
|
|
109
|
+
};
|
|
110
|
+
const customDecodeURIComponent = (encodedStr) => {
|
|
111
|
+
return encodedStr.replace(/%[0-9A-Fa-f]{2}/g, (match) => String.fromCharCode(parseInt(match.slice(1), 16)));
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
customDecodeURIComponent,
|
|
115
|
+
customEncodeURIComponent,
|
|
116
|
+
decodeNewlines,
|
|
117
|
+
encodeNewlines,
|
|
118
|
+
findKeyPosition,
|
|
119
|
+
lowercaseFirstLetter,
|
|
120
|
+
replaceLiteralsWithObjectFields,
|
|
121
|
+
replaceOctalEscapeSequences,
|
|
122
|
+
stringIncludesAny,
|
|
123
|
+
trimStringFromSymbols
|
|
124
|
+
};
|
package/dist/esm/tags.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const HTML_TAGS = {
|
|
2
|
+
root: [
|
|
3
|
+
"body",
|
|
4
|
+
"html"
|
|
5
|
+
],
|
|
6
|
+
head: [
|
|
7
|
+
"title",
|
|
8
|
+
"base",
|
|
9
|
+
"meta",
|
|
10
|
+
"style",
|
|
11
|
+
"noscript",
|
|
12
|
+
"script"
|
|
13
|
+
],
|
|
14
|
+
body: [
|
|
15
|
+
"string",
|
|
16
|
+
"style",
|
|
17
|
+
"fragment",
|
|
18
|
+
"a",
|
|
19
|
+
"abbr",
|
|
20
|
+
"acronym",
|
|
21
|
+
"address",
|
|
22
|
+
"applet",
|
|
23
|
+
"area",
|
|
24
|
+
"article",
|
|
25
|
+
"aside",
|
|
26
|
+
"audio",
|
|
27
|
+
"b",
|
|
28
|
+
"basefont",
|
|
29
|
+
"bdi",
|
|
30
|
+
"bdo",
|
|
31
|
+
"big",
|
|
32
|
+
"blockquote",
|
|
33
|
+
"br",
|
|
34
|
+
"button",
|
|
35
|
+
"canvas",
|
|
36
|
+
"caption",
|
|
37
|
+
"center",
|
|
38
|
+
"cite",
|
|
39
|
+
"code",
|
|
40
|
+
"search",
|
|
41
|
+
"col",
|
|
42
|
+
"colgroup",
|
|
43
|
+
"data",
|
|
44
|
+
"datalist",
|
|
45
|
+
"dd",
|
|
46
|
+
"del",
|
|
47
|
+
"details",
|
|
48
|
+
"dfn",
|
|
49
|
+
"dialog",
|
|
50
|
+
"dir",
|
|
51
|
+
"div",
|
|
52
|
+
"dl",
|
|
53
|
+
"dt",
|
|
54
|
+
"em",
|
|
55
|
+
"embed",
|
|
56
|
+
"fieldset",
|
|
57
|
+
"figcaption",
|
|
58
|
+
"figure",
|
|
59
|
+
"font",
|
|
60
|
+
"footer",
|
|
61
|
+
"form",
|
|
62
|
+
"frame",
|
|
63
|
+
"frameset",
|
|
64
|
+
"h1",
|
|
65
|
+
"h2",
|
|
66
|
+
"h3",
|
|
67
|
+
"h4",
|
|
68
|
+
"h5",
|
|
69
|
+
"h6",
|
|
70
|
+
"head",
|
|
71
|
+
"header",
|
|
72
|
+
"hr",
|
|
73
|
+
"i",
|
|
74
|
+
"iframe",
|
|
75
|
+
"img",
|
|
76
|
+
"input",
|
|
77
|
+
"ins",
|
|
78
|
+
"kbd",
|
|
79
|
+
"label",
|
|
80
|
+
"legend",
|
|
81
|
+
"li",
|
|
82
|
+
"link",
|
|
83
|
+
"main",
|
|
84
|
+
"map",
|
|
85
|
+
"mark",
|
|
86
|
+
"meter",
|
|
87
|
+
"nav",
|
|
88
|
+
"noframes",
|
|
89
|
+
"noscript",
|
|
90
|
+
"object",
|
|
91
|
+
"ol",
|
|
92
|
+
"optgroup",
|
|
93
|
+
"option",
|
|
94
|
+
"output",
|
|
95
|
+
"p",
|
|
96
|
+
"param",
|
|
97
|
+
"picture",
|
|
98
|
+
"pre",
|
|
99
|
+
"progress",
|
|
100
|
+
"hgroup",
|
|
101
|
+
"q",
|
|
102
|
+
"rp",
|
|
103
|
+
"rt",
|
|
104
|
+
"ruby",
|
|
105
|
+
"s",
|
|
106
|
+
"samp",
|
|
107
|
+
"script",
|
|
108
|
+
"section",
|
|
109
|
+
"select",
|
|
110
|
+
"small",
|
|
111
|
+
"source",
|
|
112
|
+
"span",
|
|
113
|
+
"strike",
|
|
114
|
+
"strong",
|
|
115
|
+
"sub",
|
|
116
|
+
"summary",
|
|
117
|
+
"sup",
|
|
118
|
+
"table",
|
|
119
|
+
"tbody",
|
|
120
|
+
"td",
|
|
121
|
+
"template",
|
|
122
|
+
"hgroup",
|
|
123
|
+
"textarea",
|
|
124
|
+
"tfoot",
|
|
125
|
+
"th",
|
|
126
|
+
"thead",
|
|
127
|
+
"time",
|
|
128
|
+
"tr",
|
|
129
|
+
"track",
|
|
130
|
+
"tt",
|
|
131
|
+
"u",
|
|
132
|
+
"ul",
|
|
133
|
+
"var",
|
|
134
|
+
"video",
|
|
135
|
+
"wbr",
|
|
136
|
+
// SVG
|
|
137
|
+
"svg",
|
|
138
|
+
"path"
|
|
139
|
+
]
|
|
140
|
+
};
|
|
141
|
+
const isValidHtmlTag = (arg) => HTML_TAGS.body.includes(arg);
|
|
142
|
+
export {
|
|
143
|
+
HTML_TAGS,
|
|
144
|
+
isValidHtmlTag
|
|
145
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isHtmlElement, isNode } from "./node";
|
|
2
|
+
const isObject = (arg) => {
|
|
3
|
+
if (arg === null)
|
|
4
|
+
return false;
|
|
5
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
6
|
+
};
|
|
7
|
+
const isString = (arg) => typeof arg === "string";
|
|
8
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
9
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
10
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
11
|
+
const isNull = (arg) => arg === null;
|
|
12
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
13
|
+
const isDate = (d) => d instanceof Date;
|
|
14
|
+
const isObjectLike = (arg) => {
|
|
15
|
+
if (arg === null)
|
|
16
|
+
return false;
|
|
17
|
+
return typeof arg === "object";
|
|
18
|
+
};
|
|
19
|
+
const isDefined = (arg) => {
|
|
20
|
+
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isDate(arg) || isNull(arg);
|
|
21
|
+
};
|
|
22
|
+
const isUndefined = (arg) => {
|
|
23
|
+
return arg === void 0;
|
|
24
|
+
};
|
|
25
|
+
const TYPES = {
|
|
26
|
+
boolean: isBoolean,
|
|
27
|
+
array: isArray,
|
|
28
|
+
object: isObject,
|
|
29
|
+
string: isString,
|
|
30
|
+
date: isDate,
|
|
31
|
+
number: isNumber,
|
|
32
|
+
null: isNull,
|
|
33
|
+
function: isFunction,
|
|
34
|
+
objectLike: isObjectLike,
|
|
35
|
+
node: isNode,
|
|
36
|
+
htmlElement: isHtmlElement,
|
|
37
|
+
defined: isDefined
|
|
38
|
+
};
|
|
39
|
+
const is = (arg) => {
|
|
40
|
+
return (...args) => {
|
|
41
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const isNot = (arg) => {
|
|
45
|
+
return (...args) => {
|
|
46
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
TYPES,
|
|
51
|
+
is,
|
|
52
|
+
isArray,
|
|
53
|
+
isBoolean,
|
|
54
|
+
isDate,
|
|
55
|
+
isDefined,
|
|
56
|
+
isFunction,
|
|
57
|
+
isNot,
|
|
58
|
+
isNull,
|
|
59
|
+
isNumber,
|
|
60
|
+
isObject,
|
|
61
|
+
isObjectLike,
|
|
62
|
+
isString,
|
|
63
|
+
isUndefined
|
|
64
|
+
};
|
package/object.js
CHANGED
|
@@ -295,7 +295,7 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
295
295
|
if (isArray(value)) {
|
|
296
296
|
str += '[\n'
|
|
297
297
|
for (const element of value) {
|
|
298
|
-
if (
|
|
298
|
+
if (isObjectLike(element) && element !== null) {
|
|
299
299
|
str += `${spaces} ${objectToString(element, indent + 2)},\n`
|
|
300
300
|
} else if (isString(element)) {
|
|
301
301
|
// if (element.includes('\n')) str += spaces + ' ' + '`' + element + '`,\n'
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.159",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"kalduna": "./index.js",
|
|
10
|
+
"kalduna": "./dist/esm/index.js",
|
|
11
11
|
"default": "./dist/cjs/index.js",
|
|
12
|
-
"import": "./index.js",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
13
|
"require": "./dist/cjs/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
23
23
|
"build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
24
24
|
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
25
|
-
"build": "yarn build:cjs",
|
|
26
|
-
"prepublish": "rimraf -I dist
|
|
25
|
+
"build": "yarn build:cjs; yarn build:esm",
|
|
26
|
+
"prepublish": "rimraf -I dist; yarn build; yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "7595b1077d3096c3ee7b1da5eef02aa9248f2ed6",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|