@dra2020/baseclient 1.0.55 → 1.0.59

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.
@@ -0,0 +1 @@
1
+ export * from './csv';
@@ -0,0 +1 @@
1
+ export {};
package/dist/geo/all.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './geo';
2
2
  export * from './vfeature';
3
+ export * from './flexname';
@@ -0,0 +1 @@
1
+ export declare function flexName(f: any): string;
@@ -93,12 +93,14 @@ export interface SessionProps {
93
93
  [prop: string]: string;
94
94
  };
95
95
  groups: any;
96
+ xid?: string;
96
97
  }
97
98
  export declare type LabelUpdate = {
98
99
  [name: string]: boolean | null;
99
100
  };
100
101
  export interface SessionUpdateProps {
101
102
  id?: string;
103
+ xid?: string;
102
104
  ids?: string[];
103
105
  deleted?: boolean;
104
106
  published?: boolean;
package/lib/all/all.ts CHANGED
@@ -21,3 +21,5 @@ import * as G from '../geo/all';
21
21
  export { G };
22
22
  import * as Emit from '../emit/all';
23
23
  export { Emit };
24
+ import * as CSV from '../csv/all';
25
+ export { CSV };
package/lib/csv/all.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './csv';
package/lib/csv/csv.ts ADDED
@@ -0,0 +1,108 @@
1
+ import * as Util from '../util/all';
2
+
3
+ // Parse CSV.
4
+ // Fields are separated by commas or pipe symbol (census uses pipe separators.
5
+ // Quoted fields may contain commas or pipes.
6
+ // Either single quotes or double quotes may be used to surround field value.
7
+ // Spaces at the beginning and end of fields are ignored.
8
+ // Quotes must be the first non-space character in the field (otherwise they are part of the field value).
9
+ //
10
+
11
+ const Space = 32;
12
+ const Tab = 9;
13
+ const Newline = 10;
14
+ const CR = 13;
15
+ const Comma = 44;
16
+ const SingleQuote = 39;
17
+ const DoubleQuote = 34;
18
+ const BackSlash = 92;
19
+ const Pipe = 124;
20
+
21
+ function isWhite(c: number): boolean
22
+ {
23
+ return c === Space || c === Newline || c === Tab || c == CR;
24
+ }
25
+
26
+ class ParseOne
27
+ {
28
+ coder: Util.Coder;
29
+ fields: string[]; // output
30
+ buf: Uint8Array;
31
+ n: number;
32
+ tok: Uint8Array;
33
+ toklen: number;
34
+ infield: boolean;
35
+ quote: number;
36
+ nwhite: number;
37
+
38
+ constructor(coder: Util.Coder, line?: string)
39
+ {
40
+ this.coder = coder;
41
+ if (line)
42
+ this.set(line);
43
+ }
44
+
45
+ set(line: string): void
46
+ {
47
+ this.fields = [];
48
+ this.buf = Util.s2u8(this.coder, line);
49
+ this.tok = new Uint8Array(new ArrayBuffer(this.buf.length));
50
+ this.n = 0;
51
+ this.toklen = 0;
52
+ this.infield = false;
53
+ this.nwhite = 0;
54
+ this.quote = 0;
55
+ this.parse();
56
+ }
57
+
58
+ get length(): number { return this.fields.length }
59
+
60
+ pushtok(force: boolean): void
61
+ {
62
+ // Trim trailing whitespace
63
+ if (!force)
64
+ this.toklen -= this.nwhite;
65
+
66
+ if (this.toklen || force)
67
+ {
68
+ this.fields.push(Util.u82s(this.coder, this.tok, 0, this.toklen));
69
+ this.toklen = 0;
70
+ }
71
+ this.infield = false;
72
+ this.nwhite = 0;
73
+ this.quote = 0;
74
+ }
75
+
76
+ parse(): void
77
+ {
78
+ while (this.n < this.buf.length)
79
+ {
80
+ let c: number = this.buf[this.n++];
81
+ if (this.quote && c === this.quote)
82
+ this.pushtok(true);
83
+ else if (c === Comma || c === Pipe)
84
+ this.pushtok(true);
85
+ else if (this.infield)
86
+ {
87
+ this.tok[this.toklen++] = c;
88
+ if (isWhite(c))
89
+ this.nwhite++;
90
+ else
91
+ this.nwhite = 0;
92
+ }
93
+ else if (isWhite(c))
94
+ continue;
95
+ else if (c === SingleQuote || c === DoubleQuote)
96
+ {
97
+ this.quote = c;
98
+ this.infield = true;
99
+ }
100
+ else
101
+ {
102
+ this.infield = true;
103
+ this.tok[this.toklen++] = c;
104
+ }
105
+ }
106
+ this.pushtok(false);
107
+ }
108
+ }
package/lib/geo/all.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './geo';
2
2
  export * from './vfeature';
3
+ export * from './flexname';
@@ -0,0 +1,27 @@
1
+ export function flexName(f: any): string
2
+ {
3
+ if (!f || !f.properties) return null;
4
+
5
+ let oneOf = [ 'name', 'entry_name', 'Name', 'NAME',
6
+ 'NAMELSAD', 'namelsad',
7
+ 'NAME10', 'name10',
8
+ 'NAMELSAD10', 'namelsad10',
9
+ 'NAME20', 'name20',
10
+ 'NAMELSAD20', 'namelsad20',
11
+ 'NAME30', 'name30',
12
+ 'NAMELSAD30', 'namelsad30',
13
+ ];
14
+
15
+ for (let i = 0; i < oneOf.length; i++)
16
+ if (f.properties[oneOf[i]] !== undefined)
17
+ {
18
+ let name: string = f.properties[oneOf[i]];
19
+ if (name.startsWith('Block Group') && f.properties['GEOID10'] !== undefined)
20
+ return String(f.properties['GEOID10']).substr(2);
21
+ name = name.replace('Voting Districts', '');
22
+ name = name.replace('Precinct', '');
23
+ return name.replace('Voting District', '').trim();
24
+ }
25
+
26
+ return `${f.properties.id}`;
27
+ }
@@ -119,6 +119,7 @@ export interface SessionProps
119
119
  expungeDate?: string;
120
120
  xprops?: { [prop: string]: string };
121
121
  groups: any; // DT.GroupsMapIndex
122
+ xid?: string; // external ID
122
123
  }
123
124
 
124
125
  // True to add, False to remove
@@ -127,6 +128,7 @@ export type LabelUpdate = { [name: string]: boolean|null }
127
128
  export interface SessionUpdateProps
128
129
  {
129
130
  id?: string;
131
+ xid?: string;
130
132
  ids?: string[];
131
133
  deleted?: boolean;
132
134
  published?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.55",
3
+ "version": "1.0.59",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",
@@ -40,9 +40,6 @@
40
40
  "webpack-cli": "^4.4.0"
41
41
  },
42
42
  "dependencies": {
43
- "@dra2020/baseclient": "^1.0.36",
44
- "@dra2020/baseserver": "^1.0.21",
45
- "@dra2020/dra-types": "^1.8.26",
46
43
  "@dra2020/topojson-client": "^3.2.7",
47
44
  "@dra2020/topojson-server": "^3.0.103",
48
45
  "@dra2020/topojson-simplify": "^3.0.102",