@larsgw/formica 0.2.0 → 0.2.1
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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
## [0.2.1](https://github.com/identification-resources/formica/compare/v0.2.0...v0.2.1) (2023-08-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **resources:** do not validate old versions ([1a8dd2e](https://github.com/identification-resources/formica/commit/1a8dd2e0e373489e287d1fd89dbb7443245c5214))
|
|
7
|
+
* **resources:** fix check for missing leaf taxa ([035f1ad](https://github.com/identification-resources/formica/commit/035f1ad20efa80b388ec3828d4ace4518c7b344e))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# [0.2.0](https://github.com/identification-resources/formica/compare/v0.1.1...v0.2.0) (2023-08-09)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **catalog:** add taxon_scope column ([6a06c37](https://github.com/identification-resources/formica/commit/6a06c37ec0640a8ffbc258ad6a4d81d84d35fee9))
|
|
17
|
+
* **resources:** check for missing leaf taxa ([387c47d](https://github.com/identification-resources/formica/commit/387c47d10bb7f1fb09a68c10dfa869bb924b7633))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [0.1.1](https://github.com/identification-resources/formica/compare/v0.1.0...v0.1.1) (2023-05-10)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **processor:** add Node hashbang ([51dee57](https://github.com/identification-resources/formica/commit/51dee57b8547afba449b2b846bd7d65e7927368f))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [0.1.0](https://github.com/identification-resources/formica/compare/fed91fd6f350c47bd067d221a4d0e2278a199dae...v0.1.0) (2023-03-01)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **resources:** fix typo in taxon name pattern ([8f1b6cf](https://github.com/identification-resources/formica/commit/8f1b6cfa3858edb83c0aee589b84ad760ab815af))
|
|
36
|
+
* **resources:** improve name parsing heuristics ([a40642e](https://github.com/identification-resources/formica/commit/a40642e9bdaeaae363584712e45f218809a5754b))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* **catalog:** add SDK for catalog data ([fed91fd](https://github.com/identification-resources/formica/commit/fed91fd6f350c47bd067d221a4d0e2278a199dae))
|
|
42
|
+
* **csv:** allow custom delims in output ([b523614](https://github.com/identification-resources/formica/commit/b523614171b0ff96347cb876a08106df413c4032))
|
|
43
|
+
* **processor:** processor for DwC creation ([0e6f21d](https://github.com/identification-resources/formica/commit/0e6f21dfe00a2892348a4ab04fcaf3d6c8324a91))
|
|
44
|
+
* **processor:** processor for DwC indexing ([279773b](https://github.com/identification-resources/formica/commit/279773b085676cf7cb3eb4d81496ad219ac85bce))
|
|
45
|
+
* **resources:** add SDK for resource text files ([0acd36d](https://github.com/identification-resources/formica/commit/0acd36dde04cc1240cb8be97d48812b201b2685a))
|
|
46
|
+
* **resources:** add support for cluster markings ([112315c](https://github.com/identification-resources/formica/commit/112315c7ebd7151c4e2cc77ab20e0cec3f579db6))
|
|
47
|
+
* **resources:** add support for diffs as input ([9751627](https://github.com/identification-resources/formica/commit/9751627a916f47552661596048f1f0d44d89b102))
|
|
48
|
+
* **resources:** add support for hybrids ([e49e96a](https://github.com/identification-resources/formica/commit/e49e96af9c3958bab2a3b0508b1fc8a018b80716))
|
|
49
|
+
* **validate:** add catalog validation script ([4cdf785](https://github.com/identification-resources/formica/commit/4cdf785afb2c77320cd9b5b76483e3464c0f1cff))
|
|
50
|
+
* **validate:** add script to validate resources ([246fb5d](https://github.com/identification-resources/formica/commit/246fb5dd8da03e736884850874cc51a11be9985c))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -43,6 +43,15 @@ var RANKS = [
|
|
|
43
43
|
'race',
|
|
44
44
|
'stirps' // not ICZN
|
|
45
45
|
];
|
|
46
|
+
var MAIN_RANKS = [
|
|
47
|
+
'kingdom',
|
|
48
|
+
'phylum',
|
|
49
|
+
'class',
|
|
50
|
+
'order',
|
|
51
|
+
'family',
|
|
52
|
+
'genus',
|
|
53
|
+
'species'
|
|
54
|
+
];
|
|
46
55
|
var DWC_RANKS = [
|
|
47
56
|
'kingdom',
|
|
48
57
|
'phylum',
|
|
@@ -350,10 +359,7 @@ function parseHeader(header) {
|
|
|
350
359
|
}
|
|
351
360
|
return metadata;
|
|
352
361
|
}
|
|
353
|
-
function
|
|
354
|
-
var _a = resource.split(/(\n---\n+)/), header = _a[0], _ = _a[1], rest = _a.slice(2);
|
|
355
|
-
var config = parseHeader(header);
|
|
356
|
-
var content = rest.join('');
|
|
362
|
+
function validateResource(config, content) {
|
|
357
363
|
// Check for too much indentation
|
|
358
364
|
var longerIndent = new RegExp("^( ){".concat(config.levels.length - 1, "}(?! [+=>] ) "), 'm');
|
|
359
365
|
var longerIndentMatch = content.match(longerIndent);
|
|
@@ -363,13 +369,22 @@ function parseResource(resource) {
|
|
|
363
369
|
throw new SyntaxError("Too much indentation at ".concat(line, ":0\n").concat(content.slice(offset).split('\n', 1), "\n^"));
|
|
364
370
|
}
|
|
365
371
|
// Check for missing leaf taxa
|
|
366
|
-
var
|
|
367
|
-
var
|
|
368
|
-
if (
|
|
369
|
-
var
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
+
var leafTaxonRank = config.levels.filter(function (rank) { return MAIN_RANKS.includes(rank); }).pop();
|
|
373
|
+
var leafTaxonParentIndent = config.levels.indexOf(leafTaxonRank) - 1;
|
|
374
|
+
if (leafTaxonRank && leafTaxonParentIndent >= 0) {
|
|
375
|
+
var missingLeafTaxa = new RegExp("^((?: ){0,".concat(leafTaxonParentIndent, "})(?![+=> ] ).*\\n(\\1( )+[+=>].*\\n)*(?!\\1 )"), 'm');
|
|
376
|
+
var missingLeafTaxaMatch = content.match(missingLeafTaxa);
|
|
377
|
+
if (missingLeafTaxaMatch !== null) {
|
|
378
|
+
var offset = missingLeafTaxaMatch.index;
|
|
379
|
+
var line = (content.slice(0, offset).match(/\n/g) || []).length + 1;
|
|
380
|
+
throw new SyntaxError("Missing leaf taxon at ".concat(line, ":0\n").concat(content.slice(offset).split('\n', 1), "\n^"));
|
|
381
|
+
}
|
|
372
382
|
}
|
|
383
|
+
}
|
|
384
|
+
function parseResource(resource) {
|
|
385
|
+
var _a = resource.split(/(\n---\n+)/), header = _a[0], _ = _a[1], rest = _a.slice(2);
|
|
386
|
+
var config = parseHeader(header);
|
|
387
|
+
var content = rest.join('');
|
|
373
388
|
return [config, content];
|
|
374
389
|
}
|
|
375
390
|
function parseResourceContent(content, resource, oldIds) {
|
|
@@ -476,6 +491,7 @@ function parseFile(file, id, old) {
|
|
|
476
491
|
var oldResources = old ? splitResources(old.txt) : [];
|
|
477
492
|
return splitResources(file).map(function (resource, index) {
|
|
478
493
|
var _a = parseResource(resource), config = _a[0], content = _a[1];
|
|
494
|
+
validateResource(config, content);
|
|
479
495
|
var template = {
|
|
480
496
|
id: "".concat(id, ":").concat(index + 1),
|
|
481
497
|
file: "".concat(id, "-").concat(index + 1),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@larsgw/formica",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "SDK and tools for data from the Library of Identification Resources",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"test": "node --test --test-reporter spec",
|
|
15
15
|
"lint": "eslint src",
|
|
16
16
|
"build": "tsc -d",
|
|
17
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
17
18
|
"preversion": "npm run lint",
|
|
19
|
+
"version": "npm run changelog && git add CHANGELOG.md",
|
|
18
20
|
"prepublishOnly": "npm run build"
|
|
19
21
|
},
|
|
20
22
|
"repository": {
|
|
@@ -37,6 +39,7 @@
|
|
|
37
39
|
"@types/node": "^18.14.1",
|
|
38
40
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
39
41
|
"@typescript-eslint/parser": "^5.54.0",
|
|
42
|
+
"conventional-changelog-cli": "^3.0.0",
|
|
40
43
|
"eslint": "^8.35.0",
|
|
41
44
|
"typescript": "^4.9.5"
|
|
42
45
|
}
|
|
@@ -31,6 +31,16 @@ const RANKS: Rank[] = [
|
|
|
31
31
|
'stirps' // not ICZN
|
|
32
32
|
]
|
|
33
33
|
|
|
34
|
+
const MAIN_RANKS: Rank[] = [
|
|
35
|
+
'kingdom',
|
|
36
|
+
'phylum',
|
|
37
|
+
'class',
|
|
38
|
+
'order',
|
|
39
|
+
'family',
|
|
40
|
+
'genus',
|
|
41
|
+
'species'
|
|
42
|
+
]
|
|
43
|
+
|
|
34
44
|
const DWC_RANKS: DwcRank[] = [
|
|
35
45
|
'kingdom',
|
|
36
46
|
'phylum',
|
|
@@ -360,11 +370,7 @@ function parseHeader (header: string): ResourceMetadata {
|
|
|
360
370
|
return metadata
|
|
361
371
|
}
|
|
362
372
|
|
|
363
|
-
function
|
|
364
|
-
const [header, _, ...rest] = resource.split(/(\n---\n+)/)
|
|
365
|
-
const config = parseHeader(header)
|
|
366
|
-
const content = rest.join('')
|
|
367
|
-
|
|
373
|
+
function validateResource (config: ResourceMetadata, content: string) {
|
|
368
374
|
// Check for too much indentation
|
|
369
375
|
const longerIndent = new RegExp(`^( ){${config.levels.length - 1}}(?! [+=>] ) `, 'm')
|
|
370
376
|
const longerIndentMatch = content.match(longerIndent)
|
|
@@ -377,15 +383,25 @@ ${content.slice(offset).split('\n', 1)}
|
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
// Check for missing leaf taxa
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
+
const leafTaxonRank = config.levels.filter(rank => MAIN_RANKS.includes(rank)).pop() as string
|
|
387
|
+
const leafTaxonParentIndent = config.levels.indexOf(leafTaxonRank) - 1
|
|
388
|
+
if (leafTaxonRank && leafTaxonParentIndent >= 0) {
|
|
389
|
+
const missingLeafTaxa = new RegExp(`^((?: ){0,${leafTaxonParentIndent}})(?![+=> ] ).*\\n(\\1( )+[+=>].*\\n)*(?!\\1 )`, 'm')
|
|
390
|
+
const missingLeafTaxaMatch = content.match(missingLeafTaxa)
|
|
391
|
+
if (missingLeafTaxaMatch !== null) {
|
|
392
|
+
const offset = missingLeafTaxaMatch.index
|
|
393
|
+
const line = (content.slice(0, offset).match(/\n/g) || []).length + 1
|
|
394
|
+
throw new SyntaxError(`Missing leaf taxon at ${line}:0
|
|
386
395
|
${content.slice(offset).split('\n', 1)}
|
|
387
396
|
^`)
|
|
397
|
+
}
|
|
388
398
|
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function parseResource (resource: string): [ResourceMetadata, string] {
|
|
402
|
+
const [header, _, ...rest] = resource.split(/(\n---\n+)/)
|
|
403
|
+
const config = parseHeader(header)
|
|
404
|
+
const content = rest.join('')
|
|
389
405
|
|
|
390
406
|
return [config, content]
|
|
391
407
|
}
|
|
@@ -499,6 +515,7 @@ export function parseFile (file: string, id: WorkId, old?: ResourceHistory): Res
|
|
|
499
515
|
const oldResources = old ? splitResources(old.txt) : []
|
|
500
516
|
return splitResources(file).map((resource, index) => {
|
|
501
517
|
const [config, content] = parseResource(resource)
|
|
518
|
+
validateResource(config, content)
|
|
502
519
|
const template: Resource = {
|
|
503
520
|
id: `${id}:${index + 1}`,
|
|
504
521
|
file: `${id}-${index + 1}`,
|