dtable-utils 5.0.20 → 5.0.21-beta.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.
@@ -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;
package/lib/index.js CHANGED
@@ -210,6 +210,7 @@ exports.getCollaboratorsName = collaborator.getCollaboratorsName;
210
210
  exports.getCollaboratorsNames = collaborator.getCollaboratorsNames;
211
211
  exports.getGeolocationByGranularity = geolocation.getGeolocationByGranularity;
212
212
  exports.getGeolocationDisplayString = geolocation.getGeolocationDisplayString;
213
+ exports.getGeolocationFormattedPoint = geolocation.getGeolocationFormattedPoint;
213
214
  exports.getDepartmentName = department.getDepartmentName;
214
215
  exports.getDigitalSignImageUrl = digitalSign.getDigitalSignImageUrl;
215
216
  exports.getLongtextDisplayString = longText.getLongtextDisplayString;
@@ -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-beta.2",
4
4
  "description": "dtable common utils",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",