@dra2020/baseclient 1.0.84 → 1.0.86

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Terry Crowley
3
+ Copyright (c) 2021-2022 Dave's Redistricting, LLC.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -889,7 +889,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
889
889
  return result;
890
890
  };
891
891
  Object.defineProperty(exports, "__esModule", ({ value: true }));
892
- exports.ParseOne = void 0;
892
+ exports.ParseOne = exports.ParseMany = void 0;
893
893
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
894
894
  // Parse CSV.
895
895
  // Fields are separated by commas or pipe symbol (census uses pipe separators.
@@ -910,6 +910,41 @@ const Pipe = 124;
910
910
  function isWhite(c) {
911
911
  return c === Space || c === Newline || c === Tab || c == CR;
912
912
  }
913
+ // Keep calling next() to retrieve next parsed line. Returns false when done. Empty lines are ignored.
914
+ class ParseMany {
915
+ constructor(coder, buf) {
916
+ this.buf = buf;
917
+ this.n = 0;
918
+ this.one = new ParseOne(coder);
919
+ }
920
+ get length() { return this.one.length; }
921
+ get fields() { return this.one.fields; }
922
+ next() {
923
+ // Move past any leading CRLF
924
+ while (this.n < this.buf.length) {
925
+ let c = this.buf[this.n];
926
+ if (c == CR || c == Newline)
927
+ this.n++;
928
+ else
929
+ break;
930
+ }
931
+ let s = this.n;
932
+ while (this.n < this.buf.length) {
933
+ let c = this.buf[this.n];
934
+ if (c == CR || c == Newline)
935
+ break;
936
+ else
937
+ this.n++;
938
+ }
939
+ if (s != this.n) {
940
+ this.one.setBuf(this.buf.subarray(s, this.n));
941
+ return true;
942
+ }
943
+ else
944
+ return false;
945
+ }
946
+ }
947
+ exports.ParseMany = ParseMany;
913
948
  class ParseOne {
914
949
  constructor(coder, line) {
915
950
  this.coder = coder;
@@ -919,9 +954,13 @@ class ParseOne {
919
954
  this.fields = [];
920
955
  }
921
956
  set(line) {
957
+ this.setBuf(Util.s2u8(this.coder, line));
958
+ }
959
+ setBuf(buf) {
960
+ this.buf = buf;
922
961
  this.fields = [];
923
- this.buf = Util.s2u8(this.coder, line);
924
- this.tok = new Uint8Array(new ArrayBuffer(this.buf.length));
962
+ if (!this.tok || this.tok.length < this.buf.length)
963
+ this.tok = new Uint8Array(new ArrayBuffer(this.buf.length));
925
964
  this.n = 0;
926
965
  this.toklen = 0;
927
966
  this.infield = false;
@@ -2239,6 +2278,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
2239
2278
  __exportStar(__webpack_require__(/*! ./geo */ "./lib/geo/geo.ts"), exports);
2240
2279
  __exportStar(__webpack_require__(/*! ./vfeature */ "./lib/geo/vfeature.ts"), exports);
2241
2280
  __exportStar(__webpack_require__(/*! ./flexname */ "./lib/geo/flexname.ts"), exports);
2281
+ __exportStar(__webpack_require__(/*! ./multiblockmapping */ "./lib/geo/multiblockmapping.ts"), exports);
2242
2282
 
2243
2283
 
2244
2284
  /***/ }),
@@ -2785,6 +2825,72 @@ function geoIntersect(multi, bbox, opt) {
2785
2825
  exports.geoIntersect = geoIntersect;
2786
2826
 
2787
2827
 
2828
+ /***/ }),
2829
+
2830
+ /***/ "./lib/geo/multiblockmapping.ts":
2831
+ /*!**************************************!*\
2832
+ !*** ./lib/geo/multiblockmapping.ts ***!
2833
+ \**************************************/
2834
+ /***/ ((__unused_webpack_module, exports) => {
2835
+
2836
+
2837
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2838
+ exports.MultiBlockMapping = exports.reverseBlockMapping = void 0;
2839
+ function reverseBlockMapping(bm) {
2840
+ let rev = {};
2841
+ if (bm)
2842
+ Object.keys(bm).forEach(blockid => {
2843
+ let geoid = bm[blockid];
2844
+ if (!rev[geoid])
2845
+ rev[geoid] = [];
2846
+ rev[geoid].push(blockid);
2847
+ });
2848
+ Object.values(rev).forEach((a) => a.sort());
2849
+ return rev;
2850
+ }
2851
+ exports.reverseBlockMapping = reverseBlockMapping;
2852
+ class MultiBlockMapping {
2853
+ constructor(tag, bm) {
2854
+ this.entries = [];
2855
+ if (tag && bm)
2856
+ this.entries.push({ tag, bm });
2857
+ }
2858
+ add(tag, bm) {
2859
+ this.entries.forEach(e => { if (e.tag === tag) {
2860
+ e.bm = bm;
2861
+ delete e.rbm;
2862
+ bm = null;
2863
+ } });
2864
+ if (bm)
2865
+ this.entries.push({ tag, bm });
2866
+ }
2867
+ remove(tag) {
2868
+ for (let i = this.entries.length - 1; i >= 0; i--)
2869
+ if (this.entries[i].tag === tag)
2870
+ this.entries.splice(i, 1);
2871
+ }
2872
+ map(blockid) {
2873
+ for (let i = 0; i < this.entries.length; i++) {
2874
+ let e = this.entries[i];
2875
+ if (e.bm[blockid])
2876
+ return e.bm[blockid];
2877
+ }
2878
+ return undefined;
2879
+ }
2880
+ rev(geoid) {
2881
+ for (let i = 0; i < this.entries.length; i++) {
2882
+ let e = this.entries[i];
2883
+ if (!e.rbm)
2884
+ e.rbm = reverseBlockMapping(e.bm);
2885
+ if (e.rbm[geoid])
2886
+ return e.rbm[geoid];
2887
+ }
2888
+ return undefined;
2889
+ }
2890
+ }
2891
+ exports.MultiBlockMapping = MultiBlockMapping;
2892
+
2893
+
2788
2894
  /***/ }),
2789
2895
 
2790
2896
  /***/ "./lib/geo/vfeature.ts":