@linkurious/ogma-linkurious-parser 3.1.11 → 4.0.0
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/captions/captions.js +39 -50
- package/dist/captions/captions.js.map +1 -1
- package/dist/filters/filters.js +54 -76
- package/dist/filters/filters.js.map +1 -1
- package/dist/ogma/features/OgmaStore.js +15 -30
- package/dist/ogma/features/OgmaStore.js.map +1 -1
- package/dist/ogma/features/captions.js +42 -87
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/reactive.js +57 -75
- package/dist/ogma/features/reactive.js.map +1 -1
- package/dist/ogma/features/selectors.js +15 -15
- package/dist/ogma/features/selectors.js.map +1 -1
- package/dist/ogma/features/styles.js +114 -137
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.js +46 -94
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.js +138 -221
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/edgeAttributes.js +30 -46
- package/dist/styles/edgeAttributes.js.map +1 -1
- package/dist/styles/itemAttributes.js +31 -41
- package/dist/styles/itemAttributes.js.map +1 -1
- package/dist/styles/nodeAttributes.js +48 -71
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/dist/styles/styleRule.js +56 -68
- package/dist/styles/styleRule.js.map +1 -1
- package/dist/styles/styleRules.js +149 -192
- package/dist/styles/styleRules.js.map +1 -1
- package/dist/tools/ogmaTool.js +27 -30
- package/dist/tools/ogmaTool.js.map +1 -1
- package/dist/tools/tools.js +87 -91
- package/dist/tools/tools.js.map +1 -1
- package/package.json +5 -5
package/dist/tools/ogmaTool.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function OgmaTools() {
|
|
7
|
-
}
|
|
3
|
+
const tools_1 = require("./tools");
|
|
4
|
+
const colorPalette_1 = require("./colorPalette");
|
|
5
|
+
class OgmaTools {
|
|
8
6
|
/**
|
|
9
7
|
* Get the amount of hidden neighbors from a list of nodes
|
|
10
8
|
*
|
|
11
9
|
* @param nodes
|
|
12
10
|
*/
|
|
13
|
-
|
|
14
|
-
return nodes.reduce(
|
|
15
|
-
|
|
11
|
+
static getHiddenNeighbors(nodes) {
|
|
12
|
+
return nodes.reduce((result, node) => {
|
|
13
|
+
const statistics = node.getData('statistics');
|
|
16
14
|
if (statistics !== undefined) {
|
|
17
|
-
|
|
15
|
+
const hiddenNeighbors = statistics.degree !== undefined && !statistics.supernode
|
|
18
16
|
? statistics.degree - tools_1.Tools.getDegreeWithoutSelfConnection(node)
|
|
19
17
|
: statistics.supernodeDegree;
|
|
20
18
|
if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {
|
|
@@ -23,39 +21,39 @@ var OgmaTools = /** @class */ (function () {
|
|
|
23
21
|
}
|
|
24
22
|
return result;
|
|
25
23
|
}, 0);
|
|
26
|
-
}
|
|
24
|
+
}
|
|
27
25
|
/**
|
|
28
26
|
* Return the visible degree of a node without self connection (self edge)
|
|
29
27
|
*
|
|
30
28
|
* @param {Node} node
|
|
31
29
|
* @return {number}
|
|
32
30
|
*/
|
|
33
|
-
|
|
31
|
+
static getDegreeWithoutSelfConnection(node) {
|
|
34
32
|
return node.getAdjacentNodes({ policy: 'exclude-sources', filter: 'all' }).size;
|
|
35
|
-
}
|
|
33
|
+
}
|
|
36
34
|
/**
|
|
37
35
|
* Return true if the color tone is "bright"
|
|
38
36
|
*
|
|
39
37
|
* @param {string} color
|
|
40
38
|
* @returns {boolean}
|
|
41
39
|
*/
|
|
42
|
-
|
|
40
|
+
static isBright(color) {
|
|
43
41
|
if (color === null || !tools_1.Tools.isStringFilled(color)) {
|
|
44
42
|
return true;
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const hexRegExp = /#[A-Fa-f0-9]{3,6}/;
|
|
45
|
+
const rgbRegExp = /^rgb\(\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*,\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*,\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*\)$/i;
|
|
46
|
+
const rgbaRegExp = /^rgba\(\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*,\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*,\s*([01]?\d\d?|2[0-4]\d|25[0-5])\s*,\s*(?:0|1|0?\.\d+)\s*\)$/i;
|
|
47
|
+
let rgb;
|
|
50
48
|
if (hexRegExp.test(color)) {
|
|
51
49
|
if (color.length < 5) {
|
|
52
50
|
color += color.slice(1);
|
|
53
51
|
}
|
|
54
52
|
color = color.replace('#', '');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rgb =
|
|
53
|
+
const r = parseInt(color[0].toString() + color[1].toString(), 16);
|
|
54
|
+
const g = parseInt(color[2].toString() + color[3].toString(), 16);
|
|
55
|
+
const b = parseInt(color[4].toString() + color[5].toString(), 16);
|
|
56
|
+
rgb = `rgb(${r}, ${g}, ${b})`;
|
|
59
57
|
}
|
|
60
58
|
else if (rgbRegExp.test(color) ||
|
|
61
59
|
rgbaRegExp.test(color) ||
|
|
@@ -67,23 +65,22 @@ var OgmaTools = /** @class */ (function () {
|
|
|
67
65
|
else {
|
|
68
66
|
return true;
|
|
69
67
|
}
|
|
70
|
-
|
|
68
|
+
const [r, g, b] = rgb
|
|
71
69
|
.replace(/\s/g, '')
|
|
72
70
|
.match(/rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,\d{1,3})?\)/)
|
|
73
|
-
.slice(1, 4)
|
|
71
|
+
.slice(1, 4);
|
|
74
72
|
if (!tools_1.Tools.isDefined(r) || !tools_1.Tools.isDefined(g) || !tools_1.Tools.isDefined(b)) {
|
|
75
73
|
console.warn('The given color is not a valid rgb formatted color');
|
|
76
74
|
return true;
|
|
77
75
|
}
|
|
78
76
|
return (+r * 299 + +g * 587 + +b * 114) / 1000 > 255 * 0.7;
|
|
79
|
-
}
|
|
80
|
-
|
|
77
|
+
}
|
|
78
|
+
static isNode(item) {
|
|
81
79
|
return item.isNode;
|
|
82
|
-
}
|
|
83
|
-
|
|
80
|
+
}
|
|
81
|
+
static isNodeList(items) {
|
|
84
82
|
return items.isNode;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
88
85
|
exports.OgmaTools = OgmaTools;
|
|
89
86
|
//# sourceMappingURL=ogmaTool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ogmaTool.js","sourceRoot":"","sources":["../../src/tools/ogmaTool.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,
|
|
1
|
+
{"version":3,"file":"ogmaTool.js","sourceRoot":"","sources":["../../src/tools/ogmaTool.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,mCAA8B;AAC9B,iDAA2C;AAE3C,MAAa,SAAS;IACpB;;;;OAIG;IACI,MAAM,CAAC,kBAAkB,CAAC,KAAuC;QACtE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,MAAc,EAAE,IAAkC,EAAE,EAAE;YACzE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC5B,MAAM,eAAe,GACnB,UAAU,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,SAAS;oBACtD,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,aAAK,CAAC,8BAA8B,CAAC,IAAI,CAAC;oBAChE,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC;gBACjC,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,GAAG,CAAC,EAAE;oBACxD,OAAO,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC;i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E,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AA3FD,8BA2FC","sourcesContent":["'use strict';\nimport {Color, NodeList, Node, EdgeList, Edge} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {Tools} from './tools';\nimport {HTML_COLORS} from './colorPalette';\n\nexport class OgmaTools {\n /**\n * Get the amount of hidden neighbors from a list of nodes\n *\n * @param nodes\n */\n public static getHiddenNeighbors(nodes: NodeList<LkNodeData, LkEdgeData>): number {\n return nodes.reduce((result: number, node: Node<LkNodeData, LkEdgeData>) => {\n const statistics = node.getData('statistics');\n if (statistics !== undefined) {\n const hiddenNeighbors =\n statistics.degree !== undefined && !statistics.supernode\n ? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)\n : statistics.supernodeDegree;\n if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {\n return (result += hiddenNeighbors);\n }\n }\n return result;\n }, 0);\n }\n\n /**\n * Return the visible degree of a node without self connection (self edge)\n *\n * @param {Node} node\n * @return {number}\n */\n public static getDegreeWithoutSelfConnection(node: Node<LkNodeData, LkEdgeData>): number {\n return node.getAdjacentNodes({policy: 'exclude-sources', filter: 'all'}).size;\n }\n\n /**\n * Return true if the color tone is \"bright\"\n *\n * @param {string} color\n * @returns {boolean}\n */\n public static isBright(color: Color): boolean {\n if (color === null || !Tools.isStringFilled(color)) {\n return true;\n }\n const hexRegExp = /#[A-Fa-f0-9]{3,6}/;\n const rgbRegExp = /^rgb\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$/i;\n const rgbaRegExp = /^rgba\\(\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|1|0?\\.\\d+)\\s*\\)$/i;\n let rgb: string;\n\n if (hexRegExp.test(color)) {\n if (color.length < 5) {\n color += color.slice(1);\n }\n color = color.replace('#', '');\n const r = parseInt(color[0].toString() + color[1].toString(), 16);\n const g = parseInt(color[2].toString() + color[3].toString(), 16);\n const b = parseInt(color[4].toString() + color[5].toString(), 16);\n rgb = `rgb(${r}, ${g}, ${b})`;\n } else if (\n rgbRegExp.test(color) ||\n rgbaRegExp.test(color) ||\n HTML_COLORS[color.toLowerCase()] !== undefined\n ) {\n rgb = Tools.isDefined(HTML_COLORS[color.toLowerCase()])\n ? HTML_COLORS[color.toLowerCase()]['rgb']\n : color;\n } else {\n return true;\n }\n\n const [r, g, b] = rgb\n .replace(/\\s/g, '')\n .match(/rgba?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})(,\\d{1,3})?\\)/)!\n .slice(1, 4);\n\n if (!Tools.isDefined(r) || !Tools.isDefined(g) || !Tools.isDefined(b)) {\n console.warn('The given color is not a valid rgb formatted color');\n return true;\n }\n return (+r * 299 + +g * 587 + +b * 114) / 1000 > 255 * 0.7;\n }\n\n public static isNode(\n item: Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData>\n ): item is Node<LkNodeData, LkEdgeData> {\n return item.isNode;\n }\n\n public static isNodeList(\n items: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>\n ): items is NodeList<LkNodeData, LkEdgeData> {\n return items.isNode;\n }\n}\n"]}
|
package/dist/tools/tools.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
7
|
+
const sortBy_1 = __importDefault(require("lodash/sortBy"));
|
|
8
8
|
exports.sortBy = sortBy_1.default;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const rest_client_1 = require("@linkurious/rest-client");
|
|
10
|
+
const URL_PATTERN = /([a-zA-Z][a-zA-Z0-9\+\-\.]*:\/\/[^\s]+)/i;
|
|
11
|
+
const IMAGE_PATTERN = /\S+\.(gif|jpe?g|tiff|png|bmp|svg)$/i;
|
|
12
12
|
exports.CAPTION_HEURISTIC = [
|
|
13
13
|
'label',
|
|
14
14
|
'Label',
|
|
@@ -18,35 +18,32 @@ exports.CAPTION_HEURISTIC = [
|
|
|
18
18
|
'Title',
|
|
19
19
|
'rdfs:label'
|
|
20
20
|
];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
Tools.isEqual = function (v1, v2) {
|
|
21
|
+
class Tools {
|
|
22
|
+
static isEqual(v1, v2) {
|
|
25
23
|
return isEqual_1.default(v1, v2);
|
|
26
|
-
}
|
|
24
|
+
}
|
|
27
25
|
/**
|
|
28
26
|
* Check that a value is defined : not null and not undefined
|
|
29
27
|
*
|
|
30
28
|
* @param {any} value
|
|
31
29
|
* @return {boolean}
|
|
32
30
|
*/
|
|
33
|
-
|
|
31
|
+
static isDefined(value) {
|
|
34
32
|
return value !== undefined && value !== null;
|
|
35
|
-
}
|
|
33
|
+
}
|
|
36
34
|
/**
|
|
37
35
|
* Truncate a text
|
|
38
36
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var suffix = '\u2026';
|
|
37
|
+
static truncate(value, position, limit = 0) {
|
|
38
|
+
const suffix = '\u2026';
|
|
42
39
|
if (!Tools.isDefined(value)) {
|
|
43
|
-
return
|
|
40
|
+
return ``;
|
|
44
41
|
}
|
|
45
|
-
|
|
42
|
+
const valueToTruncate = `${value}`;
|
|
46
43
|
if (valueToTruncate.length <= limit + 1) {
|
|
47
44
|
return valueToTruncate;
|
|
48
45
|
}
|
|
49
|
-
|
|
46
|
+
const fixedLimit = limit - 1;
|
|
50
47
|
switch (position) {
|
|
51
48
|
case 'middle':
|
|
52
49
|
return (valueToTruncate.substring(0, Math.ceil(fixedLimit / 2)) +
|
|
@@ -55,33 +52,33 @@ var Tools = /** @class */ (function () {
|
|
|
55
52
|
case 'end':
|
|
56
53
|
return valueToTruncate.substring(0, fixedLimit) + suffix;
|
|
57
54
|
}
|
|
58
|
-
}
|
|
55
|
+
}
|
|
59
56
|
/**
|
|
60
57
|
* Return a value from a nested object depending on a keyPath
|
|
61
58
|
*/
|
|
62
|
-
|
|
63
|
-
return path.reduce(
|
|
64
|
-
}
|
|
59
|
+
static getIn(ref, path) {
|
|
60
|
+
return path.reduce((p, c) => (p && p[c] !== undefined ? p[c] : undefined), ref);
|
|
61
|
+
}
|
|
65
62
|
/**
|
|
66
63
|
* Return a clone of an object
|
|
67
64
|
*/
|
|
68
|
-
|
|
65
|
+
static clone(o) {
|
|
69
66
|
return typeof o === 'object'
|
|
70
|
-
? JSON.parse(JSON.stringify(o,
|
|
67
|
+
? JSON.parse(JSON.stringify(o, (k, v) => {
|
|
71
68
|
return v instanceof Set ? {} : v;
|
|
72
69
|
}))
|
|
73
70
|
: o;
|
|
74
|
-
}
|
|
71
|
+
}
|
|
75
72
|
/**
|
|
76
73
|
* Get the amount of hidden neighbors from a list of nodes
|
|
77
74
|
*
|
|
78
75
|
* @param nodes
|
|
79
76
|
*/
|
|
80
|
-
|
|
81
|
-
return nodes.reduce(
|
|
82
|
-
|
|
77
|
+
static getHiddenNeighbors(nodes) {
|
|
78
|
+
return nodes.reduce((result, node) => {
|
|
79
|
+
const statistics = node.getData('statistics');
|
|
83
80
|
if (statistics !== undefined) {
|
|
84
|
-
|
|
81
|
+
const hiddenNeighbors = statistics.degree !== undefined && !statistics.supernode
|
|
85
82
|
? statistics.degree - Tools.getDegreeWithoutSelfConnection(node)
|
|
86
83
|
: statistics.supernodeDegree;
|
|
87
84
|
if (hiddenNeighbors !== undefined && hiddenNeighbors > 0) {
|
|
@@ -90,23 +87,23 @@ var Tools = /** @class */ (function () {
|
|
|
90
87
|
}
|
|
91
88
|
return result;
|
|
92
89
|
}, 0);
|
|
93
|
-
}
|
|
90
|
+
}
|
|
94
91
|
/**
|
|
95
92
|
* Return the visible degree of a node without self connection (self edge)
|
|
96
93
|
*
|
|
97
94
|
* @param {Node} node
|
|
98
95
|
* @return {number}
|
|
99
96
|
*/
|
|
100
|
-
|
|
97
|
+
static getDegreeWithoutSelfConnection(node) {
|
|
101
98
|
return node.getAdjacentNodes({ policy: 'exclude-sources', filter: 'raw' }).size;
|
|
102
|
-
}
|
|
99
|
+
}
|
|
103
100
|
/**
|
|
104
101
|
* Return a formatted version of a number
|
|
105
102
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
static formatNumber(number) {
|
|
104
|
+
let div = 1;
|
|
105
|
+
let suffix = '';
|
|
106
|
+
const sign = number < 0 ? '-' : '';
|
|
110
107
|
number = Math.abs(number);
|
|
111
108
|
if (number >= 1000000) {
|
|
112
109
|
div = 1000000;
|
|
@@ -116,7 +113,7 @@ var Tools = /** @class */ (function () {
|
|
|
116
113
|
div = 1000;
|
|
117
114
|
suffix = 'k';
|
|
118
115
|
}
|
|
119
|
-
|
|
116
|
+
const nn = number / div;
|
|
120
117
|
// if there is a decimal value and nn < 10
|
|
121
118
|
if (nn < 10 && nn % 1 !== 0) {
|
|
122
119
|
return sign + nn.toFixed(1) + suffix;
|
|
@@ -124,44 +121,44 @@ var Tools = /** @class */ (function () {
|
|
|
124
121
|
else {
|
|
125
122
|
return sign + Math.floor(nn) + suffix;
|
|
126
123
|
}
|
|
127
|
-
}
|
|
124
|
+
}
|
|
128
125
|
/**
|
|
129
126
|
* Return true if a string is not composed only by invisible char
|
|
130
127
|
*
|
|
131
128
|
* @param {string} value
|
|
132
129
|
* @return {boolean}
|
|
133
130
|
*/
|
|
134
|
-
|
|
131
|
+
static isStringFilled(value) {
|
|
135
132
|
return value.trim() !== '';
|
|
136
|
-
}
|
|
137
|
-
|
|
133
|
+
}
|
|
134
|
+
static getValueFromLkProperty(property) {
|
|
138
135
|
if (typeof property === 'object' && 'type' in property) {
|
|
139
136
|
if (!('original' in property) && !('value' in property)) {
|
|
140
137
|
return null;
|
|
141
138
|
}
|
|
142
139
|
if ('original' in property) {
|
|
143
|
-
return
|
|
140
|
+
return `${property.original}`;
|
|
144
141
|
}
|
|
145
142
|
if ('value' in property) {
|
|
146
143
|
return Tools.formatDate(new Date(new Date(property.value).getTime() + Tools.timezoneToMilliseconds(property.timezone)).toISOString());
|
|
147
144
|
}
|
|
148
145
|
}
|
|
149
146
|
return property;
|
|
150
|
-
}
|
|
147
|
+
}
|
|
151
148
|
/**
|
|
152
149
|
* Return a formatted date as a string
|
|
153
150
|
*/
|
|
154
|
-
|
|
151
|
+
static formatDate(isoString, isDatetime, timezone) {
|
|
155
152
|
// The date received from the server will be always in seconds
|
|
156
|
-
|
|
153
|
+
let offsetDate = isoString;
|
|
157
154
|
if (timezone !== undefined) {
|
|
158
155
|
offsetDate = new Date(isoString).getTime() + timezone * 1000;
|
|
159
156
|
}
|
|
160
|
-
|
|
157
|
+
const dateObject = new Date(offsetDate);
|
|
161
158
|
if (isNaN(dateObject.getUTCFullYear())) {
|
|
162
159
|
return null;
|
|
163
160
|
}
|
|
164
|
-
|
|
161
|
+
let formattedDate = dateObject.getFullYear() +
|
|
165
162
|
'-' +
|
|
166
163
|
((dateObject.getUTCMonth() + 1).toString().length === 1
|
|
167
164
|
? '0' + (dateObject.getUTCMonth() + 1)
|
|
@@ -186,39 +183,39 @@ var Tools = /** @class */ (function () {
|
|
|
186
183
|
: dateObject.getUTCSeconds());
|
|
187
184
|
}
|
|
188
185
|
return formattedDate;
|
|
189
|
-
}
|
|
186
|
+
}
|
|
190
187
|
/**
|
|
191
188
|
* From "+03:00" return the offset in milliseconds
|
|
192
189
|
* @param timezone
|
|
193
190
|
*/
|
|
194
|
-
|
|
191
|
+
static timezoneToMilliseconds(timezone) {
|
|
195
192
|
if (timezone === undefined) {
|
|
196
193
|
return 0;
|
|
197
194
|
}
|
|
198
195
|
if (timezone === 'Z') {
|
|
199
196
|
return 0;
|
|
200
197
|
}
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
const sign = timezone[0];
|
|
199
|
+
const [hours, minutes] = timezone.slice(1).split(':');
|
|
203
200
|
return sign === '+'
|
|
204
201
|
? this.sanitizeFormattedNumber(hours) * 3.6e6 + this.sanitizeFormattedNumber(minutes) * 60000
|
|
205
202
|
: (this.sanitizeFormattedNumber(hours) * 3.6e6 +
|
|
206
203
|
this.sanitizeFormattedNumber(minutes) * 60000) *
|
|
207
204
|
-1;
|
|
208
|
-
}
|
|
209
|
-
|
|
205
|
+
}
|
|
206
|
+
static sanitizeFormattedNumber(str) {
|
|
210
207
|
if (str.length === 2 && str.startsWith('0')) {
|
|
211
208
|
return Tools.parseNumber(str[1]);
|
|
212
209
|
}
|
|
213
210
|
return Tools.parseNumber(str);
|
|
214
|
-
}
|
|
211
|
+
}
|
|
215
212
|
/**
|
|
216
213
|
* Return true if `n` is (or can be parsed as) a float, but is NOT an integer
|
|
217
214
|
*
|
|
218
215
|
* @param {any} n
|
|
219
216
|
* @return {number} a number (NaN is `n` cannot be parsed as a number)
|
|
220
217
|
*/
|
|
221
|
-
|
|
218
|
+
static parseNumber(n) {
|
|
222
219
|
// string: try to parse as number (allow ',' as decimal separator)
|
|
223
220
|
if (typeof n === 'string') {
|
|
224
221
|
// prevent the empty string to be parsed as 0
|
|
@@ -236,7 +233,7 @@ var Tools = /** @class */ (function () {
|
|
|
236
233
|
return Number.NaN;
|
|
237
234
|
}
|
|
238
235
|
return n;
|
|
239
|
-
}
|
|
236
|
+
}
|
|
240
237
|
/**
|
|
241
238
|
* Return an Array without duplicated keys
|
|
242
239
|
*
|
|
@@ -244,11 +241,11 @@ var Tools = /** @class */ (function () {
|
|
|
244
241
|
* @param {string} key
|
|
245
242
|
* @return {Array<any>}
|
|
246
243
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
static uniqBy(arr, key) {
|
|
245
|
+
const seen = new Set();
|
|
249
246
|
if (key) {
|
|
250
|
-
|
|
251
|
-
for (
|
|
247
|
+
const result = [];
|
|
248
|
+
for (let i = 0; i < arr.length; ++i) {
|
|
252
249
|
if (arr[i] && arr[i][key] && !seen.has(arr[i][key])) {
|
|
253
250
|
seen.add(arr[i][key]);
|
|
254
251
|
result.push(arr[i]);
|
|
@@ -260,16 +257,16 @@ var Tools = /** @class */ (function () {
|
|
|
260
257
|
return result;
|
|
261
258
|
}
|
|
262
259
|
return typeof arr[0] === 'object'
|
|
263
|
-
? Array.from(new Set(arr.map(
|
|
260
|
+
? Array.from(new Set(arr.map((v) => JSON.stringify(v)))).map((v) => JSON.parse(v))
|
|
264
261
|
: Array.from(new Set(arr));
|
|
265
|
-
}
|
|
262
|
+
}
|
|
266
263
|
/**
|
|
267
264
|
* Return 'image' or 'url' depending on the given string
|
|
268
265
|
*
|
|
269
266
|
* @param {string} value
|
|
270
267
|
* @return {"image" | "url"}
|
|
271
268
|
*/
|
|
272
|
-
|
|
269
|
+
static getType(value) {
|
|
273
270
|
if (Tools.isImage(value) && Tools.isUrl(value)) {
|
|
274
271
|
return 'imageUrl';
|
|
275
272
|
}
|
|
@@ -280,42 +277,42 @@ var Tools = /** @class */ (function () {
|
|
|
280
277
|
return 'url';
|
|
281
278
|
}
|
|
282
279
|
return undefined;
|
|
283
|
-
}
|
|
280
|
+
}
|
|
284
281
|
/**
|
|
285
282
|
* Return true if the given string is an url that match the schema handled by LKE
|
|
286
283
|
*
|
|
287
284
|
* @param {string} value
|
|
288
285
|
* @return {boolean}
|
|
289
286
|
*/
|
|
290
|
-
|
|
287
|
+
static isUrl(value) {
|
|
291
288
|
return URL_PATTERN.test(value);
|
|
292
|
-
}
|
|
289
|
+
}
|
|
293
290
|
/**
|
|
294
291
|
* Return true if the given string is an url with an image extension
|
|
295
292
|
*
|
|
296
293
|
* @param {string} value
|
|
297
294
|
* @return {boolean}
|
|
298
295
|
*/
|
|
299
|
-
|
|
296
|
+
static isImage(value) {
|
|
300
297
|
return IMAGE_PATTERN.test(value);
|
|
301
|
-
}
|
|
298
|
+
}
|
|
302
299
|
/**
|
|
303
300
|
* Return true if a value is not undefined, not null and not an empty string
|
|
304
301
|
*/
|
|
305
|
-
|
|
302
|
+
static valueExists(value) {
|
|
306
303
|
return Tools.isDefined(value) && (typeof value !== 'string' || Tools.isStringFilled(value));
|
|
307
|
-
}
|
|
304
|
+
}
|
|
308
305
|
/**
|
|
309
306
|
* Return true if `n` is (or can be parsed as) a number
|
|
310
307
|
*/
|
|
311
|
-
|
|
308
|
+
static isNumber(n) {
|
|
312
309
|
n = Tools.parseNumber(n);
|
|
313
310
|
return Tools.isDefined(n) && n === n;
|
|
314
|
-
}
|
|
311
|
+
}
|
|
315
312
|
/**
|
|
316
313
|
* return the correct property value
|
|
317
314
|
*/
|
|
318
|
-
|
|
315
|
+
static getPropertyValue(property, invalidAsString, formattedDates) {
|
|
319
316
|
if (typeof property === 'object' && !Array.isArray(property)) {
|
|
320
317
|
if (!('status' in property)) {
|
|
321
318
|
if ((property.type === 'date' || property.type === 'datetime') && formattedDates) {
|
|
@@ -333,52 +330,51 @@ var Tools = /** @class */ (function () {
|
|
|
333
330
|
}
|
|
334
331
|
}
|
|
335
332
|
return property;
|
|
336
|
-
}
|
|
333
|
+
}
|
|
337
334
|
/**
|
|
338
335
|
* Parse the given value and return a float number or NaN
|
|
339
336
|
*
|
|
340
337
|
* @param {any} n
|
|
341
338
|
* @return {number}
|
|
342
339
|
*/
|
|
343
|
-
|
|
340
|
+
static parseFloat(n) {
|
|
344
341
|
return Tools.parseNumber(n);
|
|
345
|
-
}
|
|
342
|
+
}
|
|
346
343
|
/**
|
|
347
344
|
* Format a currency value to string.
|
|
348
345
|
*
|
|
349
346
|
* eg: 4123 -> 4.123,00 $
|
|
350
347
|
*/
|
|
351
|
-
|
|
352
|
-
|
|
348
|
+
static formatCurrencyValue(value, options) {
|
|
349
|
+
const sign = value < 0 ? '- ' : '';
|
|
353
350
|
switch (options.format) {
|
|
354
351
|
case rest_client_1.CurrencyFormat.SYMBOL_COMMAS_DOT:
|
|
355
|
-
return
|
|
352
|
+
return `${sign}${options.symbol} ${Tools.formatNumberToCurrency(value, ',', '.')}`;
|
|
356
353
|
case rest_client_1.CurrencyFormat.DOTS_COMMA_SYMBOL:
|
|
357
|
-
return
|
|
354
|
+
return `${sign}${Tools.formatNumberToCurrency(value, '.', ',')} ${options.symbol}`;
|
|
358
355
|
case rest_client_1.CurrencyFormat.SPACES_COMMA_DOT:
|
|
359
|
-
return
|
|
356
|
+
return `${sign}${Tools.formatNumberToCurrency(value, ' ', ',')} ${options.symbol}`;
|
|
360
357
|
default:
|
|
361
|
-
throw Error(
|
|
358
|
+
throw Error(`Cannot format property value ${value}, unknown format ${options.format}.`);
|
|
362
359
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
360
|
+
}
|
|
361
|
+
static formatNumberToCurrency(value, thousandSeparator, decimalSeparator) {
|
|
365
362
|
if (!Number.isFinite(value)) {
|
|
366
363
|
return value.toString();
|
|
367
364
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
365
|
+
const [integerPart, fractionalPart] = Math.abs(value).toFixed(2).split('.');
|
|
366
|
+
let i = -1;
|
|
367
|
+
const thousands = integerPart
|
|
371
368
|
.split('')
|
|
372
369
|
.reverse()
|
|
373
|
-
.map(
|
|
370
|
+
.map((digit) => {
|
|
374
371
|
i++;
|
|
375
372
|
return i > 0 && i % 3 === 0 ? digit + thousandSeparator : digit;
|
|
376
373
|
})
|
|
377
374
|
.reverse()
|
|
378
375
|
.join('');
|
|
379
376
|
return thousands + decimalSeparator + fractionalPart;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
}());
|
|
377
|
+
}
|
|
378
|
+
}
|
|
383
379
|
exports.Tools = Tools;
|
|
384
380
|
//# sourceMappingURL=tools.js.map
|