dtable-utils 5.0.20 → 5.0.21

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.
@@ -14,6 +14,7 @@ import '@babel/runtime/helpers/typeof';
14
14
  import '../../date.js';
15
15
  import '@babel/runtime/helpers/defineProperty';
16
16
  import '@babel/runtime/helpers/toConsumableArray';
17
+ import '@babel/runtime/helpers/slicedToArray';
17
18
 
18
19
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
19
20
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -131,7 +131,6 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
131
131
  * @param {object} formulaRows formula results of rows. Default as "{}"
132
132
  * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
133
133
  * @param {array} departments e.g. [{ name, id }, ...]. Default as "[]"
134
- * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
135
134
  * @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
136
135
  * @returns formatted cell value, string|array
137
136
  */
@@ -144,8 +143,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
144
143
  collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
145
144
  _ref2$departments = _ref2.departments,
146
145
  departments = _ref2$departments === void 0 ? [] : _ref2$departments,
147
- _ref2$isBaiduMap = _ref2.isBaiduMap,
148
- isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
149
146
  _ref2$geolocationHyph = _ref2.geolocationHyphen,
150
147
  geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
151
148
  if (!row) return '';
@@ -166,7 +163,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
166
163
  case CellType.GEOLOCATION:
167
164
  {
168
165
  return getGeolocationDisplayString(cellValue, data, {
169
- isBaiduMap: isBaiduMap,
170
166
  hyphen: geolocationHyphen
171
167
  });
172
168
  }
@@ -1,19 +1,54 @@
1
1
  import { GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
2
2
  import { GEOLOCATION_FORMAT } from '../constants/column.js';
3
- import { isValidPosition } from '../validate/geolocation.js';
3
+ import { isNumber } from '../number.js';
4
+ import { DMS_SPLITTER_TYPE, LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE } from '../constants/geolocation.js';
5
+
6
+ /**
7
+ * Convert decimal to DMS
8
+ * @param {number} lat
9
+ * @param {bool} isLat Latitude: N/S, Longitude: E/W
10
+ * @returns { dms, direction }, object
11
+ */
12
+ var convertToDMS = function convertToDMS(decimal) {
13
+ var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
14
+ if (!isNumber(decimal) && typeof decimal !== 'string') return {};
15
+ var numDecimal = typeof decimal === 'string' ? Number.parseFloat(decimal) : decimal;
16
+ if (!isNumber(numDecimal)) return {};
17
+ var degrees = Math.floor(Math.abs(numDecimal));
18
+ var minutesDecimal = Number.parseFloat(((Math.abs(numDecimal) - degrees) * 60).toFixed(8));
19
+ var minutes = Math.floor(minutesDecimal);
20
+ var seconds = Number.parseFloat(((minutesDecimal - minutes) * 60).toFixed(8));
21
+ var direction = '';
22
+ if (isLat) {
23
+ direction = numDecimal >= 0 ? LAT_DIRECTION_TYPE.N : LAT_DIRECTION_TYPE.S;
24
+ } else {
25
+ direction = numDecimal >= 0 ? LNG_DIRECTION_TYPE.E : LNG_DIRECTION_TYPE.W;
26
+ }
27
+ return {
28
+ dms: "".concat(degrees).concat(DMS_SPLITTER_TYPE.DEG).concat(minutes).concat(DMS_SPLITTER_TYPE.MIN).concat(seconds).concat(DMS_SPLITTER_TYPE.SEC),
29
+ direction: direction
30
+ };
31
+ };
32
+ var getLatLngDisplayString = function getLatLngDisplayString(lat, lng) {
33
+ var _convertToDMS = convertToDMS(lat, true),
34
+ lat_dms = _convertToDMS.dms,
35
+ lat_direction = _convertToDMS.direction;
36
+ var _convertToDMS2 = convertToDMS(lng),
37
+ lng_dms = _convertToDMS2.dms,
38
+ lng_direction = _convertToDMS2.direction;
39
+ if (!lat_dms || !lng_dms) return '';
40
+ return "".concat(lat_direction).concat(lat_dms, ", ").concat(lng_direction).concat(lng_dms);
41
+ };
4
42
 
5
43
  /**
6
44
  * Get formatted geolocation
7
45
  * @param {object} loc
8
46
  * @param {object} formats , e.g. { geo_format, ... }
9
- * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
10
47
  * @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
11
48
  * @returns formatted geolocation, string
12
49
  */
13
50
  var getGeolocationDisplayString = function getGeolocationDisplayString(loc, formats) {
14
51
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
15
- _ref$isBaiduMap = _ref.isBaiduMap,
16
- isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
17
52
  _ref$hyphen = _ref.hyphen,
18
53
  hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
19
54
  if (!loc) return '';
@@ -24,8 +59,7 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
24
59
  {
25
60
  var lng = loc.lng,
26
61
  lat = loc.lat;
27
- if (!isValidPosition(lng, lat)) return '';
28
- return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
62
+ return getLatLngDisplayString(lat, lng);
29
63
  }
30
64
  case GEOLOCATION_FORMAT.COUNTRY_REGION:
31
65
  {
@@ -101,4 +135,4 @@ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocati
101
135
  }
102
136
  };
103
137
 
104
- export { getGeolocationByGranularity, getGeolocationDisplayString };
138
+ export { convertToDMS, getGeolocationByGranularity, getGeolocationDisplayString, getLatLngDisplayString };
@@ -1,39 +1,148 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { GEOLOCATION_FORMAT } from '../constants/column.js';
3
+ import '../constants/filter/filter-column-options.js';
4
+ import '../constants/filter/filter-modifier.js';
5
+ import '../constants/filter/filter-predicate.js';
6
+ import '../constants/filter/filter-is-within.js';
7
+ import '../constants/formula.js';
8
+ import '../constants/sort.js';
9
+ import '../constants/group.js';
10
+ import { LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE, DMS_SPLITTER_TYPE } from '../constants/geolocation.js';
11
+ import { isNumber } from '../number.js';
12
+
1
13
  var provinceReg = /.+省|.+自治区|.+特别行政区|北京市|天津市|上海市|重庆市|安徽|福建|甘肃|广东|广西|贵州|海南|河北|河南|黑龙江|湖北|湖南|吉林|江苏|江西|辽宁|内蒙古|宁夏|青海|山东|山西|陕西|四川|西藏|新疆|云南|浙江|北京|上海|天津|重庆/;
2
14
  var cityReg = /.+自治州|[^市]+市|.+盟|.+地区|.+区划/;
3
15
  var districtReg = /(.+市|.+县|.+旗|.+区)/;
16
+ var LNG_LAT_REG = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
17
+ var DMS_DEG_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.DEG));
18
+ var DMS_MIN_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.MIN));
19
+ var DMS_SEC_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.SEC));
20
+ var parseDMS = function parseDMS(dms, direction) {
21
+ if (typeof dms !== 'string') {
22
+ return null;
23
+ }
24
+ var degMatches = dms.match(DMS_DEG_REG);
25
+ var minMatches = dms.match(DMS_MIN_REG);
26
+ var secMatches = dms.match(DMS_SEC_REG);
27
+ var strDeg = degMatches && degMatches[1];
28
+ var strMin = minMatches && minMatches[1];
29
+ var strSec = secMatches && secMatches[1];
30
+ if (!strDeg && !strMin && !strSec) {
31
+ // invalid DMS
32
+ return null;
33
+ }
34
+ var deg = Number.parseFloat(strDeg);
35
+ var min = Number.parseFloat(strMin);
36
+ var sec = Number.parseFloat(strSec);
37
+ if (!isNumber(deg) && !isNumber(min) && !isNumber(sec)) {
38
+ return null;
39
+ }
40
+ deg = deg || 0;
41
+ min = min || 0;
42
+ sec = sec || 0;
43
+ var decimal = deg + min / 60 + sec / 3600;
44
+ if (direction === LAT_DIRECTION_TYPE.S || direction === LNG_DIRECTION_TYPE.W) {
45
+ return -Math.abs(decimal);
46
+ }
47
+ return decimal;
48
+ };
49
+
50
+ /**
51
+ * Parse LatLng-DMS string to degree
52
+ * e.g. 'N30°50′50.55″, E30.50′50.55″'
53
+ * @param {string} strLatLng
54
+ * @returns { lat, lng }, object
55
+ */
56
+ var parseLatLngDMS = function parseLatLngDMS(strLatLngDMS) {
57
+ if (typeof strLatLngDMS !== 'string') {
58
+ return {};
59
+ }
60
+ var _strLatLngDMS$split$m = strLatLngDMS.split(',').map(function (str) {
61
+ return str ? str.trim() : '';
62
+ }),
63
+ _strLatLngDMS$split$m2 = _slicedToArray(_strLatLngDMS$split$m, 2),
64
+ strLatDMS = _strLatLngDMS$split$m2[0],
65
+ strLngDMS = _strLatLngDMS$split$m2[1];
66
+ if (!strLatDMS || !strLngDMS) {
67
+ // invalid LatLng DMS
68
+ return {};
69
+ }
70
+ var latDirection = strLatDMS[0];
71
+ var lngDirection = strLngDMS[0];
72
+ if (!latDirection || !lngDirection || latDirection !== LAT_DIRECTION_TYPE.N && latDirection !== LAT_DIRECTION_TYPE.S || lngDirection !== LNG_DIRECTION_TYPE.E && lngDirection !== LNG_DIRECTION_TYPE.W) {
73
+ // invalid lat/lng direction
74
+ return {};
75
+ }
76
+ var strLat = strLatDMS.substring(1);
77
+ var strLng = strLngDMS.substring(1);
78
+ var lat = parseDMS(strLat, latDirection);
79
+ var lng = parseDMS(strLng, lngDirection);
80
+ if (!isNumber(lat) || !isNumber(lng)) {
81
+ return {};
82
+ }
83
+ return {
84
+ lat: lat,
85
+ lng: lng
86
+ };
87
+ };
88
+
89
+ /**
90
+ * Parse LatLng-DMS string to degree
91
+ * e.g. '30.50, 30.50'
92
+ * @param {string} strLatLng
93
+ * @returns { lat, lng }, object
94
+ */
95
+ var parseLngLatDegree = function parseLngLatDegree(strLngLat) {
96
+ // match floating point numbers
97
+ // ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
98
+ // ^0\.\d+$ --> floating point type starting with 0
99
+ // ^[1-9]\d*$ --> non-zero integer
100
+ // 0
101
+ if (typeof strLngLat !== 'string') {
102
+ return {};
103
+ }
104
+ var _strLngLat$split$map = strLngLat.split(',').map(function (str) {
105
+ return str ? str.trim() : '';
106
+ }),
107
+ _strLngLat$split$map2 = _slicedToArray(_strLngLat$split$map, 2),
108
+ strLng = _strLngLat$split$map2[0],
109
+ strLat = _strLngLat$split$map2[1];
110
+ if (!strLng || !strLat || !strLng.match(LNG_LAT_REG) || !strLat.match(LNG_LAT_REG)) {
111
+ return {};
112
+ }
113
+ var numLng = Number(strLng);
114
+ var numLat = Number(strLat);
115
+ if (!isNumber(numLng) || !isNumber(numLat)) {
116
+ return {};
117
+ }
118
+ return {
119
+ lat: numLat,
120
+ lng: numLng
121
+ };
122
+ };
123
+
124
+ /**
125
+ * Parse LatLng-DMS/LngLat-Degree string to degree
126
+ * @param {string} strLatLng
127
+ * @returns { lat, lng }, object
128
+ */
129
+ var parseLatLng = function parseLatLng(strLatLng) {
130
+ if (strLatLng && (strLatLng.includes(LAT_DIRECTION_TYPE.N) && strLatLng.includes(LNG_DIRECTION_TYPE.E) || strLatLng.includes(LAT_DIRECTION_TYPE.S) && strLatLng.includes(LNG_DIRECTION_TYPE.W))) {
131
+ return parseLatLngDMS(strLatLng);
132
+ }
133
+ return parseLngLatDegree(strLatLng);
134
+ };
4
135
  var formatTextToGeolocation = function formatTextToGeolocation(value, columnData) {
5
136
  // compatible with the old version, the old version data may be null or undefined
6
137
  var _ref = columnData || {},
7
138
  _ref$geo_format = _ref.geo_format,
8
- geo_format = _ref$geo_format === void 0 ? 'geolocation' : _ref$geo_format;
139
+ geo_format = _ref$geo_format === void 0 ? GEOLOCATION_FORMAT.GEOLOCATION : _ref$geo_format;
9
140
  var cellValue = value || '';
10
141
  if (cellValue.length < 3) {
11
142
  return {};
12
143
  }
13
- if (geo_format === 'lng_lat') {
14
- // match floating point numbers
15
- // ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
16
- // ^0\.\d+$ --> floating point type starting with 0
17
- // ^[1-9]\d*$ --> non-zero integer
18
- // 0
19
- var reg = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
20
- if (cellValue.indexOf(',') < 0) return {};
21
- var lng_lat = cellValue.split(',');
22
- if (lng_lat.length !== 2) {
23
- return {};
24
- }
25
- var lng = lng_lat[0].trim();
26
- var lat = lng_lat[1].trim();
27
- if (!lng || !lat) {
28
- return {};
29
- }
30
- if (!lng.match(reg) || !lat.match(reg)) {
31
- return {};
32
- }
33
- return {
34
- lng: lng,
35
- lat: lat
36
- };
144
+ if (geo_format === GEOLOCATION_FORMAT.LNG_LAT) {
145
+ return parseLatLng(cellValue);
37
146
  }
38
147
  var matchedProvince = cellValue.match(provinceReg);
39
148
  var province = '';
@@ -65,4 +174,4 @@ var formatTextToGeolocation = function formatTextToGeolocation(value, columnData
65
174
  };
66
175
  };
67
176
 
68
- export { formatTextToGeolocation };
177
+ export { formatTextToGeolocation, parseDMS, parseLatLng, parseLatLngDMS, parseLngLatDegree };
@@ -0,0 +1,17 @@
1
+ var LAT_DIRECTION_TYPE = {
2
+ N: 'N',
3
+ // North
4
+ S: 'S' // South
5
+ };
6
+ var LNG_DIRECTION_TYPE = {
7
+ E: 'E',
8
+ // East
9
+ W: 'W' // West
10
+ };
11
+ var DMS_SPLITTER_TYPE = {
12
+ DEG: '°',
13
+ MIN: '′',
14
+ SEC: '″'
15
+ };
16
+
17
+ export { DMS_SPLITTER_TYPE, LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE };
@@ -15,6 +15,7 @@ import '../constants/filter/filter-is-within.js';
15
15
  import '../constants/sort.js';
16
16
  import '../constants/group.js';
17
17
  import { isNumericColumn } from '../column/number.js';
18
+ import '@babel/runtime/helpers/slicedToArray';
18
19
  import 'dayjs';
19
20
  import { getGroupsRowIds as _getGroupsRowIds } from '../group/core.js';
20
21
 
@@ -18,6 +18,7 @@ require('@babel/runtime/helpers/typeof');
18
18
  require('../../date.js');
19
19
  require('@babel/runtime/helpers/defineProperty');
20
20
  require('@babel/runtime/helpers/toConsumableArray');
21
+ require('@babel/runtime/helpers/slicedToArray');
21
22
 
22
23
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
23
24
 
@@ -139,7 +139,6 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
139
139
  * @param {object} formulaRows formula results of rows. Default as "{}"
140
140
  * @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
141
141
  * @param {array} departments e.g. [{ name, id }, ...]. Default as "[]"
142
- * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
143
142
  * @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
144
143
  * @returns formatted cell value, string|array
145
144
  */
@@ -152,8 +151,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
152
151
  collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
153
152
  _ref2$departments = _ref2.departments,
154
153
  departments = _ref2$departments === void 0 ? [] : _ref2$departments,
155
- _ref2$isBaiduMap = _ref2.isBaiduMap,
156
- isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
157
154
  _ref2$geolocationHyph = _ref2.geolocationHyphen,
158
155
  geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
159
156
  if (!row) return '';
@@ -174,7 +171,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
174
171
  case cellType.CellType.GEOLOCATION:
175
172
  {
176
173
  return geolocation.getGeolocationDisplayString(cellValue, data, {
177
- isBaiduMap: isBaiduMap,
178
174
  hyphen: geolocationHyphen
179
175
  });
180
176
  }
@@ -4,20 +4,55 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var group = require('../constants/group.js');
6
6
  var column = require('../constants/column.js');
7
- var geolocation = require('../validate/geolocation.js');
7
+ var number = require('../number.js');
8
+ var geolocation = require('../constants/geolocation.js');
9
+
10
+ /**
11
+ * Convert decimal to DMS
12
+ * @param {number} lat
13
+ * @param {bool} isLat Latitude: N/S, Longitude: E/W
14
+ * @returns { dms, direction }, object
15
+ */
16
+ var convertToDMS = function convertToDMS(decimal) {
17
+ var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
18
+ if (!number.isNumber(decimal) && typeof decimal !== 'string') return {};
19
+ var numDecimal = typeof decimal === 'string' ? Number.parseFloat(decimal) : decimal;
20
+ if (!number.isNumber(numDecimal)) return {};
21
+ var degrees = Math.floor(Math.abs(numDecimal));
22
+ var minutesDecimal = Number.parseFloat(((Math.abs(numDecimal) - degrees) * 60).toFixed(8));
23
+ var minutes = Math.floor(minutesDecimal);
24
+ var seconds = Number.parseFloat(((minutesDecimal - minutes) * 60).toFixed(8));
25
+ var direction = '';
26
+ if (isLat) {
27
+ direction = numDecimal >= 0 ? geolocation.LAT_DIRECTION_TYPE.N : geolocation.LAT_DIRECTION_TYPE.S;
28
+ } else {
29
+ direction = numDecimal >= 0 ? geolocation.LNG_DIRECTION_TYPE.E : geolocation.LNG_DIRECTION_TYPE.W;
30
+ }
31
+ return {
32
+ dms: "".concat(degrees).concat(geolocation.DMS_SPLITTER_TYPE.DEG).concat(minutes).concat(geolocation.DMS_SPLITTER_TYPE.MIN).concat(seconds).concat(geolocation.DMS_SPLITTER_TYPE.SEC),
33
+ direction: direction
34
+ };
35
+ };
36
+ var getLatLngDisplayString = function getLatLngDisplayString(lat, lng) {
37
+ var _convertToDMS = convertToDMS(lat, true),
38
+ lat_dms = _convertToDMS.dms,
39
+ lat_direction = _convertToDMS.direction;
40
+ var _convertToDMS2 = convertToDMS(lng),
41
+ lng_dms = _convertToDMS2.dms,
42
+ lng_direction = _convertToDMS2.direction;
43
+ if (!lat_dms || !lng_dms) return '';
44
+ return "".concat(lat_direction).concat(lat_dms, ", ").concat(lng_direction).concat(lng_dms);
45
+ };
8
46
 
9
47
  /**
10
48
  * Get formatted geolocation
11
49
  * @param {object} loc
12
50
  * @param {object} formats , e.g. { geo_format, ... }
13
- * @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
14
51
  * @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
15
52
  * @returns formatted geolocation, string
16
53
  */
17
54
  var getGeolocationDisplayString = function getGeolocationDisplayString(loc, formats) {
18
55
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
19
- _ref$isBaiduMap = _ref.isBaiduMap,
20
- isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
21
56
  _ref$hyphen = _ref.hyphen,
22
57
  hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
23
58
  if (!loc) return '';
@@ -28,8 +63,7 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
28
63
  {
29
64
  var lng = loc.lng,
30
65
  lat = loc.lat;
31
- if (!geolocation.isValidPosition(lng, lat)) return '';
32
- return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
66
+ return getLatLngDisplayString(lat, lng);
33
67
  }
34
68
  case column.GEOLOCATION_FORMAT.COUNTRY_REGION:
35
69
  {
@@ -105,5 +139,7 @@ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocati
105
139
  }
106
140
  };
107
141
 
142
+ exports.convertToDMS = convertToDMS;
108
143
  exports.getGeolocationByGranularity = getGeolocationByGranularity;
109
144
  exports.getGeolocationDisplayString = getGeolocationDisplayString;
145
+ exports.getLatLngDisplayString = getLatLngDisplayString;
@@ -2,42 +2,155 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
+ var column = require('../constants/column.js');
7
+ require('../constants/filter/filter-column-options.js');
8
+ require('../constants/filter/filter-modifier.js');
9
+ require('../constants/filter/filter-predicate.js');
10
+ require('../constants/filter/filter-is-within.js');
11
+ require('../constants/formula.js');
12
+ require('../constants/sort.js');
13
+ require('../constants/group.js');
14
+ var geolocation = require('../constants/geolocation.js');
15
+ var number = require('../number.js');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
20
+
5
21
  var provinceReg = /.+省|.+自治区|.+特别行政区|北京市|天津市|上海市|重庆市|安徽|福建|甘肃|广东|广西|贵州|海南|河北|河南|黑龙江|湖北|湖南|吉林|江苏|江西|辽宁|内蒙古|宁夏|青海|山东|山西|陕西|四川|西藏|新疆|云南|浙江|北京|上海|天津|重庆/;
6
22
  var cityReg = /.+自治州|[^市]+市|.+盟|.+地区|.+区划/;
7
23
  var districtReg = /(.+市|.+县|.+旗|.+区)/;
24
+ var LNG_LAT_REG = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
25
+ var DMS_DEG_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(geolocation.DMS_SPLITTER_TYPE.DEG));
26
+ var DMS_MIN_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(geolocation.DMS_SPLITTER_TYPE.MIN));
27
+ var DMS_SEC_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(geolocation.DMS_SPLITTER_TYPE.SEC));
28
+ var parseDMS = function parseDMS(dms, direction) {
29
+ if (typeof dms !== 'string') {
30
+ return null;
31
+ }
32
+ var degMatches = dms.match(DMS_DEG_REG);
33
+ var minMatches = dms.match(DMS_MIN_REG);
34
+ var secMatches = dms.match(DMS_SEC_REG);
35
+ var strDeg = degMatches && degMatches[1];
36
+ var strMin = minMatches && minMatches[1];
37
+ var strSec = secMatches && secMatches[1];
38
+ if (!strDeg && !strMin && !strSec) {
39
+ // invalid DMS
40
+ return null;
41
+ }
42
+ var deg = Number.parseFloat(strDeg);
43
+ var min = Number.parseFloat(strMin);
44
+ var sec = Number.parseFloat(strSec);
45
+ if (!number.isNumber(deg) && !number.isNumber(min) && !number.isNumber(sec)) {
46
+ return null;
47
+ }
48
+ deg = deg || 0;
49
+ min = min || 0;
50
+ sec = sec || 0;
51
+ var decimal = deg + min / 60 + sec / 3600;
52
+ if (direction === geolocation.LAT_DIRECTION_TYPE.S || direction === geolocation.LNG_DIRECTION_TYPE.W) {
53
+ return -Math.abs(decimal);
54
+ }
55
+ return decimal;
56
+ };
57
+
58
+ /**
59
+ * Parse LatLng-DMS string to degree
60
+ * e.g. 'N30°50′50.55″, E30.50′50.55″'
61
+ * @param {string} strLatLng
62
+ * @returns { lat, lng }, object
63
+ */
64
+ var parseLatLngDMS = function parseLatLngDMS(strLatLngDMS) {
65
+ if (typeof strLatLngDMS !== 'string') {
66
+ return {};
67
+ }
68
+ var _strLatLngDMS$split$m = strLatLngDMS.split(',').map(function (str) {
69
+ return str ? str.trim() : '';
70
+ }),
71
+ _strLatLngDMS$split$m2 = _slicedToArray__default["default"](_strLatLngDMS$split$m, 2),
72
+ strLatDMS = _strLatLngDMS$split$m2[0],
73
+ strLngDMS = _strLatLngDMS$split$m2[1];
74
+ if (!strLatDMS || !strLngDMS) {
75
+ // invalid LatLng DMS
76
+ return {};
77
+ }
78
+ var latDirection = strLatDMS[0];
79
+ var lngDirection = strLngDMS[0];
80
+ if (!latDirection || !lngDirection || latDirection !== geolocation.LAT_DIRECTION_TYPE.N && latDirection !== geolocation.LAT_DIRECTION_TYPE.S || lngDirection !== geolocation.LNG_DIRECTION_TYPE.E && lngDirection !== geolocation.LNG_DIRECTION_TYPE.W) {
81
+ // invalid lat/lng direction
82
+ return {};
83
+ }
84
+ var strLat = strLatDMS.substring(1);
85
+ var strLng = strLngDMS.substring(1);
86
+ var lat = parseDMS(strLat, latDirection);
87
+ var lng = parseDMS(strLng, lngDirection);
88
+ if (!number.isNumber(lat) || !number.isNumber(lng)) {
89
+ return {};
90
+ }
91
+ return {
92
+ lat: lat,
93
+ lng: lng
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Parse LatLng-DMS string to degree
99
+ * e.g. '30.50, 30.50'
100
+ * @param {string} strLatLng
101
+ * @returns { lat, lng }, object
102
+ */
103
+ var parseLngLatDegree = function parseLngLatDegree(strLngLat) {
104
+ // match floating point numbers
105
+ // ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
106
+ // ^0\.\d+$ --> floating point type starting with 0
107
+ // ^[1-9]\d*$ --> non-zero integer
108
+ // 0
109
+ if (typeof strLngLat !== 'string') {
110
+ return {};
111
+ }
112
+ var _strLngLat$split$map = strLngLat.split(',').map(function (str) {
113
+ return str ? str.trim() : '';
114
+ }),
115
+ _strLngLat$split$map2 = _slicedToArray__default["default"](_strLngLat$split$map, 2),
116
+ strLng = _strLngLat$split$map2[0],
117
+ strLat = _strLngLat$split$map2[1];
118
+ if (!strLng || !strLat || !strLng.match(LNG_LAT_REG) || !strLat.match(LNG_LAT_REG)) {
119
+ return {};
120
+ }
121
+ var numLng = Number(strLng);
122
+ var numLat = Number(strLat);
123
+ if (!number.isNumber(numLng) || !number.isNumber(numLat)) {
124
+ return {};
125
+ }
126
+ return {
127
+ lat: numLat,
128
+ lng: numLng
129
+ };
130
+ };
131
+
132
+ /**
133
+ * Parse LatLng-DMS/LngLat-Degree string to degree
134
+ * @param {string} strLatLng
135
+ * @returns { lat, lng }, object
136
+ */
137
+ var parseLatLng = function parseLatLng(strLatLng) {
138
+ if (strLatLng && (strLatLng.includes(geolocation.LAT_DIRECTION_TYPE.N) && strLatLng.includes(geolocation.LNG_DIRECTION_TYPE.E) || strLatLng.includes(geolocation.LAT_DIRECTION_TYPE.S) && strLatLng.includes(geolocation.LNG_DIRECTION_TYPE.W))) {
139
+ return parseLatLngDMS(strLatLng);
140
+ }
141
+ return parseLngLatDegree(strLatLng);
142
+ };
8
143
  var formatTextToGeolocation = function formatTextToGeolocation(value, columnData) {
9
144
  // compatible with the old version, the old version data may be null or undefined
10
145
  var _ref = columnData || {},
11
146
  _ref$geo_format = _ref.geo_format,
12
- geo_format = _ref$geo_format === void 0 ? 'geolocation' : _ref$geo_format;
147
+ geo_format = _ref$geo_format === void 0 ? column.GEOLOCATION_FORMAT.GEOLOCATION : _ref$geo_format;
13
148
  var cellValue = value || '';
14
149
  if (cellValue.length < 3) {
15
150
  return {};
16
151
  }
17
- if (geo_format === 'lng_lat') {
18
- // match floating point numbers
19
- // ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
20
- // ^0\.\d+$ --> floating point type starting with 0
21
- // ^[1-9]\d*$ --> non-zero integer
22
- // 0
23
- var reg = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
24
- if (cellValue.indexOf(',') < 0) return {};
25
- var lng_lat = cellValue.split(',');
26
- if (lng_lat.length !== 2) {
27
- return {};
28
- }
29
- var lng = lng_lat[0].trim();
30
- var lat = lng_lat[1].trim();
31
- if (!lng || !lat) {
32
- return {};
33
- }
34
- if (!lng.match(reg) || !lat.match(reg)) {
35
- return {};
36
- }
37
- return {
38
- lng: lng,
39
- lat: lat
40
- };
152
+ if (geo_format === column.GEOLOCATION_FORMAT.LNG_LAT) {
153
+ return parseLatLng(cellValue);
41
154
  }
42
155
  var matchedProvince = cellValue.match(provinceReg);
43
156
  var province = '';
@@ -70,3 +183,7 @@ var formatTextToGeolocation = function formatTextToGeolocation(value, columnData
70
183
  };
71
184
 
72
185
  exports.formatTextToGeolocation = formatTextToGeolocation;
186
+ exports.parseDMS = parseDMS;
187
+ exports.parseLatLng = parseLatLng;
188
+ exports.parseLatLngDMS = parseLatLngDMS;
189
+ exports.parseLngLatDegree = parseLngLatDegree;
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var LAT_DIRECTION_TYPE = {
6
+ N: 'N',
7
+ // North
8
+ S: 'S' // South
9
+ };
10
+ var LNG_DIRECTION_TYPE = {
11
+ E: 'E',
12
+ // East
13
+ W: 'W' // West
14
+ };
15
+ var DMS_SPLITTER_TYPE = {
16
+ DEG: '°',
17
+ MIN: '′',
18
+ SEC: '″'
19
+ };
20
+
21
+ exports.DMS_SPLITTER_TYPE = DMS_SPLITTER_TYPE;
22
+ exports.LAT_DIRECTION_TYPE = LAT_DIRECTION_TYPE;
23
+ exports.LNG_DIRECTION_TYPE = LNG_DIRECTION_TYPE;
@@ -19,6 +19,7 @@ require('../constants/filter/filter-is-within.js');
19
19
  require('../constants/sort.js');
20
20
  require('../constants/group.js');
21
21
  var number = require('../column/number.js');
22
+ require('@babel/runtime/helpers/slicedToArray');
22
23
  require('dayjs');
23
24
  var core$1 = require('../group/core.js');
24
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-utils",
3
- "version": "5.0.20",
3
+ "version": "5.0.21",
4
4
  "description": "dtable common utils",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",