@ca-plant-list/ca-plant-list 0.1.3 → 0.1.4

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/lib/dataloader.js CHANGED
@@ -14,16 +14,22 @@ class DataLoader {
14
14
  return OPTION_DEFS;
15
15
  }
16
16
 
17
- static load( options ) {
17
+ static init( taxaDir ) {
18
18
 
19
19
  const defaultDataDir = Config.getPackageDir() + "/data";
20
- const taxaDir = options.datadir;
21
-
22
- console.log( "loading data" );
23
20
 
24
21
  Exceptions.init( taxaDir );
25
22
  Families.init( defaultDataDir );
26
23
  Genera.init( defaultDataDir );
24
+ }
25
+
26
+ static load( options ) {
27
+
28
+ const taxaDir = options.datadir;
29
+
30
+ console.log( "loading data" );
31
+
32
+ this.init( taxaDir );
27
33
  Taxa.init( taxaDir );
28
34
 
29
35
  }
package/lib/genera.js CHANGED
@@ -9,6 +9,11 @@ class Genera {
9
9
 
10
10
  const genusName = taxon.getGenusName();
11
11
  const genusData = this.#genera[ genusName ];
12
+ if ( !genusData ) {
13
+ console.log( taxon.getName() + " genus not found" );
14
+ return;
15
+ }
16
+
12
17
  if ( genusData.taxa === undefined ) {
13
18
  genusData.taxa = [];
14
19
  }
@@ -16,7 +21,7 @@ class Genera {
16
21
 
17
22
  const family = this.getFamily( genusName );
18
23
  if ( !family ) {
19
- console.log( taxon.getName() + " genus/family not found" );
24
+ console.log( taxon.getName() + " family not found" );
20
25
  return;
21
26
  }
22
27
  family.addTaxon( taxon );
package/lib/index.js CHANGED
@@ -1,5 +1,10 @@
1
1
  import { BasePageRenderer } from "./basepagerenderer.js";
2
2
  import { Config } from "./config.js";
3
+ import { CSV } from "./csv.js";
4
+ import { DataLoader } from "./dataloader.js";
5
+ import { ErrorLog } from "./errorlog.js";
6
+ import { Exceptions } from "./exceptions.js";
3
7
  import { HTML, HTML_OPTIONS } from "./html.js";
8
+ import { Taxon } from "./taxon.js";
4
9
 
5
- export { BasePageRenderer, Config, HTML, HTML_OPTIONS };
10
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, HTML, HTML_OPTIONS, Taxon };
package/lib/pagetaxon.js CHANGED
@@ -31,16 +31,9 @@ class PageTaxon extends HTMLPage {
31
31
  )
32
32
  );
33
33
  }
34
- const iNatID = this.#taxon.getINatID();
35
- if ( iNatID ) {
36
- links.push(
37
- HTML.getLink(
38
- "https://www.inaturalist.org/taxa/" + iNatID,
39
- "iNaturalist",
40
- {},
41
- HTML_OPTIONS.OPEN_NEW
42
- )
43
- );
34
+ const iNatLink = this.#taxon.getINatTaxonLink();
35
+ if ( iNatLink ) {
36
+ links.push( iNatLink );
44
37
  }
45
38
  return links;
46
39
  }
package/lib/taxa.js CHANGED
@@ -62,6 +62,7 @@ class Taxa {
62
62
  jepsonID,
63
63
  row[ "calrecnum" ],
64
64
  row[ "inat id" ],
65
+ row[ "RPI ID" ],
65
66
  row[ "CRPR" ],
66
67
  row[ "CESA" ]
67
68
  );
package/lib/taxon.js CHANGED
@@ -12,13 +12,15 @@ class Taxon {
12
12
  #status;
13
13
  #jepsonID;
14
14
  #calRecNum;
15
+ #cfSyn;
15
16
  #iNatID;
16
17
  #iNatSyn;
18
+ #rpiID;
17
19
  #rankRPI;
18
20
  #cesa;
19
21
  #synonyms = [];
20
22
 
21
- constructor( name, commonNames, status, jepsonID, calRecNum, iNatID, rankRPI, cesa ) {
23
+ constructor( name, commonNames, status, jepsonID, calRecNum, iNatID, rpiID, rankRPI, cesa ) {
22
24
  this.#name = name;
23
25
  this.#genus = name.split( " " )[ 0 ];
24
26
  this.#commonNames = commonNames ? commonNames.split( "," ).map( t => t.trim() ) : [];
@@ -26,6 +28,7 @@ class Taxon {
26
28
  this.#jepsonID = jepsonID;
27
29
  this.#calRecNum = calRecNum;
28
30
  this.#iNatID = iNatID;
31
+ this.#rpiID = rpiID;
29
32
  this.#rankRPI = rankRPI;
30
33
  this.#cesa = cesa;
31
34
  Genera.addTaxon( this );
@@ -39,14 +42,23 @@ class Taxon {
39
42
 
40
43
  addSynonym( syn, type ) {
41
44
  this.#synonyms.push( syn );
42
- if ( type === "INAT" ) {
43
- // Synonyms should be in Jepson format, but store iNatName in iNat format (no var or subsp, space after x).
44
- this.#iNatSyn = syn;
45
+ switch ( type ) {
46
+ case "CF":
47
+ // Synonym is in Calflora format.
48
+ this.#cfSyn = syn;
49
+ break;
50
+ case "INAT":
51
+ // Synonyms should be in Jepson format, but store iNatName in iNat format (no var or subsp, space after x).
52
+ this.#iNatSyn = syn;
53
+ break;
45
54
  }
46
55
  }
47
56
 
48
57
  getCalfloraName() {
49
- return this.#name.replace( " subsp.", " ssp." ).replace( "×", "X" );
58
+ if ( this.#cfSyn ) {
59
+ return this.#cfSyn;
60
+ }
61
+ return this.getName().replace( " subsp.", " ssp." ).replace( "×", "X" );
50
62
  }
51
63
 
52
64
  getCalfloraID() {
@@ -65,9 +77,13 @@ class Taxon {
65
77
  return Genera.getFamily( this.#genus );
66
78
  }
67
79
 
68
- getFileName( ext = "html" ) {
80
+ getFileName( ext ) {
81
+ return Taxon.getFileName( this.getName(), ext );
82
+ }
83
+
84
+ static getFileName( name, ext = "html" ) {
69
85
  // Convert spaces to "-" and remove ".".
70
- return this.getName().replaceAll( " ", "-" ).replaceAll( ".", "" ) + "." + ext;
86
+ return name.replaceAll( " ", "-" ).replaceAll( ".", "" ) + "." + ext;
71
87
  }
72
88
 
73
89
  getGenus() {
@@ -97,6 +113,15 @@ class Taxon {
97
113
  return name.replace( / (subsp|var)\./, "" ).replace( "×", "× " );
98
114
  }
99
115
 
116
+ getINatTaxonLink() {
117
+ const iNatID = this.getINatID();
118
+ if ( !iNatID ) {
119
+ return "";
120
+ }
121
+ const link = HTML.getLink( "https://www.inaturalist.org/taxa/" + iNatID, "iNaturalist", {}, HTML_OPTIONS.OPEN_NEW );
122
+ return this.#iNatSyn ? ( link + " (" + this.#iNatSyn + ")" ) : link;
123
+ }
124
+
100
125
  getJepsonID() {
101
126
  return this.#jepsonID;
102
127
  }
@@ -105,6 +130,10 @@ class Taxon {
105
130
  return this.#name;
106
131
  }
107
132
 
133
+ getRPIID() {
134
+ return this.#rpiID;
135
+ }
136
+
108
137
  getRPIRank() {
109
138
  if ( !this.#rankRPI ) {
110
139
  return this.#rankRPI;
@@ -144,6 +173,18 @@ class Taxon {
144
173
  return this.getRPIRank() !== undefined;
145
174
  }
146
175
 
176
+ setCalfloraID( id ) {
177
+ this.#calRecNum = id;
178
+ }
179
+
180
+ setINatID( id ) {
181
+ this.#iNatID = id;
182
+ }
183
+
184
+ setJepsonID( id ) {
185
+ this.#jepsonID = id;
186
+ }
187
+
147
188
  }
148
189
 
149
190
  export { Taxon };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Tools to create Jekyll files for a website listing plants in an area of California.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,22 +10,7 @@
10
10
  "homepage": "https://github.com/ca-plants/ca-plant-list",
11
11
  "type": "module",
12
12
  "exports": {
13
- ".": "./lib/index.js",
14
- "./CSV": {
15
- "import": "./lib/csv.js"
16
- },
17
- "./DataLoader": {
18
- "import": "./lib/dataloader.js"
19
- },
20
- "./Exceptions": {
21
- "import": "./lib/exceptions.js"
22
- },
23
- "./Files": {
24
- "import": "./lib/files.js"
25
- },
26
- "./Taxa": {
27
- "import": "./lib/taxa.js"
28
- }
13
+ ".": "./lib/index.js"
29
14
  },
30
15
  "bin": {
31
16
  "ca-plant-list": "build-site.js"