@rokkit/core 1.0.0-next.93 → 1.0.0-next.94
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 +7 -7
- package/src/mapping.js +27 -11
- package/src/string.js +7 -6
- package/src/types.js +1 -1
- package/src/utils.js +27 -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.94",
|
|
4
4
|
"description": "Core components, actions and stores for svelte apps.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
|
16
16
|
"@testing-library/svelte": "^4.1.0",
|
|
17
|
-
"@types/ramda": "^0.29.
|
|
17
|
+
"@types/ramda": "^0.29.12",
|
|
18
18
|
"@vitest/coverage-v8": "^1.4.0",
|
|
19
19
|
"@vitest/ui": "~1.4.0",
|
|
20
20
|
"jsdom": "^24.0.0",
|
|
21
21
|
"svelte": "^4.2.12",
|
|
22
|
-
"typescript": "^5.4.
|
|
23
|
-
"vite": "^5.2.
|
|
22
|
+
"typescript": "^5.4.4",
|
|
23
|
+
"vite": "^5.2.8",
|
|
24
24
|
"vitest": "~1.4.0",
|
|
25
|
-
"shared-config": "1.0.0-next.
|
|
26
|
-
"validators": "1.0.0-next.
|
|
25
|
+
"shared-config": "1.0.0-next.94",
|
|
26
|
+
"validators": "1.0.0-next.94"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"src/**/*.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"./package.json": "./package.json",
|
|
36
36
|
"./constants": "./src/constants.js",
|
|
37
37
|
".": {
|
|
38
|
-
"types": "./dist/
|
|
38
|
+
"types": "./dist/types.d.ts",
|
|
39
39
|
"import": "./src/index.js",
|
|
40
40
|
"svelte": "./src/index.js"
|
|
41
41
|
}
|
package/src/mapping.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultFields } from './constants'
|
|
2
|
-
import { isObject } from '
|
|
2
|
+
import { toString, isObject } from './utils'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Get the component to be used to render the item.
|
|
@@ -10,7 +10,7 @@ import { isObject } from '.'
|
|
|
10
10
|
* @param {import('./types.js').ComponentMap} using
|
|
11
11
|
*/
|
|
12
12
|
export function getComponent(value, fields, using) {
|
|
13
|
-
return fields.component &&
|
|
13
|
+
return fields.component && isObject(value)
|
|
14
14
|
? using[value[fields.component]] ?? using.default
|
|
15
15
|
: using.default
|
|
16
16
|
}
|
|
@@ -47,20 +47,36 @@ export function getValue(node, fields = defaultFields) {
|
|
|
47
47
|
* Get the text for the item. If the text is an object,
|
|
48
48
|
* it will use the field mapping to determine which attribute to get.
|
|
49
49
|
*
|
|
50
|
-
* @param {*}
|
|
50
|
+
* @param {*} node
|
|
51
51
|
* @param {import('./types').FieldMapping} fields
|
|
52
|
-
* @returns {
|
|
52
|
+
* @returns {string}
|
|
53
53
|
*/
|
|
54
54
|
export function getText(node, fields = defaultFields) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return value != null
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
const value = isObject(node) ? node[fields.text] : node
|
|
56
|
+
return value
|
|
57
|
+
// return value != null
|
|
58
|
+
// ? isObject(value)
|
|
59
|
+
// ? JSON.stringify(value, null, 2)
|
|
60
|
+
// : value.toString()
|
|
61
|
+
// : value
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Get the formatted text for the item. If the text is an object, use the field mapping to determine
|
|
66
|
+
* which attribute to get currency. Use the formatter or identity function to format the text.
|
|
67
|
+
*
|
|
68
|
+
* @param {*} node
|
|
69
|
+
* @param {import('./types').FieldMapping} fields
|
|
70
|
+
* @param {function} formatter
|
|
71
|
+
* @returns {*}
|
|
72
|
+
*/
|
|
73
|
+
export function getFormattedText(node, fields = defaultFields, formatter = toString) {
|
|
74
|
+
const value = isObject(node) ? node[fields.text] : node
|
|
75
|
+
const currency = getAttribute(node, fields.currency)
|
|
76
|
+
const formatValue = typeof formatter === 'function' ? formatter : toString
|
|
77
|
+
|
|
78
|
+
return currency ? formatValue(value, currency) : formatValue(value)
|
|
79
|
+
}
|
|
64
80
|
/**
|
|
65
81
|
* Gets the attribute from the node
|
|
66
82
|
* @param {*} node
|
package/src/string.js
CHANGED
|
@@ -25,8 +25,8 @@ export function toPascalCase(text) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Convert a PascalCase string to snake case with separator as hyphen
|
|
27
27
|
*
|
|
28
|
-
* @param {
|
|
29
|
-
* @returns
|
|
28
|
+
* @param {string} text
|
|
29
|
+
* @returns {string}
|
|
30
30
|
*/
|
|
31
31
|
export function toHyphenCase(text) {
|
|
32
32
|
return text
|
|
@@ -40,11 +40,12 @@ export function toHyphenCase(text) {
|
|
|
40
40
|
*
|
|
41
41
|
* @param {String} a hyphen separates string
|
|
42
42
|
* @param {String} b hyphen separates string
|
|
43
|
-
* @
|
|
43
|
+
* @param {string} separator - separator to split the string
|
|
44
|
+
* @returns {Number} -1, 0, 1 based on comparison
|
|
44
45
|
*/
|
|
45
|
-
export function sortByParts(a, b) {
|
|
46
|
-
const partsOfA = a.split(
|
|
47
|
-
const partsOfB = b.split(
|
|
46
|
+
export function sortByParts(a, b, separator = '-') {
|
|
47
|
+
const partsOfA = a.split(separator)
|
|
48
|
+
const partsOfB = b.split(separator)
|
|
48
49
|
|
|
49
50
|
let result = compareStrings(partsOfA[0], partsOfB[0])
|
|
50
51
|
if (result === 0) result = partsOfA.length - partsOfB.length
|
package/src/types.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -17,6 +17,26 @@ export function isObject(val) {
|
|
|
17
17
|
return typeof val === 'object' && val !== null && !(val instanceof Date)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Converts the value to a string. If the value is an object, it will convert it to a JSON string.
|
|
22
|
+
*
|
|
23
|
+
* @param {*} value
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function toString(value) {
|
|
27
|
+
if (value === null || value === undefined) return value
|
|
28
|
+
if (isObject(value)) return JSON.stringify(value, null, 2)
|
|
29
|
+
return value.toString()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates icon shortcuts for a collection of icons
|
|
34
|
+
*
|
|
35
|
+
* @param {string[]} icons
|
|
36
|
+
* @param {string} collection
|
|
37
|
+
* @param {string} variants
|
|
38
|
+
* @returns {Object}
|
|
39
|
+
*/
|
|
20
40
|
export function iconShortcuts(icons, collection, variants) {
|
|
21
41
|
const suffix = variants ? `-${variants}` : ''
|
|
22
42
|
const shortcuts = !collection
|
|
@@ -32,6 +52,13 @@ export function iconShortcuts(icons, collection, variants) {
|
|
|
32
52
|
return shortcuts
|
|
33
53
|
}
|
|
34
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Scales the path by the size
|
|
57
|
+
*
|
|
58
|
+
* @param {number} size
|
|
59
|
+
* @param {string|number} x
|
|
60
|
+
* @returns {string|number}
|
|
61
|
+
*/
|
|
35
62
|
export function scaledPath(size, x) {
|
|
36
63
|
if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
|
|
37
64
|
return typeof x === 'number' ? x * size : x
|