@nocobase/utils 0.9.3-alpha.1 → 0.9.4-alpha.2
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/client.d.ts +3 -1
- package/lib/client.js +33 -11
- package/lib/getValuesByPath.js +22 -5
- package/lib/log.d.ts +1 -0
- package/lib/log.js +10 -0
- package/lib/notification.d.ts +1 -0
- package/lib/notification.js +20 -0
- package/lib/parse-filter.d.ts +1 -0
- package/lib/parse-filter.js +10 -10
- package/package.json +2 -2
package/lib/client.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export * from './common';
|
|
|
3
3
|
export * from './date';
|
|
4
4
|
export * from './forEach';
|
|
5
5
|
export * from './getValuesByPath';
|
|
6
|
+
export * from './json-templates';
|
|
7
|
+
export * from './log';
|
|
6
8
|
export * from './merge';
|
|
9
|
+
export * from './notification';
|
|
7
10
|
export * from './number';
|
|
8
11
|
export * from './parse-filter';
|
|
9
12
|
export * from './registry';
|
|
10
13
|
export * from './uid';
|
|
11
|
-
export * from './json-templates';
|
package/lib/client.js
CHANGED
|
@@ -58,6 +58,28 @@ Object.keys(_getValuesByPath).forEach(function (key) {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
+
var _jsonTemplates = require("./json-templates");
|
|
62
|
+
Object.keys(_jsonTemplates).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _jsonTemplates[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function get() {
|
|
68
|
+
return _jsonTemplates[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _log = require("./log");
|
|
73
|
+
Object.keys(_log).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _log[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _log[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
61
83
|
var _merge = require("./merge");
|
|
62
84
|
Object.keys(_merge).forEach(function (key) {
|
|
63
85
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -69,6 +91,17 @@ Object.keys(_merge).forEach(function (key) {
|
|
|
69
91
|
}
|
|
70
92
|
});
|
|
71
93
|
});
|
|
94
|
+
var _notification = require("./notification");
|
|
95
|
+
Object.keys(_notification).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _notification[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function get() {
|
|
101
|
+
return _notification[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
72
105
|
var _number = require("./number");
|
|
73
106
|
Object.keys(_number).forEach(function (key) {
|
|
74
107
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -112,15 +145,4 @@ Object.keys(_uid).forEach(function (key) {
|
|
|
112
145
|
return _uid[key];
|
|
113
146
|
}
|
|
114
147
|
});
|
|
115
|
-
});
|
|
116
|
-
var _jsonTemplates = require("./json-templates");
|
|
117
|
-
Object.keys(_jsonTemplates).forEach(function (key) {
|
|
118
|
-
if (key === "default" || key === "__esModule") return;
|
|
119
|
-
if (key in exports && exports[key] === _jsonTemplates[key]) return;
|
|
120
|
-
Object.defineProperty(exports, key, {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
get: function get() {
|
|
123
|
-
return _jsonTemplates[key];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
148
|
});
|
package/lib/getValuesByPath.js
CHANGED
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getValuesByPath = void 0;
|
|
7
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
10
|
const getValuesByPath = (obj, path, defaultValue) => {
|
|
8
11
|
if (!obj) {
|
|
9
12
|
return defaultValue;
|
|
@@ -12,22 +15,36 @@ const getValuesByPath = (obj, path, defaultValue) => {
|
|
|
12
15
|
let result = [];
|
|
13
16
|
let currentValue = obj;
|
|
14
17
|
for (let i = 0; i < keys.length; i++) {
|
|
18
|
+
var _currentValue;
|
|
15
19
|
const key = keys[i];
|
|
16
20
|
if (Array.isArray(currentValue)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
var _iterator = _createForOfIteratorHelper(currentValue),
|
|
22
|
+
_step;
|
|
23
|
+
try {
|
|
24
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
25
|
+
const element = _step.value;
|
|
26
|
+
const value = getValuesByPath(element, keys.slice(i).join('.'), defaultValue);
|
|
27
|
+
result = result.concat(value);
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
_iterator.e(err);
|
|
31
|
+
} finally {
|
|
32
|
+
_iterator.f();
|
|
20
33
|
}
|
|
21
34
|
break;
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
if (currentValue == null) {
|
|
36
|
+
if (((_currentValue = currentValue) === null || _currentValue === void 0 ? void 0 : _currentValue[key]) === undefined) {
|
|
25
37
|
break;
|
|
26
38
|
}
|
|
39
|
+
currentValue = currentValue[key];
|
|
27
40
|
if (i === keys.length - 1) {
|
|
28
41
|
result.push(currentValue);
|
|
29
42
|
}
|
|
30
43
|
}
|
|
44
|
+
result = result.filter(Boolean);
|
|
45
|
+
if (result.length === 0) {
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
31
48
|
return result.length === 1 ? result[0] : result;
|
|
32
49
|
};
|
|
33
50
|
exports.getValuesByPath = getValuesByPath;
|
package/lib/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const error: (message: Error | string, ...args: any[]) => void;
|
package/lib/log.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const showToast: (message: any, type?: string, duration?: number) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showToast = void 0;
|
|
7
|
+
function _antd() {
|
|
8
|
+
const data = require("antd");
|
|
9
|
+
_antd = function _antd() {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
const showToast = (message, type = 'info', duration = 5000) => {
|
|
15
|
+
_antd().notification[type]({
|
|
16
|
+
message,
|
|
17
|
+
duration
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
exports.showToast = showToast;
|
package/lib/parse-filter.d.ts
CHANGED
package/lib/parse-filter.js
CHANGED
|
@@ -7,14 +7,8 @@ exports.flatten = flatten;
|
|
|
7
7
|
exports.getDateVars = getDateVars;
|
|
8
8
|
exports.getDayRange = getDayRange;
|
|
9
9
|
exports.parseFilter = void 0;
|
|
10
|
+
exports.splitPathToTwoParts = splitPathToTwoParts;
|
|
10
11
|
exports.utc2unit = utc2unit;
|
|
11
|
-
function _get() {
|
|
12
|
-
const data = _interopRequireDefault(require("lodash/get"));
|
|
13
|
-
_get = function _get() {
|
|
14
|
-
return data;
|
|
15
|
-
};
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
12
|
function _set() {
|
|
19
13
|
const data = _interopRequireDefault(require("lodash/set"));
|
|
20
14
|
_set = function _set() {
|
|
@@ -29,6 +23,7 @@ function _moment() {
|
|
|
29
23
|
};
|
|
30
24
|
return data;
|
|
31
25
|
}
|
|
26
|
+
var _getValuesByPath = require("./getValuesByPath");
|
|
32
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
28
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
34
29
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -76,9 +71,10 @@ function flatten(target, opts) {
|
|
|
76
71
|
function unflatten(obj, opts = {}) {
|
|
77
72
|
const parsed = {};
|
|
78
73
|
const transformValue = opts.transformValue || keyIdentity;
|
|
79
|
-
Object.keys(obj).
|
|
74
|
+
for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
|
|
75
|
+
const key = _Object$keys[_i];
|
|
80
76
|
(0, _set().default)(parsed, key, transformValue(obj[key], key));
|
|
81
|
-
}
|
|
77
|
+
}
|
|
82
78
|
return parsed;
|
|
83
79
|
}
|
|
84
80
|
const parsePath = path => {
|
|
@@ -163,7 +159,7 @@ const parseFilter = /*#__PURE__*/function () {
|
|
|
163
159
|
const match = re.exec(value);
|
|
164
160
|
if (match) {
|
|
165
161
|
const key = match[1].trim();
|
|
166
|
-
const val = (0,
|
|
162
|
+
const val = (0, _getValuesByPath.getValuesByPath)(vars, key, null);
|
|
167
163
|
const field = getField === null || getField === void 0 ? void 0 : getField(path);
|
|
168
164
|
value = typeof val === 'function' ? val === null || val === void 0 ? void 0 : val({
|
|
169
165
|
field,
|
|
@@ -300,4 +296,8 @@ function getDateVars() {
|
|
|
300
296
|
last90Days: toDays(-90),
|
|
301
297
|
next90Days: toDays(90)
|
|
302
298
|
};
|
|
299
|
+
}
|
|
300
|
+
function splitPathToTwoParts(path) {
|
|
301
|
+
const parts = path.split('.');
|
|
302
|
+
return [parts.shift(), parts.join('.')];
|
|
303
303
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4-alpha.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"moment": "2.x",
|
|
17
17
|
"rc-input-number": "7.x"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "2bc19a85bf9425aa220b6c467315c8087f333a7e"
|
|
20
20
|
}
|