@ca-plant-list/ca-plant-list 0.1.13 → 0.1.14
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/build-site.js +1 -4
- package/data/genera.json +4 -0
- package/lib/config.js +13 -9
- package/lib/exceptions.js +13 -9
- package/lib/files.js +25 -6
- package/lib/index.d.ts +14 -2
- package/lib/pagetaxon.js +1 -1
- package/lib/taxon.js +4 -0
- package/package.json +1 -1
package/build-site.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
import { Config } from "./lib/config.js";
|
4
3
|
import { DataLoader } from "./lib/dataloader.js";
|
5
4
|
import { ErrorLog } from "./lib/errorlog.js";
|
6
5
|
import { PageRenderer } from "./lib/pagerenderer.js";
|
@@ -8,11 +7,9 @@ import commandLineArgs from "command-line-args";
|
|
8
7
|
|
9
8
|
const options = commandLineArgs( DataLoader.getOptionDefs() );
|
10
9
|
|
11
|
-
const CONFIG_DATA_DIR = "./data";
|
12
10
|
const OUTPUT_DIR = "./output";
|
13
11
|
|
14
|
-
Config.init( CONFIG_DATA_DIR );
|
15
12
|
DataLoader.load( options );
|
16
13
|
PageRenderer.render( OUTPUT_DIR );
|
17
14
|
|
18
|
-
ErrorLog.write( OUTPUT_DIR + "/errors.
|
15
|
+
ErrorLog.write( OUTPUT_DIR + "/errors.tsv" );
|
package/data/genera.json
CHANGED
package/lib/config.js
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
import * as path from "node:path";
|
2
2
|
import * as url from "node:url";
|
3
|
-
import
|
3
|
+
import { Files } from "./files.js";
|
4
4
|
|
5
5
|
class Config {
|
6
6
|
|
7
7
|
static #config = {};
|
8
8
|
static #packageDir = path.dirname( path.dirname( url.fileURLToPath( import.meta.url ) ) );
|
9
9
|
|
10
|
+
static {
|
11
|
+
try {
|
12
|
+
this.#config = JSON.parse( Files.read( "./data/config.json" ) );
|
13
|
+
} catch ( e ) {
|
14
|
+
console.log( e );
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
10
18
|
static getConfigValue( prefix, name, subcat, dflt ) {
|
11
19
|
const obj = this.#config[ prefix ];
|
12
20
|
if ( obj ) {
|
@@ -26,6 +34,10 @@ class Config {
|
|
26
34
|
return dflt;
|
27
35
|
}
|
28
36
|
|
37
|
+
static getCountyCodes() {
|
38
|
+
return this.#config[ "counties" ];
|
39
|
+
}
|
40
|
+
|
29
41
|
static getLabel( name, dflt ) {
|
30
42
|
return this.getConfigValue( "labels", name, undefined, dflt );
|
31
43
|
}
|
@@ -34,14 +46,6 @@ class Config {
|
|
34
46
|
return this.#packageDir;
|
35
47
|
}
|
36
48
|
|
37
|
-
static init( dir ) {
|
38
|
-
try {
|
39
|
-
this.#config = JSON.parse( fs.readFileSync( dir + "/config.json" ) );
|
40
|
-
} catch ( e ) {
|
41
|
-
console.log( e );
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
49
|
}
|
46
50
|
|
47
51
|
export { Config };
|
package/lib/exceptions.js
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
import
|
1
|
+
import { Files } from "./files.js";
|
2
2
|
|
3
3
|
class Exceptions {
|
4
4
|
|
5
5
|
static #exceptions = {};
|
6
6
|
|
7
|
-
static
|
7
|
+
static getExceptions() {
|
8
|
+
return Object.entries( this.#exceptions );
|
9
|
+
}
|
10
|
+
|
11
|
+
static getValue( name, cat, subcat, defaultValue ) {
|
8
12
|
const taxonData = this.#exceptions[ name ];
|
9
13
|
if ( taxonData ) {
|
10
14
|
const catData = taxonData[ cat ];
|
11
15
|
if ( catData ) {
|
12
|
-
|
16
|
+
const val = catData[ subcat ];
|
17
|
+
return ( val === undefined ) ? defaultValue : val;
|
13
18
|
}
|
14
19
|
}
|
15
|
-
return
|
20
|
+
return defaultValue;
|
16
21
|
}
|
17
22
|
|
18
|
-
static
|
23
|
+
static hasException( name, cat, subcat ) {
|
19
24
|
const taxonData = this.#exceptions[ name ];
|
20
25
|
if ( taxonData ) {
|
21
26
|
const catData = taxonData[ cat ];
|
22
27
|
if ( catData ) {
|
23
|
-
|
24
|
-
return ( val === undefined ) ? defaultValue : val;
|
28
|
+
return catData[ subcat ] !== undefined;
|
25
29
|
}
|
26
30
|
}
|
27
|
-
return
|
31
|
+
return false;
|
28
32
|
}
|
29
33
|
|
30
34
|
static init( dir ) {
|
31
35
|
try {
|
32
|
-
this.#exceptions = JSON.parse(
|
36
|
+
this.#exceptions = JSON.parse( Files.read( dir + "/exceptions.json" ) );
|
33
37
|
} catch ( e ) {
|
34
38
|
console.log( e );
|
35
39
|
}
|
package/lib/files.js
CHANGED
@@ -22,11 +22,30 @@ class Files {
|
|
22
22
|
return fs.existsSync( path );
|
23
23
|
}
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
/**
|
26
|
+
* Retrieve data from a URL and write it to a file.
|
27
|
+
* @param {string|URL} url
|
28
|
+
* @param {string|undefined} targetFileName If targetFileName is undefined, the data will be retrieved but not written to a file.
|
29
|
+
* @param {Object} [headers={}] Request Headers.
|
30
|
+
*/
|
31
|
+
static async fetch( url, targetFileName, headers = {} ) {
|
32
|
+
const response = await fetch( url, headers );
|
27
33
|
const data = await response.blob();
|
28
|
-
const
|
29
|
-
|
34
|
+
const arrayBuffer = await data.arrayBuffer();
|
35
|
+
const buffer = Buffer.from( arrayBuffer );
|
36
|
+
if ( targetFileName ) {
|
37
|
+
fs.writeFileSync( targetFileName, buffer );
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Retrieve data from a URL and return the Response Header.
|
43
|
+
* @param {string|URL} url
|
44
|
+
* @returns {Headers}
|
45
|
+
*/
|
46
|
+
static async fetchHeaders( url ) {
|
47
|
+
const response = await fetch( url );
|
48
|
+
return response.headers;
|
30
49
|
}
|
31
50
|
|
32
51
|
static mkdir( path ) {
|
@@ -41,8 +60,8 @@ class Files {
|
|
41
60
|
fs.rmSync( dir, { force: true, recursive: true, maxRetries: 2, retryDelay: 1000 } );
|
42
61
|
}
|
43
62
|
|
44
|
-
static write( path, data ) {
|
45
|
-
if ( this.exists( path ) ) {
|
63
|
+
static write( path, data, overwrite = false ) {
|
64
|
+
if ( !overwrite && this.exists( path ) ) {
|
46
65
|
throw new Error( path + " already exists" );
|
47
66
|
}
|
48
67
|
fs.writeFileSync( path, data );
|
package/lib/index.d.ts
CHANGED
@@ -2,11 +2,23 @@ export class Files {
|
|
2
2
|
static copyDir(srcDir: any, targetDir: any): void;
|
3
3
|
static createFileFromStream(fileName: any, inStream: any): Promise<any>;
|
4
4
|
static exists(path: any): boolean;
|
5
|
-
|
5
|
+
/**
|
6
|
+
* Retrieve data from a URL and write it to a file.
|
7
|
+
* @param {string|URL} url
|
8
|
+
* @param {string|undefined} targetFileName If targetFileName is undefined, the data will be retrieved but not written to a file.
|
9
|
+
* @param {Object} [headers={}] Request Headers.
|
10
|
+
*/
|
11
|
+
static fetch(url: string | URL, targetFileName: string | undefined, headers?: any): Promise<void>;
|
12
|
+
/**
|
13
|
+
* Retrieve data from a URL and return the Response Header.
|
14
|
+
* @param {string|URL} url
|
15
|
+
* @returns {Headers}
|
16
|
+
*/
|
17
|
+
static fetchHeaders(url: string | URL): Headers;
|
6
18
|
static mkdir(path: any): void;
|
7
19
|
static read(path: any): string;
|
8
20
|
static rmDir(dir: any): void;
|
9
|
-
static write(path: any, data: any): void;
|
21
|
+
static write(path: any, data: any, overwrite?: boolean): void;
|
10
22
|
static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
|
11
23
|
}
|
12
24
|
export namespace HTML_OPTIONS {
|
package/lib/pagetaxon.js
CHANGED
@@ -40,7 +40,7 @@ class PageTaxon extends GenericPage {
|
|
40
40
|
links.push(
|
41
41
|
HTML.getLink(
|
42
42
|
"https://www.calflora.org/entry/observ.html?track=m#srch=t&grezc=5&cols=b&lpcli=t&cc="
|
43
|
-
+ Config.
|
43
|
+
+ Config.getCountyCodes().join( "!" ) + "&incobs=f&taxon="
|
44
44
|
+ this.#taxon.getCalfloraName().replaceAll( " ", "+" ),
|
45
45
|
"Calflora",
|
46
46
|
{},
|
package/lib/taxon.js
CHANGED
@@ -192,6 +192,10 @@ class Taxon {
|
|
192
192
|
return this.#status === "N" || this.#status === "NC";
|
193
193
|
}
|
194
194
|
|
195
|
+
/**
|
196
|
+
* Determine whether a species is a local native.
|
197
|
+
* @returns {boolean} true if taxon is a local native; false if not a CA native, or native elsewhere in CA.
|
198
|
+
*/
|
195
199
|
isNative() {
|
196
200
|
return this.#status === "N";
|
197
201
|
}
|