@rokkit/core 1.0.0-next.37 → 1.0.0-next.39
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/package.json +2 -4
- package/src/constants.js +4 -4
- package/src/mapping.js +46 -0
- package/src/parser.js +20 -13
- package/src/utils.js +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/core",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.39",
|
|
4
4
|
"description": "Core components, actions and stores for svelte apps.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,6 @@
|
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@sveltejs/vite-plugin-svelte": "^2.4.3",
|
|
17
17
|
"@testing-library/svelte": "^4.0.3",
|
|
18
|
-
"@vitest/coverage-c8": "^0.33.0",
|
|
19
|
-
"@vitest/coverage-istanbul": "^0.33.0",
|
|
20
18
|
"@vitest/coverage-v8": "^0.33.0",
|
|
21
19
|
"@vitest/ui": "~0.33.0",
|
|
22
20
|
"jsdom": "^22.1.0",
|
|
@@ -25,7 +23,7 @@
|
|
|
25
23
|
"validators": "latest",
|
|
26
24
|
"vite": "^4.4.7",
|
|
27
25
|
"vitest": "~0.33.0",
|
|
28
|
-
"shared-config": "1.0.0-next.
|
|
26
|
+
"shared-config": "1.0.0-next.39"
|
|
29
27
|
},
|
|
30
28
|
"files": [
|
|
31
29
|
"src/**/*.js",
|
package/src/constants.js
CHANGED
|
@@ -52,10 +52,10 @@ export const defaultIcons = [
|
|
|
52
52
|
'state-success',
|
|
53
53
|
'state-info',
|
|
54
54
|
'state-unknown',
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
55
|
+
'badge-fail',
|
|
56
|
+
'badge-warn',
|
|
57
|
+
'badge-pass',
|
|
58
|
+
'badge-unknown'
|
|
59
59
|
]
|
|
60
60
|
|
|
61
61
|
export const defaultOptions = {
|
package/src/mapping.js
CHANGED
|
@@ -38,3 +38,49 @@ export function getValue(node, fields = defaultFields) {
|
|
|
38
38
|
export function getText(node, fields = defaultFields) {
|
|
39
39
|
return typeof node === 'object' && node !== null ? node[fields.text] : node
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if the current item is a parent
|
|
44
|
+
*
|
|
45
|
+
* @param {*} item
|
|
46
|
+
* @param {import('./types').FieldMapping} fields
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
export function hasChildren(item, fields) {
|
|
50
|
+
return (
|
|
51
|
+
item != null &&
|
|
52
|
+
typeof item === 'object' &&
|
|
53
|
+
fields.children in item &&
|
|
54
|
+
Array.isArray(item[fields.children])
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if the current item is a parent and is expanded
|
|
60
|
+
*
|
|
61
|
+
* @param {*} item
|
|
62
|
+
* @param {import('./types').FieldMapping} fields
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function isExpanded(item, fields) {
|
|
66
|
+
if (item == null) return false
|
|
67
|
+
if (!hasChildren(item, fields)) return false
|
|
68
|
+
if (fields.isOpen in item) {
|
|
69
|
+
return item[fields.isOpen]
|
|
70
|
+
}
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Verify if at least one item has children
|
|
76
|
+
*
|
|
77
|
+
* @param {Array<*>} items
|
|
78
|
+
* @param {import('./types').FieldMapping} fields
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
export function isNested(items, fields) {
|
|
82
|
+
for (let i = 0; i < items.length; i++) {
|
|
83
|
+
if (hasChildren(items[i], fields)) return true
|
|
84
|
+
}
|
|
85
|
+
return false
|
|
86
|
+
}
|
package/src/parser.js
CHANGED
|
@@ -15,28 +15,19 @@ export function parseFilters(string) {
|
|
|
15
15
|
// Split the string into an array of tokens
|
|
16
16
|
const tokens = string.matchAll(regex)
|
|
17
17
|
let search = string
|
|
18
|
+
|
|
18
19
|
// Iterate over the tokens
|
|
19
20
|
for (const token of tokens) {
|
|
20
21
|
// Extract the named groups from the token
|
|
21
22
|
let { group, column, operator, value } = token.groups
|
|
22
23
|
search = search.replace(group, '').trim()
|
|
23
24
|
|
|
24
|
-
operator = operator
|
|
25
|
-
|
|
26
|
-
.replace('=>', '>=')
|
|
27
|
-
.replace('=<', '<=')
|
|
28
|
-
|
|
29
|
-
if (value) {
|
|
30
|
-
value = !isNaN(parseInt(value)) ? parseInt(value) : removeQuotes(value)
|
|
25
|
+
operator = replaceOperators(operator)
|
|
26
|
+
value = processValue(value, operator)
|
|
31
27
|
|
|
32
|
-
if (operator.includes('~')) {
|
|
33
|
-
value = operator.includes('*')
|
|
34
|
-
? new RegExp(value, 'i')
|
|
35
|
-
: new RegExp(value)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
28
|
if (column && value) results.push({ column, operator, value })
|
|
39
29
|
}
|
|
30
|
+
|
|
40
31
|
if (search.length > 0) {
|
|
41
32
|
results.push({
|
|
42
33
|
operator: '~*',
|
|
@@ -47,6 +38,22 @@ export function parseFilters(string) {
|
|
|
47
38
|
return results
|
|
48
39
|
}
|
|
49
40
|
|
|
41
|
+
function replaceOperators(operator) {
|
|
42
|
+
return operator.replace(':', '~*').replace('=>', '>=').replace('=<', '<=')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function processValue(value, operator) {
|
|
46
|
+
// if (!value) return value
|
|
47
|
+
|
|
48
|
+
value = !isNaN(parseInt(value)) ? parseInt(value) : removeQuotes(value)
|
|
49
|
+
|
|
50
|
+
if (operator.includes('~')) {
|
|
51
|
+
value = operator.includes('*') ? new RegExp(value, 'i') : new RegExp(value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return value
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
function removeQuotes(str) {
|
|
51
58
|
const quoteMatch = str.match(/^"([^"]+)"$/)
|
|
52
59
|
return quoteMatch ? quoteMatch[1] : str
|
package/src/utils.js
CHANGED