vis-chronicle 1.2.0 → 1.2.2
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/package.json +3 -3
- package/src/fetch.js +1 -1
- package/src/relativeDates.js +18 -16
- package/src/wikidata.js +9 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vis-chronicle",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Generates JSON for populating a vis.js timeline from Wikidata queries.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wikidata",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"exports": {
|
|
20
20
|
"./styles/style.css": "./styles/style.css",
|
|
21
21
|
".": "./src/index.js",
|
|
22
|
-
|
|
22
|
+
"./wikidataToRange.js": "./src/wikidataToRange.js"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {},
|
|
25
25
|
"author": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"url": "https://brianmacintosh.com"
|
|
29
29
|
},
|
|
30
30
|
"license": "ISC",
|
|
31
|
-
"
|
|
31
|
+
"dependencies": {
|
|
32
32
|
"jewish-date": "2.0.23",
|
|
33
33
|
"moment": "2.30.1"
|
|
34
34
|
}
|
package/src/fetch.js
CHANGED
package/src/relativeDates.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const moment = require('moment')
|
|
3
3
|
const { toJewishDate, toGregorianDate, getIndexByJewishMonth } = require("jewish-date");
|
|
4
|
+
const wikidata = require('./wikidata');
|
|
4
5
|
|
|
5
6
|
function momentToHDate(inMoment)
|
|
6
7
|
{
|
|
@@ -26,23 +27,19 @@ function durationToWikidataPrecision(duration)
|
|
|
26
27
|
// Flattens a relative date string into a hard date string
|
|
27
28
|
module.exports = function flattenRelativeDate(wikidataCache, dateString)
|
|
28
29
|
{
|
|
30
|
+
if (dateString == '') return null
|
|
31
|
+
|
|
29
32
|
// parse out relative date components
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
while (true)
|
|
33
|
+
var relSplit
|
|
34
|
+
var match = dateString.match(wikidata.pathQueryRegex)
|
|
35
|
+
if (match)
|
|
34
36
|
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
relSplit.push(dateString.substring(lastSep))
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
lastSep = match.index
|
|
37
|
+
relSplit = match.slice(1)
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
{
|
|
41
|
+
console.error(`Failed to parse relative date '${dateString}'.`)
|
|
42
|
+
return null
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
if (!relSplit[0])
|
|
@@ -70,7 +67,12 @@ module.exports = function flattenRelativeDate(wikidataCache, dateString)
|
|
|
70
67
|
for (var i = 1; i < relSplit.length; i++)
|
|
71
68
|
{
|
|
72
69
|
const component = relSplit[i]
|
|
73
|
-
if (component
|
|
70
|
+
if (!component)
|
|
71
|
+
{
|
|
72
|
+
// empty group from regex
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
else if (component[0] == "+")
|
|
74
76
|
{
|
|
75
77
|
const momentDelta = moment.duration(component.substring(1))
|
|
76
78
|
momentDate = momentDate.add(momentDelta)
|
package/src/wikidata.js
CHANGED
|
@@ -41,6 +41,8 @@ const wikidata = module.exports = {
|
|
|
41
41
|
rankNormal: "http://wikiba.se/ontology#NormalRank",
|
|
42
42
|
rankPreferred: "http://wikiba.se/ontology#PreferredRank",
|
|
43
43
|
|
|
44
|
+
pathQueryRegex: /^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)([\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*$/,
|
|
45
|
+
|
|
44
46
|
initialize: function()
|
|
45
47
|
{
|
|
46
48
|
const chroniclePackage = require("../package.json")
|
|
@@ -499,21 +501,22 @@ const wikidata = module.exports = {
|
|
|
499
501
|
const wdQualifiers = new Set()
|
|
500
502
|
for (const query of queries)
|
|
501
503
|
{
|
|
502
|
-
|
|
504
|
+
const match = query.match(/^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)([\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*$/)
|
|
505
|
+
if (match && match[1])
|
|
503
506
|
{
|
|
504
|
-
const
|
|
505
|
-
const split =
|
|
507
|
+
const root = match[1]
|
|
508
|
+
const split = root.split(':')
|
|
506
509
|
if (split.length == 1)
|
|
507
510
|
{
|
|
508
|
-
wdStandaloneIds.add(
|
|
511
|
+
wdStandaloneIds.add(root)
|
|
509
512
|
}
|
|
510
513
|
else if (split.length == 2)
|
|
511
514
|
{
|
|
512
|
-
wdProperties.add(
|
|
515
|
+
wdProperties.add(root)
|
|
513
516
|
}
|
|
514
517
|
else if (split.length == 4)
|
|
515
518
|
{
|
|
516
|
-
wdQualifiers.add(
|
|
519
|
+
wdQualifiers.add(root)
|
|
517
520
|
}
|
|
518
521
|
else
|
|
519
522
|
{
|