xcraft-core-utils 4.3.8 → 4.3.9

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/lib/prop-types.js CHANGED
@@ -1,154 +1,154 @@
1
- 'use strict';
2
-
3
- const PropTypes = require('prop-types');
4
-
5
- /******************************************************************************/
6
-
7
- function getType(type) {
8
- switch (type.type) {
9
- case 'any':
10
- return PropTypes.any;
11
- case 'string':
12
- case 'color':
13
- case 'richColor':
14
- case 'background':
15
- case 'shortcut':
16
- case 'angle':
17
- case 'percentage':
18
- case 'fontWeight':
19
- case 'shape':
20
- case 'horizontalSpacing':
21
- case 'verticalSpacing':
22
- case 'fontStyle':
23
- case 'cursor':
24
- case 'textTransform':
25
- case 'justify':
26
- case 'textJustify':
27
- case 'date':
28
- case 'time':
29
- case 'datetime':
30
- case 'price':
31
- case 'weight':
32
- case 'length':
33
- case 'pixel':
34
- case 'volume':
35
- case 'percent':
36
- case 'delay':
37
- case 'place':
38
- case 'transition':
39
- return PropTypes.string;
40
- case 'number':
41
- return PropTypes.number;
42
- case 'nabu':
43
- return (props, propName, componentName) => {
44
- const prop = props[propName];
45
- if (prop !== null && prop !== undefined) {
46
- if (typeof prop === 'object') {
47
- let isNabu =
48
- 'nabuId' in prop ||
49
- ('_type' in prop &&
50
- (prop['_type'] === 'translatableString' ||
51
- prop['_type'] === 'translatableMarkdown'));
52
- // Handle Map or OrderedMap
53
- if (prop.get) {
54
- isNabu = prop.get('nabuId') ? true : false;
55
- if (!isNabu) {
56
- isNabu =
57
- prop.get('_type') === 'translatableString' ||
58
- prop.get('_type') === 'translatableMarkdown';
59
- }
60
- }
61
- if (!isNabu) {
62
- return new Error(
63
- 'Invalid prop `' +
64
- propName +
65
- ' of value "' +
66
- prop +
67
- '" supplied to' +
68
- ' `' +
69
- componentName +
70
- '`. Validation failed. Missing nabuId !'
71
- );
72
- }
73
- } else if (typeof prop !== 'string' && typeof prop !== 'number') {
74
- return new Error(
75
- 'Invalid prop `' +
76
- propName +
77
- ' of value "' +
78
- prop +
79
- '" supplied to' +
80
- ' `' +
81
- componentName +
82
- '`. Validation failed.'
83
- );
84
- }
85
- }
86
- };
87
- case 'glyph':
88
- return PropTypes.oneOfType([
89
- PropTypes.string,
90
- PropTypes.shape({
91
- glyph: PropTypes.string,
92
- color: PropTypes.string,
93
- }),
94
- ]);
95
- case 'bool':
96
- return PropTypes.oneOf([false, true]);
97
- case 'enum':
98
- return PropTypes.oneOf(type.values);
99
- case 'component':
100
- return PropTypes.node;
101
- case 'function':
102
- return PropTypes.func;
103
- case 'grow':
104
- return PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
105
- case 'oneOfType':
106
- // eslint-disable-next-line no-case-declarations
107
- const types = type.types.map((t) => getType(t));
108
- return PropTypes.oneOfType(types);
109
- default:
110
- throw new Error(`Unknown prop type: '${type.type}'`);
111
- }
112
- }
113
-
114
- function getPropType(prop) {
115
- let propType = prop.type.propType || getType(prop.type);
116
- if (prop.required && propType !== undefined) {
117
- propType = propType.isRequired;
118
- }
119
- return propType;
120
- }
121
-
122
- function getDefaultProp(prop) {
123
- if (prop.defaultValue !== undefined) {
124
- return prop.defaultValue;
125
- } else {
126
- return null;
127
- }
128
- }
129
-
130
- /******************************************************************************/
131
-
132
- function makePropTypes(props) {
133
- const propTypes = {};
134
- for (const prop of props) {
135
- propTypes[prop.name] = getPropType(prop);
136
- }
137
- return propTypes;
138
- }
139
-
140
- function makeDefaultProps(props) {
141
- const defaultProps = {};
142
- for (const prop of props) {
143
- const d = getDefaultProp(prop);
144
- if (d !== null) {
145
- defaultProps[prop.name] = d;
146
- }
147
- }
148
- return defaultProps;
149
- }
150
-
151
- module.exports = {
152
- makePropTypes,
153
- makeDefaultProps,
154
- };
1
+ 'use strict';
2
+
3
+ const PropTypes = require('prop-types');
4
+
5
+ /******************************************************************************/
6
+
7
+ function getType(type) {
8
+ switch (type.type) {
9
+ case 'any':
10
+ return PropTypes.any;
11
+ case 'string':
12
+ case 'color':
13
+ case 'richColor':
14
+ case 'background':
15
+ case 'shortcut':
16
+ case 'angle':
17
+ case 'percentage':
18
+ case 'fontWeight':
19
+ case 'shape':
20
+ case 'horizontalSpacing':
21
+ case 'verticalSpacing':
22
+ case 'fontStyle':
23
+ case 'cursor':
24
+ case 'textTransform':
25
+ case 'justify':
26
+ case 'textJustify':
27
+ case 'date':
28
+ case 'time':
29
+ case 'datetime':
30
+ case 'price':
31
+ case 'weight':
32
+ case 'length':
33
+ case 'pixel':
34
+ case 'volume':
35
+ case 'percent':
36
+ case 'delay':
37
+ case 'place':
38
+ case 'transition':
39
+ return PropTypes.string;
40
+ case 'number':
41
+ return PropTypes.number;
42
+ case 'nabu':
43
+ return (props, propName, componentName) => {
44
+ const prop = props[propName];
45
+ if (prop !== null && prop !== undefined) {
46
+ if (typeof prop === 'object') {
47
+ let isNabu =
48
+ 'nabuId' in prop ||
49
+ ('_type' in prop &&
50
+ (prop['_type'] === 'translatableString' ||
51
+ prop['_type'] === 'translatableMarkdown'));
52
+ // Handle Map or OrderedMap
53
+ if (prop.get) {
54
+ isNabu = prop.get('nabuId') ? true : false;
55
+ if (!isNabu) {
56
+ isNabu =
57
+ prop.get('_type') === 'translatableString' ||
58
+ prop.get('_type') === 'translatableMarkdown';
59
+ }
60
+ }
61
+ if (!isNabu) {
62
+ return new Error(
63
+ 'Invalid prop `' +
64
+ propName +
65
+ ' of value "' +
66
+ prop +
67
+ '" supplied to' +
68
+ ' `' +
69
+ componentName +
70
+ '`. Validation failed. Missing nabuId !'
71
+ );
72
+ }
73
+ } else if (typeof prop !== 'string' && typeof prop !== 'number') {
74
+ return new Error(
75
+ 'Invalid prop `' +
76
+ propName +
77
+ ' of value "' +
78
+ prop +
79
+ '" supplied to' +
80
+ ' `' +
81
+ componentName +
82
+ '`. Validation failed.'
83
+ );
84
+ }
85
+ }
86
+ };
87
+ case 'glyph':
88
+ return PropTypes.oneOfType([
89
+ PropTypes.string,
90
+ PropTypes.shape({
91
+ glyph: PropTypes.string,
92
+ color: PropTypes.string,
93
+ }),
94
+ ]);
95
+ case 'bool':
96
+ return PropTypes.oneOf([false, true]);
97
+ case 'enum':
98
+ return PropTypes.oneOf(type.values);
99
+ case 'component':
100
+ return PropTypes.node;
101
+ case 'function':
102
+ return PropTypes.func;
103
+ case 'grow':
104
+ return PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
105
+ case 'oneOfType':
106
+ // eslint-disable-next-line no-case-declarations
107
+ const types = type.types.map((t) => getType(t));
108
+ return PropTypes.oneOfType(types);
109
+ default:
110
+ throw new Error(`Unknown prop type: '${type.type}'`);
111
+ }
112
+ }
113
+
114
+ function getPropType(prop) {
115
+ let propType = prop.type.propType || getType(prop.type);
116
+ if (prop.required && propType !== undefined) {
117
+ propType = propType.isRequired;
118
+ }
119
+ return propType;
120
+ }
121
+
122
+ function getDefaultProp(prop) {
123
+ if (prop.defaultValue !== undefined) {
124
+ return prop.defaultValue;
125
+ } else {
126
+ return null;
127
+ }
128
+ }
129
+
130
+ /******************************************************************************/
131
+
132
+ function makePropTypes(props) {
133
+ const propTypes = {};
134
+ for (const prop of props) {
135
+ propTypes[prop.name] = getPropType(prop);
136
+ }
137
+ return propTypes;
138
+ }
139
+
140
+ function makeDefaultProps(props) {
141
+ const defaultProps = {};
142
+ for (const prop of props) {
143
+ const d = getDefaultProp(prop);
144
+ if (d !== null) {
145
+ defaultProps[prop.name] = d;
146
+ }
147
+ }
148
+ return defaultProps;
149
+ }
150
+
151
+ module.exports = {
152
+ makePropTypes,
153
+ makeDefaultProps,
154
+ };
@@ -1,87 +1,87 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('events');
4
- const LinkedList = require('linked-list');
5
-
6
- class RankedCache extends EventEmitter {
7
- constructor(limit) {
8
- super();
9
-
10
- this._limit = limit;
11
- this._size = 0;
12
- this._linkedList = new LinkedList();
13
- }
14
-
15
- /**
16
- * Push a new payload or an existing item in the linked cache.
17
- *
18
- * If the limit is reached, the older item is sent by event emitter to the
19
- * `out` topic.
20
- *
21
- * Note that a RankedCache with a limit <= 0 will just return null.
22
- *
23
- * @param {*} item - Push an item in the linked cache.
24
- * @returns {*} the ranked item (always wrapper in an Item).
25
- */
26
- rank(item) {
27
- if (this._limit <= 0) {
28
- return null;
29
- }
30
-
31
- const isNew = !(item instanceof LinkedList.Item);
32
-
33
- /* Create the item on the fly if necessary. */
34
- if (isNew) {
35
- const _item = new LinkedList.Item();
36
- _item.payload = item;
37
- item = _item;
38
- }
39
-
40
- /* Limit the cache to this._limit entries. The less used item is deleted
41
- * when the limit is reached.
42
- */
43
- if (this._size === this._limit) {
44
- const prevItem = this._linkedList.head;
45
- prevItem.detach();
46
- this._size--;
47
- this.emit('out', prevItem);
48
- }
49
-
50
- if (item.list) {
51
- /* When an existing style is used, detach from its current position
52
- * and move of one step in the linked-list. The goal is to keep the less
53
- * used items in front of the list (head).
54
- */
55
- const nextItem = item.next;
56
- if (nextItem) {
57
- item.detach();
58
- nextItem.append(item);
59
- }
60
- } else {
61
- /* Add the item to the end of the list. Here, it's still not possible to
62
- * be sure that this item will be often used. Anyway, if it's not used
63
- * anymore, it will move one-by-one to the front of the list.
64
- */
65
- this._linkedList.append(item);
66
- this._size++;
67
- }
68
-
69
- return item;
70
- }
71
-
72
- /**
73
- * Clear the whole RankedCache.
74
- *
75
- * All items are sent to the 'out' event.
76
- */
77
- clear() {
78
- let item;
79
- while ((item = this._linkedList.head)) {
80
- item.detach();
81
- this._size--;
82
- this.emit('out', item);
83
- }
84
- }
85
- }
86
-
87
- module.exports = RankedCache;
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('events');
4
+ const LinkedList = require('linked-list');
5
+
6
+ class RankedCache extends EventEmitter {
7
+ constructor(limit) {
8
+ super();
9
+
10
+ this._limit = limit;
11
+ this._size = 0;
12
+ this._linkedList = new LinkedList();
13
+ }
14
+
15
+ /**
16
+ * Push a new payload or an existing item in the linked cache.
17
+ *
18
+ * If the limit is reached, the older item is sent by event emitter to the
19
+ * `out` topic.
20
+ *
21
+ * Note that a RankedCache with a limit <= 0 will just return null.
22
+ *
23
+ * @param {*} item - Push an item in the linked cache.
24
+ * @returns {*} the ranked item (always wrapper in an Item).
25
+ */
26
+ rank(item) {
27
+ if (this._limit <= 0) {
28
+ return null;
29
+ }
30
+
31
+ const isNew = !(item instanceof LinkedList.Item);
32
+
33
+ /* Create the item on the fly if necessary. */
34
+ if (isNew) {
35
+ const _item = new LinkedList.Item();
36
+ _item.payload = item;
37
+ item = _item;
38
+ }
39
+
40
+ /* Limit the cache to this._limit entries. The less used item is deleted
41
+ * when the limit is reached.
42
+ */
43
+ if (this._size === this._limit) {
44
+ const prevItem = this._linkedList.head;
45
+ prevItem.detach();
46
+ this._size--;
47
+ this.emit('out', prevItem);
48
+ }
49
+
50
+ if (item.list) {
51
+ /* When an existing style is used, detach from its current position
52
+ * and move of one step in the linked-list. The goal is to keep the less
53
+ * used items in front of the list (head).
54
+ */
55
+ const nextItem = item.next;
56
+ if (nextItem) {
57
+ item.detach();
58
+ nextItem.append(item);
59
+ }
60
+ } else {
61
+ /* Add the item to the end of the list. Here, it's still not possible to
62
+ * be sure that this item will be often used. Anyway, if it's not used
63
+ * anymore, it will move one-by-one to the front of the list.
64
+ */
65
+ this._linkedList.append(item);
66
+ this._size++;
67
+ }
68
+
69
+ return item;
70
+ }
71
+
72
+ /**
73
+ * Clear the whole RankedCache.
74
+ *
75
+ * All items are sent to the 'out' event.
76
+ */
77
+ clear() {
78
+ let item;
79
+ while ((item = this._linkedList.head)) {
80
+ item.detach();
81
+ this._size--;
82
+ this.emit('out', item);
83
+ }
84
+ }
85
+ }
86
+
87
+ module.exports = RankedCache;
package/lib/reflect.js CHANGED
@@ -1,12 +1,12 @@
1
- 'use strict';
2
-
3
- const STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/gm;
4
- const ARGUMENT_NAMES = /([^\s,]+)/g;
5
-
6
- exports.funcParams = (func) => {
7
- const fnStr = func.toString().replace(STRIP_COMMENTS, '');
8
- const result = fnStr
9
- .slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')'))
10
- .match(ARGUMENT_NAMES);
11
- return result || [];
12
- };
1
+ 'use strict';
2
+
3
+ const STRIP_COMMENTS = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/gm;
4
+ const ARGUMENT_NAMES = /([^\s,]+)/g;
5
+
6
+ exports.funcParams = (func) => {
7
+ const fnStr = func.toString().replace(STRIP_COMMENTS, '');
8
+ const result = fnStr
9
+ .slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')'))
10
+ .match(ARGUMENT_NAMES);
11
+ return result || [];
12
+ };
package/lib/regex.js CHANGED
@@ -1,24 +1,24 @@
1
- 'use strict';
2
-
3
- const escape = require('escape-regexp');
4
-
5
- exports.toRegexp = function (value) {
6
- if (value instanceof RegExp) {
7
- return value;
8
- }
9
-
10
- var escapeStringRegexp = require('escape-string-regexp');
11
- return new RegExp('^' + escapeStringRegexp(value) + '$');
12
- };
13
-
14
- exports.toAxonRegExpStr = function (str) {
15
- str = escape(str).replace(/\\\*/g, '(.+)');
16
- return '^' + str + '$';
17
- };
18
-
19
- exports.toXcraftRegExpStr = function (str) {
20
- str = escape(str)
21
- .replace(/\\\((.+)\\\)/g, (m) => m.replace(/\\/g, ''))
22
- .replace(/\\\*/g, '(.+)');
23
- return '^' + str + '$';
24
- };
1
+ 'use strict';
2
+
3
+ const escape = require('escape-regexp');
4
+
5
+ exports.toRegexp = function (value) {
6
+ if (value instanceof RegExp) {
7
+ return value;
8
+ }
9
+
10
+ var escapeStringRegexp = require('escape-string-regexp');
11
+ return new RegExp('^' + escapeStringRegexp(value) + '$');
12
+ };
13
+
14
+ exports.toAxonRegExpStr = function (str) {
15
+ str = escape(str).replace(/\\\*/g, '(.+)');
16
+ return '^' + str + '$';
17
+ };
18
+
19
+ exports.toXcraftRegExpStr = function (str) {
20
+ str = escape(str)
21
+ .replace(/\\\((.+)\\\)/g, (m) => m.replace(/\\/g, ''))
22
+ .replace(/\\\*/g, '(.+)');
23
+ return '^' + str + '$';
24
+ };