@nocobase/utils 0.9.2-alpha.1 → 0.9.2-alpha.3

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 CHANGED
@@ -2,6 +2,7 @@ export * from './collections-graph';
2
2
  export * from './common';
3
3
  export * from './date';
4
4
  export * from './forEach';
5
+ export * from './getValuesByPath';
5
6
  export * from './merge';
6
7
  export * from './number';
7
8
  export * from './parse-filter';
package/lib/client.js CHANGED
@@ -47,6 +47,17 @@ Object.keys(_forEach).forEach(function (key) {
47
47
  }
48
48
  });
49
49
  });
50
+ var _getValuesByPath = require("./getValuesByPath");
51
+ Object.keys(_getValuesByPath).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _getValuesByPath[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _getValuesByPath[key];
58
+ }
59
+ });
60
+ });
50
61
  var _merge = require("./merge");
51
62
  Object.keys(_merge).forEach(function (key) {
52
63
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1 @@
1
+ export declare const getValuesByPath: (obj: object, path: string, defaultValue?: any) => any;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getValuesByPath = void 0;
7
+ const getValuesByPath = (obj, path, defaultValue) => {
8
+ if (!obj) {
9
+ return defaultValue;
10
+ }
11
+ const keys = path.split('.');
12
+ let result = [];
13
+ let currentValue = obj;
14
+ for (let i = 0; i < keys.length; i++) {
15
+ const key = keys[i];
16
+ if (Array.isArray(currentValue)) {
17
+ for (let j = 0; j < currentValue.length; j++) {
18
+ const value = getValuesByPath(currentValue[j], keys.slice(i).join('.'), defaultValue);
19
+ result = result.concat(value);
20
+ }
21
+ break;
22
+ }
23
+ currentValue = currentValue[key] === undefined ? defaultValue : currentValue[key];
24
+ if (currentValue == null) {
25
+ break;
26
+ }
27
+ if (i === keys.length - 1) {
28
+ result.push(currentValue);
29
+ }
30
+ }
31
+ return result.length === 1 ? result[0] : result;
32
+ };
33
+ exports.getValuesByPath = getValuesByPath;
@@ -1,3 +1,4 @@
1
+ export declare function flatten(target: any, opts?: any): {};
1
2
  export declare type ParseFilterOptions = {
2
3
  vars?: Record<string, any>;
3
4
  now?: any;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.flatten = flatten;
6
7
  exports.getDateVars = getDateVars;
7
8
  exports.getDayRange = getDayRange;
8
9
  exports.parseFilter = void 0;
@@ -48,14 +49,17 @@ function flatten(target, opts) {
48
49
  function step(object, prev, currentDepth) {
49
50
  currentDepth = currentDepth || 1;
50
51
  Object.keys(object).forEach(function (key) {
52
+ var _opts$breakOn, _opts;
51
53
  const value = object[key];
52
54
  const isarray = opts.safe && Array.isArray(value);
53
55
  const type = Object.prototype.toString.call(value);
54
56
  const isbuffer = isBuffer(value);
55
57
  const isobject = type === '[object Object]' || type === '[object Array]';
56
58
  const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
57
- if (opts.breakOn({
58
- key
59
+ if ((_opts$breakOn = (_opts = opts).breakOn) === null || _opts$breakOn === void 0 ? void 0 : _opts$breakOn.call(_opts, {
60
+ key,
61
+ value,
62
+ path: newKey
59
63
  })) {
60
64
  output[newKey] = transformValue(value, newKey);
61
65
  return;
@@ -187,7 +191,7 @@ function getDayRange(options) {
187
191
  _options$timezone = options.timezone,
188
192
  timezone = _options$timezone === void 0 ? '+00:00' : _options$timezone,
189
193
  offset = options.offset;
190
- let m = toMoment(now).utcOffset(timezone);
194
+ const m = toMoment(now).utcOffset(timezone);
191
195
  if (offset > 0) {
192
196
  return [
193
197
  // 第二天开始计算
@@ -217,7 +221,7 @@ function utc2unit(options) {
217
221
  _options$timezone2 = options.timezone,
218
222
  timezone = _options$timezone2 === void 0 ? '+00:00' : _options$timezone2,
219
223
  offset = options.offset;
220
- let m = toMoment(now);
224
+ const m = toMoment(now);
221
225
  m.utcOffset(timezone);
222
226
  m.startOf(unit);
223
227
  if (offset > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "0.9.2-alpha.1",
3
+ "version": "0.9.2-alpha.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -14,5 +14,5 @@
14
14
  "moment": "2.x",
15
15
  "rc-input-number": "7.x"
16
16
  },
17
- "gitHead": "a4f103eb0144f07205aff7b2a6be8ea6aa1330df"
17
+ "gitHead": "b6b5f9372202d942c97d2d90a4197e060db05124"
18
18
  }