@speleotica/frcsdata 4.1.1 → 4.2.0

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/FrcsShot.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { UnitizedNumber, Length, Angle } from '@speleotica/unitized';
2
+ import { FrcsUnits } from './FrcsTrip';
2
3
  export declare enum FrcsShotKind {
3
4
  Normal = " ",
4
5
  Horizontal = "H",
@@ -42,4 +43,14 @@ export type FrcsShot = {
42
43
  excludeDistance?: boolean | null;
43
44
  isSplay?: boolean | null;
44
45
  comment?: string | null;
46
+ /**
47
+ * In the edge case that the surveyors changed measurement units or
48
+ * corrected/uncorrected backsights in the middle of a trip, the measurements
49
+ * will be normalized to the initial trip settings, and this field will contain
50
+ * the actual values recorded, verbatim. The first shot of the group with
51
+ * changed units will include the changed units.
52
+ */
53
+ recorded?: FrcsShot & {
54
+ units?: FrcsUnits;
55
+ };
45
56
  };
package/FrcsTrip.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import { Unit, Length, Angle } from '@speleotica/unitized';
2
2
  import { FrcsShot } from './FrcsShot';
3
- export type FrcsTripHeader = {
4
- name: string;
5
- comment?: string | null;
6
- section?: string | null;
7
- date?: Date | null;
8
- team?: Array<string> | null;
3
+ export type FrcsUnits = {
9
4
  distanceUnit: Unit<Length>;
10
5
  azimuthUnit: Unit<Angle>;
11
6
  inclinationUnit: Unit<Angle>;
@@ -14,6 +9,13 @@ export type FrcsTripHeader = {
14
9
  hasBacksightAzimuth?: boolean | null;
15
10
  hasBacksightInclination?: boolean | null;
16
11
  };
12
+ export type FrcsTripHeader = FrcsUnits & {
13
+ name: string;
14
+ comment?: string | null;
15
+ section?: string | null;
16
+ date?: Date | null;
17
+ team?: Array<string> | null;
18
+ };
17
19
  export type FrcsTrip = {
18
20
  header: FrcsTripHeader;
19
21
  shots: Array<FrcsShot>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speleotica/frcsdata",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "description": "parser for Chip Hopper's survey data format used in Fisher Ridge Cave System",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -7,10 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = parseFrcsSurveyFile;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _parseSegment = require("parse-segment");
12
13
  var _unitized = require("@speleotica/unitized");
13
14
  var _FrcsShot = require("./FrcsShot.js");
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
17
  function _asyncIterator(r) { var n, t, o, e = 2; for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) { if (t && null != (n = r[t])) return n.call(r); if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r)); t = "@@asyncIterator", o = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
15
18
  function AsyncFromSyncIterator(r) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var n = r.done; return Promise.resolve(r.value).then(function (r) { return { value: r, done: n }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) { this.s = r, this.n = r.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(r) { var n = this.s["return"]; return void 0 === n ? Promise.resolve({ value: r, done: !0 }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); }, "throw": function _throw(r) { var n = this.s["return"]; return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(r); }
16
19
  function parseNumber(s, unit) {
@@ -167,7 +170,7 @@ function _parseFrcsSurveyFile() {
167
170
  _parseFrcsSurveyFile = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(file,
168
171
  // eslint-disable-line @typescript-eslint/no-explicit-any
169
172
  lines) {
170
- var cave, location, trips, errors, tripName, tripTeam, tripDate, inTripComment, tripCommentStartLine, tripCommentEndLine, tripComment, commentLines, trip, inBlockComment, section, commentFromStationLruds, addCommentLine, getComment, lineNumber, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _loop, _ret, _iterator, _step;
173
+ var cave, location, trips, errors, tripName, tripTeam, tripDate, inTripComment, tripCommentStartLine, tripCommentEndLine, tripComment, commentLines, trip, inBlockComment, section, commentFromStationLruds, addCommentLine, getComment, unitsChanged, alternateUnits, nextShotUnits, lineNumber, line, errored, error, parseUnits, validate, addShot, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _loop, _ret, _iterator, _step;
171
174
  return _regenerator["default"].wrap(function _callee$(_context2) {
172
175
  while (1) switch (_context2.prev = _context2.next) {
173
176
  case 0:
@@ -202,34 +205,127 @@ function _parseFrcsSurveyFile() {
202
205
  trip = null;
203
206
  inBlockComment = false;
204
207
  commentFromStationLruds = new Map();
208
+ unitsChanged = false;
205
209
  lineNumber = 0;
210
+ errored = false;
211
+ error = function error(message, startColumn, endColumn) {
212
+ errored = true;
213
+ errors.push(new _parseSegment.SegmentParseError(message, new _parseSegment.Segment({
214
+ value: line,
215
+ source: file,
216
+ startLine: lineNumber,
217
+ startCol: 0
218
+ }).substring(startColumn, endColumn)));
219
+ };
220
+ parseUnits = function parseUnits() {
221
+ // FT CC DD
222
+ // 01234567
223
+ var distanceUnit = parseLengthUnit(line.slice(0, 2));
224
+ if (!distanceUnit) {
225
+ distanceUnit = _unitized.Length.feet;
226
+ error('Invalid distance unit', 0, 2);
227
+ }
228
+ var azimuthUnit = parseAngleUnit(line[6]);
229
+ if (!azimuthUnit) {
230
+ azimuthUnit = _unitized.Angle.degrees;
231
+ error('Invalid azimuth unit', 6, 7);
232
+ }
233
+ var inclinationUnit = parseAngleUnit(line[7]);
234
+ if (!inclinationUnit) {
235
+ inclinationUnit = _unitized.Angle.degrees;
236
+ error('Invalid inclination unit', 7, 8);
237
+ }
238
+ var backsightAzimuthCorrected = line[3] === 'C';
239
+ var backsightInclinationCorrected = line[4] === 'C';
240
+ var hasBacksightAzimuth = line[3] !== ' ' && line[3] !== '-';
241
+ var hasBacksightInclination = line[4] !== ' ' && line[4] !== '-';
242
+ if (!/[-CB ]/.test(line[3])) {
243
+ error('Invalid backsight azimuth type', 3, 4);
244
+ }
245
+ if (!/[-CB ]/.test(line[4])) {
246
+ error('Invalid backsight inclination type', 4, 5);
247
+ }
248
+ return {
249
+ distanceUnit: distanceUnit,
250
+ azimuthUnit: azimuthUnit,
251
+ inclinationUnit: inclinationUnit,
252
+ backsightAzimuthCorrected: backsightAzimuthCorrected,
253
+ backsightInclinationCorrected: backsightInclinationCorrected,
254
+ hasBacksightAzimuth: hasBacksightAzimuth,
255
+ hasBacksightInclination: hasBacksightInclination
256
+ };
257
+ };
258
+ validate = function validate(startColumn, endColumn, fieldName, validator) {
259
+ var field = line.substring(startColumn, endColumn);
260
+ if (!validator(field)) {
261
+ error((field.trim() ? 'Invalid ' : 'Missing ') + fieldName, startColumn, endColumn);
262
+ }
263
+ return field;
264
+ };
265
+ addShot = function addShot(shot) {
266
+ if (!trip) return;
267
+ if (alternateUnits) {
268
+ var recorded = shot;
269
+ shot = _objectSpread(_objectSpread({}, shot), {}, {
270
+ recorded: recorded
271
+ });
272
+ if (nextShotUnits) {
273
+ recorded.units = nextShotUnits;
274
+ nextShotUnits = undefined;
275
+ }
276
+ var _trip$header = trip.header,
277
+ backsightAzimuthCorrected = _trip$header.backsightAzimuthCorrected,
278
+ backsightInclinationCorrected = _trip$header.backsightInclinationCorrected,
279
+ distanceUnit = _trip$header.distanceUnit,
280
+ azimuthUnit = _trip$header.azimuthUnit,
281
+ inclinationUnit = _trip$header.inclinationUnit;
282
+ if (alternateUnits.backsightAzimuthCorrected !== backsightAzimuthCorrected) {
283
+ shot.backsightAzimuth = shot.backsightAzimuth ? _unitized.Angle.opposite(shot.backsightAzimuth) : undefined;
284
+ }
285
+ if (alternateUnits.backsightInclinationCorrected !== backsightInclinationCorrected) {
286
+ var _shot$backsightInclin;
287
+ shot.backsightInclination = (_shot$backsightInclin = shot.backsightInclination) === null || _shot$backsightInclin === void 0 ? void 0 : _shot$backsightInclin.negate();
288
+ }
289
+ if (distanceUnit !== alternateUnits.distanceUnit) {
290
+ shot.distance = shot.distance["in"](distanceUnit);
291
+ if (shot.fromLruds) {
292
+ var _shot$fromLruds$left, _shot$fromLruds$right, _shot$fromLruds$up, _shot$fromLruds$down;
293
+ shot.fromLruds.left = (_shot$fromLruds$left = shot.fromLruds.left) === null || _shot$fromLruds$left === void 0 ? void 0 : _shot$fromLruds$left["in"](distanceUnit);
294
+ shot.fromLruds.right = (_shot$fromLruds$right = shot.fromLruds.right) === null || _shot$fromLruds$right === void 0 ? void 0 : _shot$fromLruds$right["in"](distanceUnit);
295
+ shot.fromLruds.up = (_shot$fromLruds$up = shot.fromLruds.up) === null || _shot$fromLruds$up === void 0 ? void 0 : _shot$fromLruds$up["in"](distanceUnit);
296
+ shot.fromLruds.down = (_shot$fromLruds$down = shot.fromLruds.down) === null || _shot$fromLruds$down === void 0 ? void 0 : _shot$fromLruds$down["in"](distanceUnit);
297
+ }
298
+ if (shot.toLruds) {
299
+ var _shot$toLruds$left, _shot$toLruds$right, _shot$toLruds$up, _shot$toLruds$down;
300
+ shot.toLruds.left = (_shot$toLruds$left = shot.toLruds.left) === null || _shot$toLruds$left === void 0 ? void 0 : _shot$toLruds$left["in"](distanceUnit);
301
+ shot.toLruds.right = (_shot$toLruds$right = shot.toLruds.right) === null || _shot$toLruds$right === void 0 ? void 0 : _shot$toLruds$right["in"](distanceUnit);
302
+ shot.toLruds.up = (_shot$toLruds$up = shot.toLruds.up) === null || _shot$toLruds$up === void 0 ? void 0 : _shot$toLruds$up["in"](distanceUnit);
303
+ shot.toLruds.down = (_shot$toLruds$down = shot.toLruds.down) === null || _shot$toLruds$down === void 0 ? void 0 : _shot$toLruds$down["in"](distanceUnit);
304
+ }
305
+ }
306
+ if (azimuthUnit !== alternateUnits.azimuthUnit) {
307
+ var _shot$frontsightAzimu, _shot$backsightAzimut;
308
+ shot.frontsightAzimuth = (_shot$frontsightAzimu = shot.frontsightAzimuth) === null || _shot$frontsightAzimu === void 0 ? void 0 : _shot$frontsightAzimu["in"](azimuthUnit);
309
+ shot.backsightAzimuth = (_shot$backsightAzimut = shot.backsightAzimuth) === null || _shot$backsightAzimut === void 0 ? void 0 : _shot$backsightAzimut["in"](azimuthUnit);
310
+ }
311
+ if (inclinationUnit !== alternateUnits.inclinationUnit) {
312
+ var _shot$frontsightIncli, _shot$backsightInclin2;
313
+ shot.frontsightInclination = (_shot$frontsightIncli = shot.frontsightInclination) === null || _shot$frontsightIncli === void 0 ? void 0 : _shot$frontsightIncli["in"](inclinationUnit);
314
+ shot.backsightInclination = (_shot$backsightInclin2 = shot.backsightInclination) === null || _shot$backsightInclin2 === void 0 ? void 0 : _shot$backsightInclin2["in"](inclinationUnit);
315
+ }
316
+ }
317
+ trip.shots.push(shot);
318
+ };
206
319
  _iteratorAbruptCompletion = false;
207
320
  _didIteratorError = false;
208
- _context2.prev = 17;
321
+ _context2.prev = 23;
209
322
  _loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
210
- var line, errored, thisLineNumber, error, validate, match, _match, k, team, month, day, year, _match2, part, distanceUnit, azimuthUnit, inclinationUnit, backsightAzimuthCorrected, backsightInclinationCorrected, hasBacksightAzimuth, hasBacksightInclination, _trip, shots, _trip$header, _azimuthUnit, _inclinationUnit, _distanceUnit, inches, fromStr, from, lStr, rStr, uStr, dStr, up, down, left, right, toStr, _shot, fromLruds, fromLrudMatch, _fromLrudMatch$1$trim, _fromLrudMatch$1$trim2, _left, _right, _up, _down, comment, azmFsStr, azmBsStr, incFsStr, incBsStr, kind, distance, horizontalDistance, verticalDistance, frontsightInclination, backsightInclination, excludeDistance, isSplay, feetStr, inchesStr, invalid, _feetStr, h, v, d, _v, frontsightAzimuth, backsightAzimuth, shot;
323
+ var match, _match, k, team, month, day, year, _match2, part, _ref, distanceUnit, _ref2, azimuthUnit, inclinationUnit, inches, fromStr, from, lStr, rStr, uStr, dStr, up, down, left, right, toStr, _shot, fromLruds, fromLrudMatch, _fromLrudMatch$1$trim, _fromLrudMatch$1$trim2, _left, _right, _up, _down, comment, azmFsStr, azmBsStr, incFsStr, incBsStr, kind, distance, horizontalDistance, verticalDistance, frontsightInclination, backsightInclination, excludeDistance, isSplay, feetStr, inchesStr, invalid, _feetStr, h, v, d, _v, frontsightAzimuth, backsightAzimuth, shot;
211
324
  return _regenerator["default"].wrap(function _loop$(_context) {
212
325
  while (1) switch (_context.prev = _context.next) {
213
326
  case 0:
214
327
  line = _step.value;
215
328
  errored = false;
216
- thisLineNumber = lineNumber;
217
- error = function error(message, startColumn, endColumn) {
218
- errored = true;
219
- errors.push(new _parseSegment.SegmentParseError(message, new _parseSegment.Segment({
220
- value: line,
221
- source: file,
222
- startLine: thisLineNumber,
223
- startCol: 0
224
- }).substring(startColumn, endColumn)));
225
- };
226
- validate = function validate(startColumn, endColumn, fieldName, validator) {
227
- var field = line.substring(startColumn, endColumn);
228
- if (!validator(field)) {
229
- error((field.trim() ? 'Invalid ' : 'Missing ') + fieldName, startColumn, endColumn);
230
- }
231
- return field;
232
- };
233
329
  lineNumber++;
234
330
  if (lineNumber === 1) {
235
331
  match = /^\s*([^,]+)(,(.*))?/.exec(line);
@@ -240,11 +336,23 @@ function _parseFrcsSurveyFile() {
240
336
  }
241
337
  }
242
338
  }
339
+ if (!unitsChanged) {
340
+ _context.next = 10;
341
+ break;
342
+ }
343
+ unitsChanged = false;
344
+ alternateUnits = parseUnits();
345
+ nextShotUnits = alternateUnits;
346
+ _context.next = 105;
347
+ break;
348
+ case 10:
243
349
  if (!(line.charAt(0) === ' ' && line.charAt(1) === '*')) {
244
- _context.next = 12;
350
+ _context.next = 17;
245
351
  break;
246
352
  }
247
353
  inTripComment = !inTripComment;
354
+ alternateUnits = nextShotUnits = undefined;
355
+ unitsChanged = false;
248
356
  if (inTripComment) {
249
357
  section = undefined;
250
358
  tripComment = [];
@@ -252,11 +360,11 @@ function _parseFrcsSurveyFile() {
252
360
  } else {
253
361
  tripCommentEndLine = lineNumber;
254
362
  }
255
- _context.next = 109;
363
+ _context.next = 105;
256
364
  break;
257
- case 12:
365
+ case 17:
258
366
  if (!inTripComment) {
259
- _context.next = 18;
367
+ _context.next = 23;
260
368
  break;
261
369
  }
262
370
  if (lineNumber === tripCommentStartLine + 1) {
@@ -279,89 +387,62 @@ function _parseFrcsSurveyFile() {
279
387
  if (_match2) {
280
388
  section = _match2[1].trim();
281
389
  }
282
- _context.next = 109;
390
+ _context.next = 105;
283
391
  break;
284
- case 18:
392
+ case 23:
285
393
  if (!(line.charAt(0) === '*')) {
286
- _context.next = 23;
394
+ _context.next = 31;
395
+ break;
396
+ }
397
+ if (!/^\*\s*%NC(\b|$)/.test(line)) {
398
+ _context.next = 27;
287
399
  break;
288
400
  }
401
+ unitsChanged = true;
402
+ return _context.abrupt("return", 0);
403
+ case 27:
289
404
  inBlockComment = !inBlockComment;
290
405
  if (inBlockComment) commentLines = [];else {
291
406
  part = line.substring(1);
292
407
  if (part) addCommentLine(part);
293
408
  }
294
- _context.next = 109;
409
+ _context.next = 105;
295
410
  break;
296
- case 23:
411
+ case 31:
297
412
  if (!inBlockComment) {
298
- _context.next = 27;
413
+ _context.next = 35;
299
414
  break;
300
415
  }
301
416
  addCommentLine(line);
302
- _context.next = 109;
417
+ _context.next = 105;
303
418
  break;
304
- case 27:
419
+ case 35:
305
420
  if (!(lineNumber === tripCommentEndLine + 1)) {
306
- _context.next = 44;
421
+ _context.next = 40;
307
422
  break;
308
423
  }
309
- // FT CC DD
310
- // 01234567
311
- distanceUnit = parseLengthUnit(line.slice(0, 2));
312
- if (!distanceUnit) {
313
- distanceUnit = _unitized.Length.feet;
314
- error('Invalid distance unit', 0, 2);
315
- }
316
- azimuthUnit = parseAngleUnit(line[6]);
317
- if (!azimuthUnit) {
318
- azimuthUnit = _unitized.Angle.degrees;
319
- error('Invalid azimuth unit', 6, 7);
320
- }
321
- inclinationUnit = parseAngleUnit(line[7]);
322
- if (!inclinationUnit) {
323
- inclinationUnit = _unitized.Angle.degrees;
324
- error('Invalid inclination unit', 7, 8);
325
- }
326
- backsightAzimuthCorrected = line[3] === 'C';
327
- backsightInclinationCorrected = line[4] === 'C';
328
- hasBacksightAzimuth = line[3] !== ' ' && line[3] !== '-';
329
- hasBacksightInclination = line[4] !== ' ' && line[4] !== '-';
330
- if (!/[-CB ]/.test(line[3])) {
331
- error('Invalid backsight azimuth type', 3, 4);
332
- }
333
- if (!/[-CB ]/.test(line[4])) {
334
- error('Invalid backsight inclination type', 4, 5);
335
- }
336
424
  trip = {
337
- header: {
425
+ header: _objectSpread({
338
426
  name: tripName || '',
339
427
  comment: tripComment && tripComment.join('\n') || null,
340
428
  section: section,
341
429
  date: tripDate,
342
- team: tripTeam,
343
- distanceUnit: distanceUnit,
344
- azimuthUnit: azimuthUnit,
345
- inclinationUnit: inclinationUnit,
346
- backsightAzimuthCorrected: backsightAzimuthCorrected,
347
- backsightInclinationCorrected: backsightInclinationCorrected,
348
- hasBacksightAzimuth: hasBacksightAzimuth,
349
- hasBacksightInclination: hasBacksightInclination
350
- },
430
+ team: tripTeam
431
+ }, parseUnits()),
351
432
  shots: []
352
433
  };
353
434
  trips.push(trip);
354
- _context.next = 109;
435
+ _context.next = 105;
355
436
  break;
356
- case 44:
437
+ case 40:
357
438
  if (!trip) {
358
- _context.next = 109;
439
+ _context.next = 105;
359
440
  break;
360
441
  }
361
- _trip = trip, shots = _trip.shots, _trip$header = _trip.header, _azimuthUnit = _trip$header.azimuthUnit, _inclinationUnit = _trip$header.inclinationUnit;
362
- _distanceUnit = trip.header.distanceUnit;
363
- inches = _distanceUnit === _unitized.Length.inches;
364
- if (inches) _distanceUnit = _unitized.Length.feet;
442
+ _ref = alternateUnits || trip.header, distanceUnit = _ref.distanceUnit;
443
+ _ref2 = alternateUnits || trip.header, azimuthUnit = _ref2.azimuthUnit, inclinationUnit = _ref2.inclinationUnit;
444
+ inches = distanceUnit === _unitized.Length.inches;
445
+ if (inches) distanceUnit = _unitized.Length.feet;
365
446
 
366
447
  // rigorously check the values in all the columns to make sure this
367
448
  // is really a survey shot line, just in case any stray comments are
@@ -369,11 +450,11 @@ function _parseFrcsSurveyFile() {
369
450
 
370
451
  // from station name
371
452
  if (/\S/.test(line.substring(5, 10))) {
372
- _context.next = 51;
453
+ _context.next = 47;
373
454
  break;
374
455
  }
375
456
  return _context.abrupt("return", 0);
376
- case 51:
457
+ case 47:
377
458
  fromStr = validate(5, 10, 'from station', isValidStation);
378
459
  from = fromStr.trim(); // Sadly I have found negative LRUD values in Chip's format and apparently
379
460
  // his program doesn't fail on them, so I have to accept them here
@@ -383,25 +464,25 @@ function _parseFrcsSurveyFile() {
383
464
  uStr = validate(46, 49, 'up', isValidOptFloat);
384
465
  dStr = validate(49, 52, 'down', isValidOptFloat);
385
466
  if (!errored) {
386
- _context.next = 59;
467
+ _context.next = 55;
387
468
  break;
388
469
  }
389
470
  return _context.abrupt("return", 0);
390
- case 59:
391
- up = parseLrud(uStr, _distanceUnit);
392
- down = parseLrud(dStr, _distanceUnit);
393
- left = parseLrud(lStr, _distanceUnit);
394
- right = parseLrud(rStr, _distanceUnit); // to station name
471
+ case 55:
472
+ up = parseLrud(uStr, distanceUnit);
473
+ down = parseLrud(dStr, distanceUnit);
474
+ left = parseLrud(lStr, distanceUnit);
475
+ right = parseLrud(rStr, distanceUnit); // to station name
395
476
  toStr = line.substring(0, 5);
396
477
  if (toStr.trim()) {
397
- _context.next = 68;
478
+ _context.next = 64;
398
479
  break;
399
480
  }
400
481
  _shot = {
401
482
  from: from,
402
483
  to: null,
403
484
  kind: _FrcsShot.FrcsShotKind.Normal,
404
- distance: new _unitized.UnitizedNumber(0, _distanceUnit),
485
+ distance: new _unitized.UnitizedNumber(0, distanceUnit),
405
486
  frontsightAzimuth: null,
406
487
  backsightAzimuth: null,
407
488
  frontsightInclination: null,
@@ -415,9 +496,9 @@ function _parseFrcsSurveyFile() {
415
496
  excludeDistance: true,
416
497
  comment: getComment()
417
498
  };
418
- shots.push(_shot);
499
+ addShot(_shot);
419
500
  return _context.abrupt("return", 0);
420
- case 68:
501
+ case 64:
421
502
  if (!isValidStation(toStr)) {
422
503
  error('Invalid station name', 0, 5);
423
504
  }
@@ -428,7 +509,7 @@ function _parseFrcsSurveyFile() {
428
509
  fromLrudMatch = new RegExp("^\\s+".concat(fromStr.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "((\\s+(\\d+(\\.\\d*)?|\\.\\d+)){4})")).exec(line.substring(52));
429
510
  if (fromLrudMatch) {
430
511
  _fromLrudMatch$1$trim = fromLrudMatch[1].trim().split(/\s+/g).map(function (s) {
431
- return parseLrud(s, _distanceUnit);
512
+ return parseLrud(s, distanceUnit);
432
513
  }), _fromLrudMatch$1$trim2 = (0, _slicedToArray2["default"])(_fromLrudMatch$1$trim, 4), _left = _fromLrudMatch$1$trim2[0], _right = _fromLrudMatch$1$trim2[1], _up = _fromLrudMatch$1$trim2[2], _down = _fromLrudMatch$1$trim2[3];
433
514
  fromLruds = {
434
515
  left: _left,
@@ -444,25 +525,25 @@ function _parseFrcsSurveyFile() {
444
525
  incFsStr = line.substring(30, 35);
445
526
  incBsStr = line.substring(35, 40);
446
527
  if (!errored) {
447
- _context.next = 78;
528
+ _context.next = 74;
448
529
  break;
449
530
  }
450
531
  return _context.abrupt("return", 0);
451
- case 78:
532
+ case 74:
452
533
  if (!inches) {
453
- _context.next = 91;
534
+ _context.next = 87;
454
535
  break;
455
536
  }
456
537
  feetStr = line.substring(10, 14);
457
538
  inchesStr = line.substring(14, 17); // feet and inches are not both optional
458
539
  if (!(!isValidUInt(feetStr) && !isValidUInt(inchesStr))) {
459
- _context.next = 85;
540
+ _context.next = 81;
460
541
  break;
461
542
  }
462
543
  invalid = feetStr.trim() || inchesStr.trim();
463
544
  error(invalid ? 'Invalid distance' : 'Missing distance', 10, 17);
464
545
  return _context.abrupt("return", 0);
465
- case 85:
546
+ case 81:
466
547
  // sometimes inches are omitted, hence the || 0...I'm assuming it's possible
467
548
  // for feet to be omitted as well
468
549
  distance = _unitized.Unitize.inches(parseFloat(inchesStr) || 0).add(_unitized.Unitize.feet(parseFloat(feetStr) || 0));
@@ -473,16 +554,16 @@ function _parseFrcsSurveyFile() {
473
554
  // first column that can contain a * for decimal feet shots
474
555
  excludeDistance = line[18] === '*' || line[18] === 's';
475
556
  isSplay = line[18] === 's';
476
- _context.next = 96;
557
+ _context.next = 92;
477
558
  break;
478
- case 91:
559
+ case 87:
479
560
  // decimal feet are not optional
480
561
  _feetStr = validate(10, 16, 'distance', isValidUFloat);
481
- distance = new _unitized.UnitizedNumber(parseFloat(_feetStr), _distanceUnit);
562
+ distance = new _unitized.UnitizedNumber(parseFloat(_feetStr), distanceUnit);
482
563
  kind = parseKind(line[16]);
483
564
  excludeDistance = line[17] === '*' || line[17] === 's';
484
565
  isSplay = line[17] === 's';
485
- case 96:
566
+ case 92:
486
567
  if (kind !== _FrcsShot.FrcsShotKind.Normal) {
487
568
  validate(30, 35, 'vertical-distance', isValidFloat);
488
569
  }
@@ -494,17 +575,17 @@ function _parseFrcsSurveyFile() {
494
575
  if (kind === _FrcsShot.FrcsShotKind.Horizontal) {
495
576
  // distance is horizontal offset and incFsStr is vertical offset
496
577
  horizontalDistance = distance;
497
- h = horizontalDistance.get(_distanceUnit);
578
+ h = horizontalDistance.get(distanceUnit);
498
579
  v = parseFloat(incFsStr);
499
- verticalDistance = new _unitized.UnitizedNumber(v, _distanceUnit);
500
- distance = new _unitized.UnitizedNumber(Math.sqrt(h * h + v * v), _distanceUnit);
580
+ verticalDistance = new _unitized.UnitizedNumber(v, distanceUnit);
581
+ distance = new _unitized.UnitizedNumber(Math.sqrt(h * h + v * v), distanceUnit);
501
582
  frontsightInclination = _unitized.Angle.atan2(verticalDistance, horizontalDistance);
502
583
  backsightInclination = null;
503
584
  } else if (kind === _FrcsShot.FrcsShotKind.Diagonal) {
504
585
  // distance is as usual, but incFsStr is vertical offset
505
- d = distance.get(_distanceUnit);
586
+ d = distance.get(distanceUnit);
506
587
  _v = parseFloat(incFsStr);
507
- verticalDistance = new _unitized.UnitizedNumber(_v, _distanceUnit);
588
+ verticalDistance = new _unitized.UnitizedNumber(_v, distanceUnit);
508
589
  frontsightInclination = _unitized.Angle.asin(_v / d);
509
590
  backsightInclination = null;
510
591
  } else {
@@ -512,17 +593,17 @@ function _parseFrcsSurveyFile() {
512
593
  validate(30, 35, 'inclination', isValidOptInclination);
513
594
  // frontsight inclination
514
595
  validate(35, 40, 'inclination', isValidOptInclination);
515
- frontsightInclination = parseNumber(incFsStr, _inclinationUnit);
516
- backsightInclination = parseNumber(incBsStr, _inclinationUnit);
596
+ frontsightInclination = parseNumber(incFsStr, inclinationUnit);
597
+ backsightInclination = parseNumber(incBsStr, inclinationUnit);
517
598
  }
518
599
  if (!errored) {
519
- _context.next = 100;
600
+ _context.next = 96;
520
601
  break;
521
602
  }
522
603
  return _context.abrupt("return", 0);
523
- case 100:
524
- frontsightAzimuth = parseAzimuth(azmFsStr, _azimuthUnit);
525
- backsightAzimuth = parseAzimuth(azmBsStr, _azimuthUnit);
604
+ case 96:
605
+ frontsightAzimuth = parseAzimuth(azmFsStr, azimuthUnit);
606
+ backsightAzimuth = parseAzimuth(azmBsStr, azimuthUnit);
526
607
  if (!frontsightInclination && !backsightInclination) {
527
608
  frontsightInclination = _unitized.Unitize.degrees(0);
528
609
  }
@@ -548,74 +629,74 @@ function _parseFrcsSurveyFile() {
548
629
  if (fromLruds) shot.fromLruds = fromLruds;
549
630
  if (horizontalDistance) shot.horizontalDistance = horizontalDistance;
550
631
  if (verticalDistance) shot.verticalDistance = verticalDistance;
551
- shots.push(shot);
552
- case 109:
632
+ addShot(shot);
633
+ case 105:
553
634
  case "end":
554
635
  return _context.stop();
555
636
  }
556
637
  }, _loop);
557
638
  });
558
639
  _iterator = _asyncIterator(lines);
559
- case 20:
560
- _context2.next = 22;
640
+ case 26:
641
+ _context2.next = 28;
561
642
  return _iterator.next();
562
- case 22:
643
+ case 28:
563
644
  if (!(_iteratorAbruptCompletion = !(_step = _context2.sent).done)) {
564
- _context2.next = 30;
645
+ _context2.next = 36;
565
646
  break;
566
647
  }
567
- return _context2.delegateYield(_loop(), "t0", 24);
568
- case 24:
648
+ return _context2.delegateYield(_loop(), "t0", 30);
649
+ case 30:
569
650
  _ret = _context2.t0;
570
651
  if (!(_ret === 0)) {
571
- _context2.next = 27;
652
+ _context2.next = 33;
572
653
  break;
573
654
  }
574
- return _context2.abrupt("continue", 27);
575
- case 27:
655
+ return _context2.abrupt("continue", 33);
656
+ case 33:
576
657
  _iteratorAbruptCompletion = false;
577
- _context2.next = 20;
658
+ _context2.next = 26;
578
659
  break;
579
- case 30:
580
- _context2.next = 36;
660
+ case 36:
661
+ _context2.next = 42;
581
662
  break;
582
- case 32:
583
- _context2.prev = 32;
584
- _context2.t1 = _context2["catch"](17);
663
+ case 38:
664
+ _context2.prev = 38;
665
+ _context2.t1 = _context2["catch"](23);
585
666
  _didIteratorError = true;
586
667
  _iteratorError = _context2.t1;
587
- case 36:
588
- _context2.prev = 36;
589
- _context2.prev = 37;
668
+ case 42:
669
+ _context2.prev = 42;
670
+ _context2.prev = 43;
590
671
  if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
591
- _context2.next = 41;
672
+ _context2.next = 47;
592
673
  break;
593
674
  }
594
- _context2.next = 41;
675
+ _context2.next = 47;
595
676
  return _iterator["return"]();
596
- case 41:
597
- _context2.prev = 41;
677
+ case 47:
678
+ _context2.prev = 47;
598
679
  if (!_didIteratorError) {
599
- _context2.next = 44;
680
+ _context2.next = 50;
600
681
  break;
601
682
  }
602
683
  throw _iteratorError;
603
- case 44:
604
- return _context2.finish(41);
605
- case 45:
606
- return _context2.finish(36);
607
- case 46:
684
+ case 50:
685
+ return _context2.finish(47);
686
+ case 51:
687
+ return _context2.finish(42);
688
+ case 52:
608
689
  return _context2.abrupt("return", {
609
690
  cave: cave,
610
691
  location: location,
611
692
  trips: trips,
612
693
  errors: errors
613
694
  });
614
- case 47:
695
+ case 53:
615
696
  case "end":
616
697
  return _context2.stop();
617
698
  }
618
- }, _callee, null, [[17, 32, 36, 46], [37,, 41, 45]]);
699
+ }, _callee, null, [[23, 38, 42, 52], [43,, 47, 51]]);
619
700
  }));
620
701
  return _parseFrcsSurveyFile.apply(this, arguments);
621
702
  }
package/web/index.js CHANGED
@@ -43,6 +43,7 @@ var LinesTransform = /*#__PURE__*/function (_TransformStream) {
43
43
  } finally {
44
44
  _iterator.f();
45
45
  }
46
+ if (end < chunk.length) _this.parts.push(chunk.substring(end));
46
47
  },
47
48
  flush: function flush(controller) {
48
49
  if (_this.parts.length) {