@nocobase/utils 0.9.1-alpha.2 → 0.9.2-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/assign.d.ts CHANGED
@@ -4,7 +4,6 @@ export declare type MergeStrategy = MergeStrategyType | MergeStrategyFunc;
4
4
  export interface MergeStrategies {
5
5
  [key: string]: MergeStrategy;
6
6
  }
7
- export default function isPlainObject(value: any): boolean;
8
7
  export declare const mergeStrategies: Map<MergeStrategyType, MergeStrategyFunc>;
9
8
  export declare function assign(target: any, source: any, strategies?: MergeStrategies): any;
10
9
  export {};
package/lib/assign.js CHANGED
@@ -4,70 +4,47 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assign = assign;
7
- exports.default = isPlainObject;
8
7
  exports.mergeStrategies = void 0;
9
-
10
8
  function _deepmerge() {
11
9
  const data = _interopRequireDefault(require("deepmerge"));
12
-
13
10
  _deepmerge = function _deepmerge() {
14
11
  return data;
15
12
  };
16
-
17
13
  return data;
18
14
  }
19
-
20
15
  function _lodash() {
21
16
  const data = _interopRequireDefault(require("lodash"));
22
-
23
17
  _lodash = function _lodash() {
24
18
  return data;
25
19
  };
26
-
27
20
  return data;
28
21
  }
29
-
22
+ var _common = require("./common");
30
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function isPlainObject(value) {
33
- if (Object.prototype.toString.call(value) !== '[object Object]') {
34
- return false;
35
- }
36
-
37
- const prototype = Object.getPrototypeOf(value);
38
- return prototype === null || prototype === Object.prototype;
39
- }
40
-
41
24
  function getEnumerableOwnPropertySymbols(target) {
42
25
  return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(symbol => target.propertyIsEnumerable(symbol)) : [];
43
26
  }
44
-
45
27
  function getKeys(target) {
46
28
  return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
47
29
  }
48
-
49
30
  const mergeStrategies = new Map();
50
31
  exports.mergeStrategies = mergeStrategies;
51
32
  mergeStrategies.set('overwrite', (_, y) => {
52
33
  if (typeof y === 'string') {
53
34
  y = y.split(',');
54
35
  }
55
-
56
36
  return y;
57
37
  });
58
38
  mergeStrategies.set('andMerge', (x, y) => {
59
39
  if (!x && !y) {
60
40
  return;
61
41
  }
62
-
63
42
  if (!x) {
64
43
  return y;
65
44
  }
66
-
67
45
  if (!y) {
68
46
  return x;
69
47
  }
70
-
71
48
  return {
72
49
  $and: [x, y]
73
50
  };
@@ -76,69 +53,57 @@ mergeStrategies.set('orMerge', (x, y) => {
76
53
  if (!x && !y) {
77
54
  return;
78
55
  }
79
-
80
56
  if (!x) {
81
57
  return y;
82
58
  }
83
-
84
59
  if (!y) {
85
60
  return x;
86
61
  }
87
-
88
62
  return {
89
63
  $or: [x, y]
90
64
  };
91
65
  });
92
66
  mergeStrategies.set('deepMerge', (x, y) => {
93
- return isPlainObject(x) && isPlainObject(y) ? (0, _deepmerge().default)(x, y, {
67
+ return (0, _common.isPlainObject)(x) && (0, _common.isPlainObject)(y) ? (0, _deepmerge().default)(x, y, {
94
68
  arrayMerge: (x, y) => y
95
69
  }) : y;
96
70
  });
97
71
  mergeStrategies.set('merge', (x, y) => {
98
- return isPlainObject(x) && isPlainObject(y) ? Object.assign(x, y) : y;
72
+ return (0, _common.isPlainObject)(x) && (0, _common.isPlainObject)(y) ? Object.assign(x, y) : y;
99
73
  });
100
74
  mergeStrategies.set('union', (x, y) => {
101
75
  if (typeof x === 'string') {
102
76
  x = x.split(',');
103
77
  }
104
-
105
78
  if (typeof y === 'string') {
106
79
  y = y.split(',');
107
80
  }
108
-
109
81
  return _lodash().default.uniq((x || []).concat(y || [])).filter(Boolean);
110
82
  });
111
83
  mergeStrategies.set('intersect', (x, y) => (() => {
112
84
  if (typeof x === 'string') {
113
85
  x = x.split(',');
114
86
  }
115
-
116
87
  if (typeof y === 'string') {
117
88
  y = y.split(',');
118
89
  }
119
-
120
90
  if (!Array.isArray(x) || x.length === 0) {
121
91
  return y || [];
122
92
  }
123
-
124
93
  if (!Array.isArray(y) || y.length === 0) {
125
94
  return x || [];
126
95
  }
127
-
128
96
  return x.filter(v => y.includes(v));
129
97
  })().filter(Boolean));
130
-
131
98
  function assign(target, source, strategies = {}) {
132
99
  getKeys(source).forEach(sourceKey => {
133
100
  const strategy = strategies[sourceKey];
134
101
  let func = mergeStrategies.get('deepMerge');
135
-
136
102
  if (typeof strategy === 'function') {
137
103
  func = strategy;
138
104
  } else if (typeof strategy === 'string' && mergeStrategies.has(strategy)) {
139
105
  func = mergeStrategies.get(strategy);
140
106
  }
141
-
142
107
  target[sourceKey] = func(target[sourceKey], source[sourceKey]);
143
108
  });
144
109
  return target;
package/lib/client.d.ts CHANGED
@@ -1,5 +1,9 @@
1
+ export * from './collections-graph';
2
+ export * from './common';
1
3
  export * from './date';
4
+ export * from './forEach';
2
5
  export * from './merge';
3
6
  export * from './number';
7
+ export * from './parse-filter';
4
8
  export * from './registry';
5
9
  export * from './uid';
package/lib/client.js CHANGED
@@ -3,9 +3,29 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
6
+ var _collectionsGraph = require("./collections-graph");
7
+ Object.keys(_collectionsGraph).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _collectionsGraph[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _collectionsGraph[key];
14
+ }
15
+ });
16
+ });
17
+ var _common = require("./common");
18
+ Object.keys(_common).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _common[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _common[key];
25
+ }
26
+ });
27
+ });
7
28
  var _date = require("./date");
8
-
9
29
  Object.keys(_date).forEach(function (key) {
10
30
  if (key === "default" || key === "__esModule") return;
11
31
  if (key in exports && exports[key] === _date[key]) return;
@@ -16,9 +36,18 @@ Object.keys(_date).forEach(function (key) {
16
36
  }
17
37
  });
18
38
  });
19
-
39
+ var _forEach = require("./forEach");
40
+ Object.keys(_forEach).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _forEach[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _forEach[key];
47
+ }
48
+ });
49
+ });
20
50
  var _merge = require("./merge");
21
-
22
51
  Object.keys(_merge).forEach(function (key) {
23
52
  if (key === "default" || key === "__esModule") return;
24
53
  if (key in exports && exports[key] === _merge[key]) return;
@@ -29,9 +58,7 @@ Object.keys(_merge).forEach(function (key) {
29
58
  }
30
59
  });
31
60
  });
32
-
33
61
  var _number = require("./number");
34
-
35
62
  Object.keys(_number).forEach(function (key) {
36
63
  if (key === "default" || key === "__esModule") return;
37
64
  if (key in exports && exports[key] === _number[key]) return;
@@ -42,9 +69,18 @@ Object.keys(_number).forEach(function (key) {
42
69
  }
43
70
  });
44
71
  });
45
-
72
+ var _parseFilter = require("./parse-filter");
73
+ Object.keys(_parseFilter).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _parseFilter[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return _parseFilter[key];
80
+ }
81
+ });
82
+ });
46
83
  var _registry = require("./registry");
47
-
48
84
  Object.keys(_registry).forEach(function (key) {
49
85
  if (key === "default" || key === "__esModule") return;
50
86
  if (key in exports && exports[key] === _registry[key]) return;
@@ -55,9 +91,7 @@ Object.keys(_registry).forEach(function (key) {
55
91
  }
56
92
  });
57
93
  });
58
-
59
94
  var _uid = require("./uid");
60
-
61
95
  Object.keys(_uid).forEach(function (key) {
62
96
  if (key === "default" || key === "__esModule") return;
63
97
  if (key in exports && exports[key] === _uid[key]) return;
@@ -0,0 +1,16 @@
1
+ declare type BuildGraphOptions = {
2
+ direction?: 'forward' | 'reverse';
3
+ collections: any[];
4
+ };
5
+ export declare class CollectionsGraph {
6
+ static graphlib(): any;
7
+ static connectedNodes(options: BuildGraphOptions & {
8
+ nodes: Array<string>;
9
+ excludes?: Array<string>;
10
+ }): unknown[];
11
+ static preOrder(options: BuildGraphOptions & {
12
+ node: string;
13
+ }): any;
14
+ static build(options: BuildGraphOptions): any;
15
+ }
16
+ export {};
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CollectionsGraph = void 0;
7
+ function graphlib() {
8
+ const data = _interopRequireWildcard(require("graphlib"));
9
+ graphlib = function graphlib() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _lodash() {
15
+ const data = require("lodash");
16
+ _lodash = function _lodash() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+ 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; } } }; }
24
+ 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); }
25
+ 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; }
26
+ class CollectionsGraph {
27
+ static graphlib() {
28
+ return graphlib();
29
+ }
30
+ static connectedNodes(options) {
31
+ const nodes = (0, _lodash().castArray)(options.nodes);
32
+ const excludes = (0, _lodash().castArray)(options.excludes || []);
33
+ const graph = CollectionsGraph.build(options);
34
+ const connectedNodes = new Set();
35
+ var _iterator = _createForOfIteratorHelper(nodes),
36
+ _step;
37
+ try {
38
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
39
+ const node = _step.value;
40
+ const connected = graphlib().alg.preorder(graph, node);
41
+ var _iterator2 = _createForOfIteratorHelper(connected),
42
+ _step2;
43
+ try {
44
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
45
+ const connectedNode = _step2.value;
46
+ if (excludes.includes(connectedNode)) continue;
47
+ connectedNodes.add(connectedNode);
48
+ }
49
+ } catch (err) {
50
+ _iterator2.e(err);
51
+ } finally {
52
+ _iterator2.f();
53
+ }
54
+ }
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+ return Array.from(connectedNodes);
61
+ }
62
+ static preOrder(options) {
63
+ return CollectionsGraph.graphlib().alg.preorder(CollectionsGraph.build(options), options.node);
64
+ }
65
+ static build(options) {
66
+ const collections = options.collections;
67
+ const direction = (options === null || options === void 0 ? void 0 : options.direction) || 'forward';
68
+ const isForward = direction === 'forward';
69
+ const graph = new (graphlib().Graph)();
70
+ var _iterator3 = _createForOfIteratorHelper(collections),
71
+ _step3;
72
+ try {
73
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
74
+ const collection = _step3.value;
75
+ graph.setNode(collection.name);
76
+ }
77
+ } catch (err) {
78
+ _iterator3.e(err);
79
+ } finally {
80
+ _iterator3.f();
81
+ }
82
+ var _iterator4 = _createForOfIteratorHelper(collections),
83
+ _step4;
84
+ try {
85
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
86
+ const collection = _step4.value;
87
+ const parents = collection.inherits || [];
88
+ var _iterator5 = _createForOfIteratorHelper(parents),
89
+ _step5;
90
+ try {
91
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
92
+ const parent = _step5.value;
93
+ if (isForward) {
94
+ graph.setEdge(collection.name, parent);
95
+ } else {
96
+ graph.setEdge(parent, collection.name);
97
+ }
98
+ }
99
+ } catch (err) {
100
+ _iterator5.e(err);
101
+ } finally {
102
+ _iterator5.f();
103
+ }
104
+ var _iterator6 = _createForOfIteratorHelper(collection.fields || []),
105
+ _step6;
106
+ try {
107
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
108
+ const field = _step6.value;
109
+ if (field.type === 'hasMany' || field.type === 'belongsTo' || field.type === 'hasOne') {
110
+ isForward ? graph.setEdge(collection.name, field.target) : graph.setEdge(field.target, collection.name);
111
+ }
112
+ if (field.type === 'belongsToMany') {
113
+ const throughCollection = field.through;
114
+ if (isForward) {
115
+ graph.setEdge(collection.name, throughCollection);
116
+ graph.setEdge(throughCollection, field.target);
117
+ } else {
118
+ graph.setEdge(field.target, throughCollection);
119
+ graph.setEdge(throughCollection, collection.name);
120
+ }
121
+ }
122
+ }
123
+ } catch (err) {
124
+ _iterator6.e(err);
125
+ } finally {
126
+ _iterator6.f();
127
+ }
128
+ }
129
+ } catch (err) {
130
+ _iterator4.e(err);
131
+ } finally {
132
+ _iterator4.f();
133
+ }
134
+ return graph;
135
+ }
136
+ }
137
+ exports.CollectionsGraph = CollectionsGraph;
@@ -0,0 +1,5 @@
1
+ export declare const isString: (value: any) => value is string;
2
+ export declare const isArray: (value: any) => value is any[];
3
+ export declare const isEmpty: (value: unknown) => boolean;
4
+ export declare const isPlainObject: (value: any) => boolean;
5
+ export declare const hasEmptyValue: (objOrArr: object | any[]) => any;
package/lib/common.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isString = exports.isPlainObject = exports.isEmpty = exports.isArray = exports.hasEmptyValue = void 0;
7
+ const isString = value => {
8
+ return typeof value === 'string';
9
+ };
10
+ exports.isString = isString;
11
+ const isArray = value => {
12
+ return Array.isArray(value);
13
+ };
14
+ exports.isArray = isArray;
15
+ const isEmpty = value => {
16
+ if (isPlainObject(value)) {
17
+ return Object.keys(value).length === 0;
18
+ }
19
+ if (Array.isArray(value)) {
20
+ return value.length === 0;
21
+ }
22
+ return !value;
23
+ };
24
+ exports.isEmpty = isEmpty;
25
+ const isPlainObject = value => {
26
+ if (Object.prototype.toString.call(value) !== '[object Object]') {
27
+ return false;
28
+ }
29
+ const prototype = Object.getPrototypeOf(value);
30
+ return prototype === null || prototype === Object.prototype;
31
+ };
32
+ exports.isPlainObject = isPlainObject;
33
+ const hasEmptyValue = objOrArr => {
34
+ let result = true;
35
+ for (const key in objOrArr) {
36
+ result = false;
37
+ if (isArray(objOrArr[key]) && objOrArr[key].length === 0) {
38
+ return true;
39
+ }
40
+ if (!objOrArr[key]) {
41
+ return true;
42
+ }
43
+ if (isPlainObject(objOrArr[key]) || isArray(objOrArr[key])) {
44
+ return hasEmptyValue(objOrArr[key]);
45
+ }
46
+ }
47
+ return result;
48
+ };
49
+ exports.hasEmptyValue = hasEmptyValue;
package/lib/date.d.ts CHANGED
@@ -3,15 +3,15 @@ export interface Str2momentOptions {
3
3
  gmt?: boolean;
4
4
  picker?: 'year' | 'month' | 'week' | 'quarter';
5
5
  utcOffset?: any;
6
+ utc?: boolean;
6
7
  }
7
8
  export declare const getDefaultFormat: (props: any) => any;
8
- export declare const toGmt: (value: moment.Moment | moment.Moment[]) => string | string[] | moment.Moment | moment.Moment[];
9
- export declare const toLocal: (value: moment.Moment | moment.Moment[]) => string | string[] | moment.Moment | moment.Moment[];
9
+ export declare const toGmt: (value: moment.Moment) => string | moment.Moment;
10
+ export declare const toLocal: (value: moment.Moment) => string | any[] | moment.Moment;
10
11
  export declare const str2moment: (value?: string | string[], options?: Str2momentOptions) => any;
11
12
  export interface Moment2strOptions {
12
13
  showTime?: boolean;
13
14
  gmt?: boolean;
14
15
  picker?: 'year' | 'month' | 'week' | 'quarter';
15
16
  }
16
- export declare const moment2str: (value?: moment.Moment | moment.Moment[], options?: Moment2strOptions) => string | string[] | moment.Moment | moment.Moment[];
17
- export declare const mapDateFormat: () => (props: any) => any;
17
+ export declare const moment2str: (value?: moment.Moment, options?: Moment2strOptions) => string | any[] | moment.Moment;
package/lib/date.js CHANGED
@@ -3,39 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toLocal = exports.toGmt = exports.str2moment = exports.moment2str = exports.mapDateFormat = exports.getDefaultFormat = void 0;
7
-
6
+ exports.toLocal = exports.toGmt = exports.str2moment = exports.moment2str = exports.getDefaultFormat = void 0;
8
7
  function _moment() {
9
8
  const data = _interopRequireDefault(require("moment"));
10
-
11
9
  _moment = function _moment() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
15
  const getDefaultFormat = props => {
27
16
  if (props.format) {
28
17
  return props.format;
29
18
  }
30
-
31
19
  if (props.dateFormat) {
32
20
  if (props['showTime']) {
33
21
  return `${props.dateFormat} ${props.timeFormat || 'HH:mm:ss'}`;
34
22
  }
35
-
36
23
  return props.dateFormat;
37
24
  }
38
-
39
25
  if (props['picker'] === 'month') {
40
26
  return 'YYYY-MM';
41
27
  } else if (props['picker'] === 'quarter') {
@@ -45,139 +31,90 @@ const getDefaultFormat = props => {
45
31
  } else if (props['picker'] === 'week') {
46
32
  return 'YYYY-wo';
47
33
  }
48
-
49
34
  return props['showTime'] ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
50
35
  };
51
-
52
36
  exports.getDefaultFormat = getDefaultFormat;
53
-
54
37
  const toGmt = value => {
55
- if (!value) {
38
+ if (!value || !_moment().default.isMoment(value)) {
56
39
  return value;
57
40
  }
58
-
59
- if (Array.isArray(value)) {
60
- return value.map(val => `${val.format('YYYY-MM-DD')}T${val.format('HH:mm:ss.SSS')}Z`);
61
- }
62
-
63
- if (_moment().default.isMoment(value)) {
64
- return `${value.format('YYYY-MM-DD')}T${value.format('HH:mm:ss.SSS')}Z`;
65
- }
41
+ return `${value.format('YYYY-MM-DD')}T${value.format('HH:mm:ss.SSS')}Z`;
66
42
  };
67
-
68
43
  exports.toGmt = toGmt;
69
-
70
44
  const toLocal = value => {
71
45
  if (!value) {
72
46
  return value;
73
47
  }
74
-
75
48
  if (Array.isArray(value)) {
76
- return value.map(val => val.toISOString());
49
+ return value.map(val => val.startOf('second').toISOString());
77
50
  }
78
-
79
51
  if (_moment().default.isMoment(value)) {
80
- return value.toISOString();
52
+ return value.startOf('second').toISOString();
81
53
  }
82
54
  };
83
-
84
55
  exports.toLocal = toLocal;
85
-
86
56
  const toMoment = (val, options) => {
87
57
  if (!val) {
88
58
  return;
89
59
  }
90
-
91
60
  const offset = options.utcOffset || -1 * new Date().getTimezoneOffset();
92
-
61
+ const gmt = options.gmt,
62
+ picker = options.picker,
63
+ _options$utc = options.utc,
64
+ utc = _options$utc === void 0 ? true : _options$utc;
65
+ if (!utc) {
66
+ return (0, _moment().default)(val);
67
+ }
93
68
  if (_moment().default.isMoment(val)) {
94
69
  return val.utcOffset(offset);
95
70
  }
96
-
97
- const gmt = options.gmt,
98
- picker = options.picker;
99
-
100
71
  if (gmt || picker) {
101
72
  return (0, _moment().default)(val).utcOffset(0);
102
73
  }
103
-
104
74
  return (0, _moment().default)(val).utcOffset(offset);
105
75
  };
106
-
107
76
  const str2moment = (value, options = {}) => {
108
77
  return Array.isArray(value) ? value.map(val => {
109
78
  return toMoment(val, options);
110
79
  }) : value ? toMoment(value, options) : value;
111
80
  };
112
-
113
81
  exports.str2moment = str2moment;
114
-
115
82
  const toStringByPicker = (value, picker) => {
116
83
  if (picker === 'year') {
117
84
  return value.format('YYYY') + '-01-01T00:00:00.000Z';
118
85
  }
119
-
120
86
  if (picker === 'month') {
121
87
  return value.format('YYYY-MM') + '-01T00:00:00.000Z';
122
88
  }
123
-
124
89
  if (picker === 'quarter') {
125
90
  return value.format('YYYY-MM') + '-01T00:00:00.000Z';
126
91
  }
127
-
128
92
  if (picker === 'week') {
129
93
  return value.format('YYYY-MM-DD') + 'T00:00:00.000Z';
130
94
  }
131
-
132
95
  return value.format('YYYY-MM-DD') + 'T00:00:00.000Z';
133
96
  };
134
-
135
97
  const toGmtByPicker = (value, picker) => {
136
98
  if (!value) {
137
99
  return value;
138
100
  }
139
-
140
101
  if (Array.isArray(value)) {
141
102
  return value.map(val => toStringByPicker(val, picker));
142
103
  }
143
-
144
104
  if (_moment().default.isMoment(value)) {
145
105
  return toStringByPicker(value, picker);
146
106
  }
147
107
  };
148
-
149
108
  const moment2str = (value, options = {}) => {
150
109
  const showTime = options.showTime,
151
- gmt = options.gmt,
152
- picker = options.picker;
153
-
110
+ gmt = options.gmt,
111
+ picker = options.picker;
154
112
  if (!value) {
155
113
  return value;
156
114
  }
157
-
158
115
  if (showTime) {
159
116
  return gmt ? toGmt(value) : toLocal(value);
160
117
  }
161
-
162
118
  return toGmtByPicker(value, picker);
163
119
  };
164
-
165
- exports.moment2str = moment2str;
166
-
167
- const mapDateFormat = function mapDateFormat() {
168
- return props => {
169
- const format = getDefaultFormat(props);
170
- const _onChange = props.onChange;
171
- return _objectSpread(_objectSpread({}, props), {}, {
172
- format: format,
173
- value: str2moment(props.value, props),
174
- onChange: value => {
175
- if (_onChange) {
176
- _onChange(moment2str(value, props));
177
- }
178
- }
179
- });
180
- };
181
- };
182
-
183
- exports.mapDateFormat = mapDateFormat;
120
+ exports.moment2str = moment2str;
@@ -0,0 +1 @@
1
+ export declare const forEach: (obj: any, callback: (value: any, key: string | number) => void) => void;