stated-protocol-parser 1.0.3 → 1.0.5
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/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -0
- package/dist/esm/constants.d.ts +47 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +47 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/hash.browser.d.ts +31 -0
- package/dist/esm/hash.browser.d.ts.map +1 -0
- package/dist/esm/hash.browser.js +58 -0
- package/dist/esm/hash.browser.js.map +1 -0
- package/dist/esm/hash.node.d.ts +31 -0
- package/dist/esm/hash.node.d.ts.map +1 -0
- package/dist/esm/hash.node.js +43 -0
- package/dist/esm/hash.node.js.map +1 -0
- package/dist/esm/hash.test.d.ts +2 -0
- package/dist/esm/hash.test.d.ts.map +1 -0
- package/dist/esm/hash.test.js +181 -0
- package/dist/esm/hash.test.js.map +1 -0
- package/dist/esm/index.d.ts +44 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +643 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.test.d.ts +2 -0
- package/dist/esm/index.test.d.ts.map +1 -0
- package/dist/esm/index.test.js +293 -0
- package/dist/esm/index.test.js.map +1 -0
- package/dist/esm/types.d.ts +149 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +4 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +23 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/v3.d.ts +5 -0
- package/dist/esm/v3.d.ts.map +1 -0
- package/dist/esm/v3.js +60 -0
- package/dist/esm/v3.js.map +1 -0
- package/dist/hash.browser.d.ts +1 -0
- package/dist/hash.browser.d.ts.map +1 -0
- package/dist/hash.browser.js +1 -0
- package/dist/hash.browser.js.map +1 -0
- package/dist/hash.node.d.ts +1 -0
- package/dist/hash.node.d.ts.map +1 -0
- package/dist/hash.node.js +1 -0
- package/dist/hash.node.js.map +1 -0
- package/dist/hash.test.d.ts +2 -0
- package/dist/hash.test.d.ts.map +1 -0
- package/dist/hash.test.js +183 -0
- package/dist/hash.test.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +295 -0
- package/dist/index.test.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/dist/v3.d.ts +1 -0
- package/dist/v3.d.ts.map +1 -0
- package/dist/v3.js +1 -0
- package/dist/v3.js.map +1 -0
- package/package.json +7 -13
- package/src/constants.ts +61 -0
- package/src/hash.browser.ts +65 -0
- package/src/hash.node.ts +47 -0
- package/src/hash.test.ts +217 -0
- package/src/index.test.ts +378 -0
- package/src/index.ts +678 -0
- package/src/types.ts +186 -0
- package/src/utils.ts +18 -0
- package/src/v3.ts +62 -0
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
/* eslint-disable no-useless-concat */
|
|
2
|
+
import { legalForms, UTCFormat, peopleCountBuckets } from './constants';
|
|
3
|
+
import { parsePollV3 } from './v3';
|
|
4
|
+
import { monthIndex, birthDateFormat } from './utils';
|
|
5
|
+
const fallBackVersion = 3;
|
|
6
|
+
const version = 4;
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './constants';
|
|
9
|
+
export * from './utils';
|
|
10
|
+
export * from './v3';
|
|
11
|
+
// Export browser-compatible async hash functions (default)
|
|
12
|
+
export * from './hash.browser';
|
|
13
|
+
// Export Node.js synchronous hash functions with clear names
|
|
14
|
+
export { sha256 as sha256Node, verify as verifyNode, fromUrlSafeBase64, toUrlSafeBase64 } from './hash.node';
|
|
15
|
+
export const buildStatement = ({ domain, author, time, tags, content, representative, supersededStatement }) => {
|
|
16
|
+
if (content.match(/\nPublishing domain: /))
|
|
17
|
+
throw (new Error("Statement must not contain 'Publishing domain: ', as this marks the beginning of a new statement."));
|
|
18
|
+
if (content.match(/\n\n/))
|
|
19
|
+
throw (new Error("Statement must not contain two line breaks in a row, as this is used for separating statements."));
|
|
20
|
+
if (typeof time !== 'object' || !time.toUTCString)
|
|
21
|
+
throw (new Error("Time must be a Date object."));
|
|
22
|
+
if (!domain)
|
|
23
|
+
throw (new Error("Publishing domain missing."));
|
|
24
|
+
const statement = "Publishing domain: " + domain + "\n" +
|
|
25
|
+
"Author: " + (author || "") + "\n" +
|
|
26
|
+
(representative && representative?.length > 0 ? "Authorized signing representative: " + (representative || "") + "\n" : '') +
|
|
27
|
+
"Time: " + time.toUTCString() + "\n" +
|
|
28
|
+
(tags && tags.length > 0 ? "Tags: " + tags.join(', ') + "\n" : '') +
|
|
29
|
+
(supersededStatement && supersededStatement?.length > 0 ? "Superseded statement: " + (supersededStatement || "") + "\n" : '') +
|
|
30
|
+
"Format version: " + version + "\n" +
|
|
31
|
+
"Statement content: " + content + (content.match(/\n$/) ? '' : "\n");
|
|
32
|
+
if (statement.length > 3000)
|
|
33
|
+
throw (new Error("Statement must not be longer than 3,000 characters."));
|
|
34
|
+
return statement;
|
|
35
|
+
};
|
|
36
|
+
export const parseStatement = ({ statement: s, allowNoVersion = false }) => {
|
|
37
|
+
if (s.length > 3000)
|
|
38
|
+
throw (new Error("Statement must not be longer than 3,000 characters."));
|
|
39
|
+
if (s.match(/\n\n/))
|
|
40
|
+
throw new Error("Statements cannot contain two line breaks in a row, as this is used for separating statements.");
|
|
41
|
+
const statementRegex = new RegExp(''
|
|
42
|
+
+ /^Publishing domain: (?<domain>[^\n]+?)\n/.source
|
|
43
|
+
+ /Author: (?<author>[^\n]+?)\n/.source
|
|
44
|
+
+ /(?:Authorized signing representative: (?<representative>[^\n]*?)\n)?/.source
|
|
45
|
+
+ /Time: (?<time>[^\n]+?)\n/.source
|
|
46
|
+
+ /(?:Tags: (?<tags>[^\n]*?)\n)?/.source
|
|
47
|
+
+ /(?:Superseded statement: (?<supersededStatement>[^\n]*?)\n)?/.source
|
|
48
|
+
+ /(?:Format version: (?<formatVersion>[^\n]*?)\n)?/.source
|
|
49
|
+
+ /Statement content: (?:(?<typedContent>\n\tType: (?<type>[^\n]+?)\n[\s\S]+?\n$)|(?<content>[\s\S]+?\n$))/.source);
|
|
50
|
+
const match = s.match(statementRegex);
|
|
51
|
+
if (!match)
|
|
52
|
+
throw new Error("Invalid statement format:" + s);
|
|
53
|
+
const m = {
|
|
54
|
+
domain: match[1], author: match[2], representative: match[3], timeStr: match[4], tagsStr: match[5],
|
|
55
|
+
supersededStatement: match[6], formatVersion: match[7], content: match[8] || match[10],
|
|
56
|
+
type: match[9] ? match[9].toLowerCase().replace(' ', '_') : undefined
|
|
57
|
+
};
|
|
58
|
+
if (!(m['timeStr'].match(UTCFormat)))
|
|
59
|
+
throw new Error("Invalid statement format: time must be in UTC");
|
|
60
|
+
if (!m['domain'])
|
|
61
|
+
throw new Error("Invalid statement format: domain is required");
|
|
62
|
+
if (!m['author'])
|
|
63
|
+
throw new Error("Invalid statement format: author is required");
|
|
64
|
+
if (!m['content'])
|
|
65
|
+
throw new Error("Invalid statement format: statement content is required");
|
|
66
|
+
if (!allowNoVersion && !m['formatVersion'])
|
|
67
|
+
throw new Error("Invalid statement format: format version is required");
|
|
68
|
+
const tags = m['tagsStr']?.split(', ');
|
|
69
|
+
const time = new Date(m['timeStr']);
|
|
70
|
+
return {
|
|
71
|
+
domain: m['domain'],
|
|
72
|
+
author: m['author'],
|
|
73
|
+
representative: m['representative'],
|
|
74
|
+
time,
|
|
75
|
+
tags: (tags && tags.length > 0) ? tags : undefined,
|
|
76
|
+
supersededStatement: m['supersededStatement'],
|
|
77
|
+
formatVersion: m['formatVersion'] || ('' + fallBackVersion),
|
|
78
|
+
content: m['content'],
|
|
79
|
+
type: m['type']?.toLowerCase().replace(' ', '_'),
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export const buildQuotationContent = ({ originalAuthor, authorVerification, originalTime, source, quotation, paraphrasedStatement, picture, confidence }) => {
|
|
83
|
+
if (quotation && quotation.match(/\n/))
|
|
84
|
+
throw (new Error("Quotation must not contain line breaks."));
|
|
85
|
+
if (!paraphrasedStatement && !quotation)
|
|
86
|
+
throw (new Error("Quotation must contain either a quotation or a paraphrased statement."));
|
|
87
|
+
const content = "\n" +
|
|
88
|
+
"\t" + "Type: Quotation" + "\n" +
|
|
89
|
+
"\t" + "Original author: " + originalAuthor + "\n" +
|
|
90
|
+
"\t" + "Author verification: " + authorVerification + "\n" +
|
|
91
|
+
(originalTime && originalTime?.length > 0 ? "\t" + "Original publication time: " + originalTime + "\n" : "") +
|
|
92
|
+
(source && source?.length > 0 ? "\t" + "Source: " + (source || "") + "\n" : '') +
|
|
93
|
+
(picture && picture.length > 0 ? "\t" + "Picture proof: " + (picture || "") + "\n" : '') +
|
|
94
|
+
(confidence && confidence?.length > 0 ? "\t" + "Confidence: " + (confidence || "") + "\n" : '') +
|
|
95
|
+
(quotation && quotation?.length > 0 ? "\t" + "Quotation: " + (quotation || "") + "\n" : '') +
|
|
96
|
+
(paraphrasedStatement && paraphrasedStatement?.length > 0 ? "\t" + "Paraphrased statement: " +
|
|
97
|
+
(paraphrasedStatement || "").replace(/\n\t([^\t])/, '\n\t\t($1)') + "\n" : '') +
|
|
98
|
+
"";
|
|
99
|
+
return content;
|
|
100
|
+
};
|
|
101
|
+
export const parseQuotation = (s) => {
|
|
102
|
+
const voteRegex = new RegExp(''
|
|
103
|
+
+ /^\n\tType: Quotation\n/.source
|
|
104
|
+
+ /\tOriginal author: (?<originalAuthor>[^\n]+?)\n/.source
|
|
105
|
+
+ /\tAuthor verification: (?<authorVerification>[^\n]+?)\n/.source
|
|
106
|
+
+ /(?:\tOriginal publication time: (?<originalTime>[^\n]+?)\n)?/.source
|
|
107
|
+
+ /(?:\tSource: (?<source>[^\n]+?)\n)?/.source
|
|
108
|
+
+ /(?:\tPicture proof: (?<picture>[^\n]+?)\n)?/.source
|
|
109
|
+
+ /(?:\tConfidence: (?<confidence>[^\n]+?)\n)?/.source
|
|
110
|
+
+ /(?:\tQuotation: (?<quotation>[^\n]+?)\n)?/.source
|
|
111
|
+
+ /(?:\tParaphrased statement: (?:(?<paraphrasedTypedStatement>\n\t\tType: (?<type>[^\n]+?)\n[\s\S]+?)|(?<paraphrasedStatement>[\s\S]+?)))/.source
|
|
112
|
+
+ /$/.source);
|
|
113
|
+
let match = s.match(voteRegex);
|
|
114
|
+
if (!match)
|
|
115
|
+
throw new Error("Invalid quotation format: " + s);
|
|
116
|
+
let m = {};
|
|
117
|
+
m = {
|
|
118
|
+
originalAuthor: match[1], authorVerification: match[2], originalTime: match[3], source: match[4],
|
|
119
|
+
picture: match[5], confidence: match[6], quotation: match[7], paraphrasedStatement: match[8] || match[10],
|
|
120
|
+
type: match[9] ? match[9].toLowerCase().replace(' ', '_') : undefined
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
originalAuthor: m['originalAuthor'],
|
|
124
|
+
authorVerification: m['authorVerification'],
|
|
125
|
+
originalTime: m['originalTime'],
|
|
126
|
+
source: m['source'],
|
|
127
|
+
picture: m['picture'],
|
|
128
|
+
confidence: m['confidence'],
|
|
129
|
+
quotation: m['quotation'],
|
|
130
|
+
paraphrasedStatement: (m['paraphrasedStatement']?.replace(/\n\t\t/g, "\n\t")),
|
|
131
|
+
type: m['type']?.toLowerCase().replace(' ', '_'),
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export const buildPollContent = ({ country, city, legalEntity, domainScope, judges, deadline, poll, scopeDescription, scopeQueryLink, options, allowArbitraryVote, requiredProperty: propertyScope, requiredPropertyObserver: propertyScopeObserver }) => {
|
|
135
|
+
if (!poll)
|
|
136
|
+
throw (new Error("Poll must contain a poll question."));
|
|
137
|
+
const scopeContent = (scopeDescription ? "\t\t" + "Description: " + scopeDescription + "\n" : "") +
|
|
138
|
+
(country ? "\t\t" + "Country scope: " + country + "\n" : "") +
|
|
139
|
+
(city ? "\t\t" + "City scope: " + city + "\n" : "") +
|
|
140
|
+
(legalEntity ? "\t\t" + "Legal form scope: " + legalEntity + "\n" : "") +
|
|
141
|
+
(domainScope && domainScope?.length > 0 ? "\t\t" + "Domain scope: " + domainScope.join(', ') + "\n" : "") +
|
|
142
|
+
(propertyScope ? "\t\t" + "All entities with the following property: " + propertyScope + "\n" : "") +
|
|
143
|
+
(propertyScopeObserver ? "\t\t" + "As observed by: " + propertyScopeObserver + "\n" : "") +
|
|
144
|
+
(scopeQueryLink ? "\t\t" + "Link to query defining who can vote: " + scopeQueryLink + "\n" : "");
|
|
145
|
+
if (scopeContent.length > 0 && !scopeDescription)
|
|
146
|
+
throw (new Error("Poll must contain a description of who can vote."));
|
|
147
|
+
const content = "\n" +
|
|
148
|
+
"\t" + "Type: Poll" + "\n" +
|
|
149
|
+
(judges ? "\t" + "The poll outcome is finalized when the following nodes agree: " + judges + "\n" : "") +
|
|
150
|
+
(deadline ? "\t" + "Voting deadline: " + deadline.toUTCString() + "\n" : "") +
|
|
151
|
+
"\t" + "Poll: " + poll + "\n" +
|
|
152
|
+
(options.length > 0 && options[0] ? "\t" + "Option 1: " + options[0] + "\n" : "") +
|
|
153
|
+
(options.length > 1 && options[1] ? "\t" + "Option 2: " + options[1] + "\n" : "") +
|
|
154
|
+
(options.length > 2 && options[2] ? "\t" + "Option 3: " + options[2] + "\n" : "") +
|
|
155
|
+
(options.length > 3 && options[3] ? "\t" + "Option 4: " + options[3] + "\n" : "") +
|
|
156
|
+
(options.length > 4 && options[4] ? "\t" + "Option 5: " + options[4] + "\n" : "") +
|
|
157
|
+
((allowArbitraryVote === true || allowArbitraryVote === false) ? ("\t" + "Allow free text votes: " + (allowArbitraryVote ? 'Yes' : 'No') + "\n") : "") +
|
|
158
|
+
(scopeContent ? "\t" + "Who can vote: \n" + scopeContent : "") +
|
|
159
|
+
"";
|
|
160
|
+
return content;
|
|
161
|
+
};
|
|
162
|
+
export const parsePoll = (s, version) => {
|
|
163
|
+
if (version && version === '3')
|
|
164
|
+
return parsePollV3(s);
|
|
165
|
+
if (version && version !== '4')
|
|
166
|
+
throw new Error("Invalid version " + version);
|
|
167
|
+
const pollRegex = new RegExp(''
|
|
168
|
+
+ /^\n\tType: Poll\n/.source
|
|
169
|
+
+ /(?:\tThe poll outcome is finalized when the following nodes agree: (?<judges>[^\n]+?)\n)?/.source
|
|
170
|
+
+ /(?:\tVoting deadline: (?<deadline>[^\n]+?)\n)?/.source
|
|
171
|
+
+ /\tPoll: (?<poll>[^\n]+?)\n/.source
|
|
172
|
+
+ /(?:\tOption 1: (?<option1>[^\n]+?)\n)?/.source
|
|
173
|
+
+ /(?:\tOption 2: (?<option2>[^\n]+?)\n)?/.source
|
|
174
|
+
+ /(?:\tOption 3: (?<option3>[^\n]+?)\n)?/.source
|
|
175
|
+
+ /(?:\tOption 4: (?<option4>[^\n]+?)\n)?/.source
|
|
176
|
+
+ /(?:\tOption 5: (?<option5>[^\n]+?)\n)?/.source
|
|
177
|
+
+ /(?:\tAllow free text votes: (?<allowArbitraryVote>Yes|No)\n)?/.source
|
|
178
|
+
+ /(?:\tWho can vote: (?<whoCanVote>\n[\s\S]+?\n))?/.source
|
|
179
|
+
+ /$/.source);
|
|
180
|
+
let m = s.match(pollRegex);
|
|
181
|
+
if (!m)
|
|
182
|
+
throw new Error("Invalid poll format: " + s);
|
|
183
|
+
m = {
|
|
184
|
+
judges: m[1], deadline: m[2], poll: m[3],
|
|
185
|
+
option1: m[4], option2: m[5], option3: m[6], option4: m[7], option5: m[8],
|
|
186
|
+
allowArbitraryVote: m[9],
|
|
187
|
+
whoCanVote: m[10]
|
|
188
|
+
};
|
|
189
|
+
const whoCanVoteParsed = {};
|
|
190
|
+
if (m.whoCanVote) {
|
|
191
|
+
const whoCanVoteRegex = new RegExp(''
|
|
192
|
+
+ /^\n\t\tDescription: (?<scopeDescription>[^\n]+?)\n/.source
|
|
193
|
+
+ /(?:\t\tCountry scope: (?<countryScope>[^\n]+?)\n)?/.source
|
|
194
|
+
+ /(?:\t\tCity scope: (?<cityScope>[^\n]+?)\n)?/.source
|
|
195
|
+
+ /(?:\t\tLegal form scope: (?<legalEntity>[^\n]+?)\n)?/.source
|
|
196
|
+
+ /(?:\t\tDomain scope: (?<domainScope>[^\n]+?)\n)?/.source
|
|
197
|
+
+ /(?:\t\tAll entities with the following property: (?<propertyScope>[^\n]+?)\n)?/.source
|
|
198
|
+
+ /(?:\t\tAs observed by: (?<propertyScopeObserver>[^\n]+?)\n)?/.source
|
|
199
|
+
+ /(?:\t\tLink to query defining who can vote: (?<scopeQueryLink>[^\n]+?)\n)?/.source
|
|
200
|
+
+ /$/.source);
|
|
201
|
+
let m2 = m.whoCanVote.match(whoCanVoteRegex);
|
|
202
|
+
if (!m2)
|
|
203
|
+
throw new Error("Invalid who can vote section: " + m.whoCanVote);
|
|
204
|
+
whoCanVoteParsed['scopeDescription'] = m2[1];
|
|
205
|
+
whoCanVoteParsed['country'] = m2[2];
|
|
206
|
+
whoCanVoteParsed['city'] = m2[3];
|
|
207
|
+
whoCanVoteParsed['legalEntity'] = m2[4];
|
|
208
|
+
whoCanVoteParsed['domainScopeStr'] = m2[5];
|
|
209
|
+
whoCanVoteParsed['requiredProperty'] = m2[6];
|
|
210
|
+
whoCanVoteParsed['requiredPropertyObserver'] = m2[7];
|
|
211
|
+
whoCanVoteParsed['scopeQueryLink'] = m2[8];
|
|
212
|
+
}
|
|
213
|
+
const options = [m.option1, m.option2, m.option3, m.option4, m.option5].filter(o => o);
|
|
214
|
+
const domainScope = whoCanVoteParsed.domainScopeStr?.split(', ');
|
|
215
|
+
const allowArbitraryVote = (m['allowArbitraryVote'] === 'Yes' ? true :
|
|
216
|
+
(m['allowArbitraryVote'] === 'No' ? false : undefined));
|
|
217
|
+
const deadlineStr = m.deadline;
|
|
218
|
+
if (deadlineStr && !deadlineStr.match(UTCFormat))
|
|
219
|
+
throw new Error("Invalid poll, deadline must be in UTC: " + deadlineStr);
|
|
220
|
+
return {
|
|
221
|
+
judges: m['judges'],
|
|
222
|
+
deadline: deadlineStr ? new Date(deadlineStr) : undefined,
|
|
223
|
+
poll: m['poll'],
|
|
224
|
+
options,
|
|
225
|
+
allowArbitraryVote,
|
|
226
|
+
country: whoCanVoteParsed['country'],
|
|
227
|
+
scopeDescription: whoCanVoteParsed['scopeDescription'],
|
|
228
|
+
requiredProperty: whoCanVoteParsed['requiredProperty'],
|
|
229
|
+
requiredPropertyObserver: whoCanVoteParsed['requiredPropertyObserver'],
|
|
230
|
+
scopeQueryLink: whoCanVoteParsed['scopeQueryLink'],
|
|
231
|
+
city: whoCanVoteParsed['city'],
|
|
232
|
+
legalEntity: whoCanVoteParsed['legalEntity'],
|
|
233
|
+
domainScope: (domainScope && domainScope.length > 0) ? domainScope : undefined,
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
export const buildOrganisationVerificationContent = ({ name, englishName, country, city, province, legalForm, department, domain, foreignDomain, serialNumber, confidence, reliabilityPolicy, employeeCount, pictureHash, latitude, longitude, population }) => {
|
|
237
|
+
if (!name || !country || !legalForm || (!domain && !foreignDomain))
|
|
238
|
+
throw new Error("Missing required fields");
|
|
239
|
+
if (!Object.values(legalForms).includes(legalForm))
|
|
240
|
+
throw new Error("Invalid legal form " + legalForm);
|
|
241
|
+
if (employeeCount && !Object.values(peopleCountBuckets).includes(employeeCount))
|
|
242
|
+
throw new Error("Invalid employee count " + employeeCount);
|
|
243
|
+
if (population && !Object.values(peopleCountBuckets).includes(population))
|
|
244
|
+
throw new Error("Invalid population " + population);
|
|
245
|
+
if (confidence && !('' + confidence)?.match(/^[0-9.]+$/))
|
|
246
|
+
throw new Error("Invalid confidence " + confidence);
|
|
247
|
+
return "\n" +
|
|
248
|
+
"\t" + "Type: Organisation verification" + "\n" +
|
|
249
|
+
"\t" + "Description: We verified the following information about an organisation." + "\n" +
|
|
250
|
+
"\t" + "Name: " + name + "\n" +
|
|
251
|
+
(englishName ? "\t" + "English name: " + englishName + "\n" : "") +
|
|
252
|
+
"\t" + "Country: " + country + "\n" +
|
|
253
|
+
"\t" + "Legal form: " + legalForm + "\n" +
|
|
254
|
+
(domain ? "\t" + "Owner of the domain: " + domain + "\n" : "") +
|
|
255
|
+
(foreignDomain ? "\t" + "Foreign domain used for publishing statements: " + foreignDomain + "\n" : "") +
|
|
256
|
+
(department ? "\t" + "Department using the domain: " + department + "\n" : "") +
|
|
257
|
+
(province ? "\t" + "Province or state: " + province + "\n" : "") +
|
|
258
|
+
(serialNumber ? "\t" + "Business register number: " + serialNumber + "\n" : "") +
|
|
259
|
+
(city ? "\t" + "City: " + city + "\n" : "") +
|
|
260
|
+
(latitude ? "\t" + "Latitude: " + latitude + "\n" : "") +
|
|
261
|
+
(longitude ? "\t" + "Longitude: " + longitude + "\n" : "") +
|
|
262
|
+
(population ? "\t" + "Population: " + population + "\n" : "") +
|
|
263
|
+
(pictureHash ? "\t" + "Logo: " + pictureHash + "\n" : "") +
|
|
264
|
+
(employeeCount ? "\t" + "Employee count: " + employeeCount + "\n" : "") +
|
|
265
|
+
(reliabilityPolicy ? "\t" + "Reliability policy: " + reliabilityPolicy + "\n" : "") +
|
|
266
|
+
(confidence ? "\t" + "Confidence: " + confidence + "\n" : "") +
|
|
267
|
+
"";
|
|
268
|
+
};
|
|
269
|
+
export const parseOrganisationVerification = (s) => {
|
|
270
|
+
const organisationVerificationRegex = new RegExp(''
|
|
271
|
+
+ /^\n\tType: Organisation verification\n/.source
|
|
272
|
+
+ /\tDescription: We verified the following information about an organisation.\n/.source
|
|
273
|
+
+ /\tName: (?<name>[^\n]+?)\n/.source
|
|
274
|
+
+ /(?:\tEnglish name: (?<englishName>[^\n]+?)\n)?/.source
|
|
275
|
+
+ /\tCountry: (?<country>[^\n]+?)\n/.source
|
|
276
|
+
+ /\tLegal (?:form|entity): (?<legalForm>[^\n]+?)\n/.source
|
|
277
|
+
+ /(?:\tOwner of the domain: (?<domain>[^\n]+?)\n)?/.source
|
|
278
|
+
+ /(?:\tForeign domain used for publishing statements: (?<foreignDomain>[^\n]+?)\n)?/.source
|
|
279
|
+
+ /(?:\tDepartment using the domain: (?<department>[^\n]+?)\n)?/.source
|
|
280
|
+
+ /(?:\tProvince or state: (?<province>[^\n]+?)\n)?/.source
|
|
281
|
+
+ /(?:\tBusiness register number: (?<serialNumber>[^\n]+?)\n)?/.source
|
|
282
|
+
+ /(?:\tCity: (?<city>[^\n]+?)\n)?/.source
|
|
283
|
+
+ /(?:\tLatitude: (?<latitude>[^\n]+?)\n)?/.source
|
|
284
|
+
+ /(?:\tLongitude: (?<longitude>[^\n]+?)\n)?/.source
|
|
285
|
+
+ /(?:\tPopulation: (?<population>[^\n]+?)\n)?/.source
|
|
286
|
+
+ /(?:\tLogo: (?<pictureHash>[^\n]+?)\n)?/.source
|
|
287
|
+
+ /(?:\tEmployee count: (?<employeeCount>[01,+-]+?)\n)?/.source
|
|
288
|
+
+ /(?:\tReliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source
|
|
289
|
+
+ /(?:\tConfidence: (?<confidence>[0-9.]+?)\n)?/.source
|
|
290
|
+
+ /$/.source);
|
|
291
|
+
const m = s.match(organisationVerificationRegex);
|
|
292
|
+
if (!m)
|
|
293
|
+
throw new Error("Invalid organisation verification format: " + s);
|
|
294
|
+
return {
|
|
295
|
+
name: m[1],
|
|
296
|
+
englishName: m[2],
|
|
297
|
+
country: m[3],
|
|
298
|
+
legalForm: m[4],
|
|
299
|
+
domain: m[5],
|
|
300
|
+
foreignDomain: m[6],
|
|
301
|
+
department: m[7],
|
|
302
|
+
province: m[8],
|
|
303
|
+
serialNumber: m[9],
|
|
304
|
+
city: m[10],
|
|
305
|
+
latitude: m[11] ? parseFloat(m[11]) : undefined,
|
|
306
|
+
longitude: m[12] ? parseFloat(m[12]) : undefined,
|
|
307
|
+
population: m[13],
|
|
308
|
+
pictureHash: m[14],
|
|
309
|
+
employeeCount: m[15],
|
|
310
|
+
reliabilityPolicy: m[16],
|
|
311
|
+
confidence: m[17] ? parseFloat(m[17]) : undefined,
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
export const buildPersonVerificationContent = ({ name, countryOfBirth, cityOfBirth, ownDomain, foreignDomain, dateOfBirth, jobTitle, employer, verificationMethod, confidence, picture, reliabilityPolicy }) => {
|
|
315
|
+
if (!name || !countryOfBirth || !cityOfBirth || !dateOfBirth || (!ownDomain && !foreignDomain)) {
|
|
316
|
+
console.log("Missing required fields: ", { name, countryOfBirth, cityOfBirth, dateOfBirth, ownDomain, foreignDomain });
|
|
317
|
+
return "";
|
|
318
|
+
}
|
|
319
|
+
const [day, month, year] = dateOfBirth.toUTCString().split(' ').filter((i, j) => [1, 2, 3].includes(j));
|
|
320
|
+
let content = "\n" +
|
|
321
|
+
"\t" + "Type: Person verification" + "\n" +
|
|
322
|
+
"\t" + "Description: We verified the following information about a person." + "\n" +
|
|
323
|
+
"\t" + "Name: " + name + "\n" +
|
|
324
|
+
"\t" + "Date of birth: " + [day.replace(/$0/, ''), month, year].join(' ') + "\n" +
|
|
325
|
+
"\t" + "City of birth: " + cityOfBirth + "\n" +
|
|
326
|
+
"\t" + "Country of birth: " + countryOfBirth + "\n" +
|
|
327
|
+
(jobTitle ? "\t" + "Job title: " + jobTitle + "\n" : "") +
|
|
328
|
+
(employer ? "\t" + "Employer: " + employer + "\n" : "") +
|
|
329
|
+
(ownDomain ? "\t" + "Owner of the domain: " + ownDomain + "\n" : "") +
|
|
330
|
+
(foreignDomain ? "\t" + "Foreign domain used for publishing statements: " + foreignDomain + "\n" : "") +
|
|
331
|
+
(picture ? "\t" + "Picture: " + picture + "\n" : "") +
|
|
332
|
+
(verificationMethod ? "\t" + "Verification method: " + verificationMethod + "\n" : "") +
|
|
333
|
+
(confidence ? "\t" + "Confidence: " + confidence + "\n" : "") +
|
|
334
|
+
(reliabilityPolicy ? "\t" + "Reliability policy: " + reliabilityPolicy + "\n" : "") +
|
|
335
|
+
"";
|
|
336
|
+
return content;
|
|
337
|
+
};
|
|
338
|
+
export const parsePersonVerification = (s) => {
|
|
339
|
+
const domainVerificationRegex = new RegExp(''
|
|
340
|
+
+ /^\n\tType: Person verification\n/.source
|
|
341
|
+
+ /\tDescription: We verified the following information about a person.\n/.source
|
|
342
|
+
+ /\tName: (?<name>[^\n]+?)\n/.source
|
|
343
|
+
+ /\tDate of birth: (?<dateOfBirth>[^\n]+?)\n/.source
|
|
344
|
+
+ /\tCity of birth: (?<cityOfBirth>[^\n]+?)\n/.source
|
|
345
|
+
+ /\tCountry of birth: (?<countryOfBirth>[^\n]+?)\n/.source
|
|
346
|
+
+ /(?:\tJob title: (?<jobTitle>[^\n]+?)\n)?/.source
|
|
347
|
+
+ /(?:\tEmployer: (?<employer>[^\n]+?)\n)?/.source
|
|
348
|
+
+ /(?:\tOwner of the domain: (?<domain>[^\n]+?)\n)?/.source
|
|
349
|
+
+ /(?:\tForeign domain used for publishing statements: (?<foreignDomain>[^\n]+?)\n)?/.source
|
|
350
|
+
+ /(?:\tPicture: (?<picture>[^\n]+?)\n)?/.source
|
|
351
|
+
+ /(?:\tVerification method: (?<verificationMethod>[^\n]+?)\n)?/.source
|
|
352
|
+
+ /(?:\tConfidence: (?<confidence>[^\n]+?)\n)?/.source
|
|
353
|
+
+ /(?:\tReliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source
|
|
354
|
+
+ /$/.source);
|
|
355
|
+
const m = s.match(domainVerificationRegex);
|
|
356
|
+
if (!m)
|
|
357
|
+
throw new Error("Invalid person verification format: " + s);
|
|
358
|
+
if (m[2] && !m[2].match(birthDateFormat))
|
|
359
|
+
throw new Error("Invalid birth date format: " + m[2]);
|
|
360
|
+
let { d, month, y } = m[2].match(birthDateFormat)?.groups || {};
|
|
361
|
+
if (!d || !month || !y)
|
|
362
|
+
throw new Error("Invalid birth date format: " + m[2]);
|
|
363
|
+
return {
|
|
364
|
+
name: m[1],
|
|
365
|
+
dateOfBirth: new Date(Date.UTC(parseInt(y), monthIndex(month), parseInt(d))),
|
|
366
|
+
cityOfBirth: m[3],
|
|
367
|
+
countryOfBirth: m[4],
|
|
368
|
+
jobTitle: m[5],
|
|
369
|
+
employer: m[6],
|
|
370
|
+
ownDomain: m[7],
|
|
371
|
+
foreignDomain: m[8],
|
|
372
|
+
picture: m[9],
|
|
373
|
+
verificationMethod: m[10],
|
|
374
|
+
confidence: m[11] ? parseFloat(m[11]) : undefined,
|
|
375
|
+
reliabilityPolicy: m[12]
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
export const buildVoteContent = ({ pollHash, poll, vote }) => {
|
|
379
|
+
const content = "\n" +
|
|
380
|
+
"\t" + "Type: Vote" + "\n" +
|
|
381
|
+
"\t" + "Poll id: " + pollHash + "\n" +
|
|
382
|
+
"\t" + "Poll: " + poll + "\n" +
|
|
383
|
+
"\t" + "Option: " + vote + "\n" +
|
|
384
|
+
"";
|
|
385
|
+
return content;
|
|
386
|
+
};
|
|
387
|
+
export const parseVote = (s) => {
|
|
388
|
+
const voteRegex = new RegExp(''
|
|
389
|
+
+ /^\n\tType: Vote\n/.source
|
|
390
|
+
+ /\tPoll id: (?<pollHash>[^\n]+?)\n/.source
|
|
391
|
+
+ /\tPoll: (?<poll>[^\n]+?)\n/.source
|
|
392
|
+
+ /\tOption: (?<vote>[^\n]+?)\n/.source
|
|
393
|
+
+ /$/.source);
|
|
394
|
+
const m = s.match(voteRegex);
|
|
395
|
+
if (!m)
|
|
396
|
+
throw new Error("Invalid vote format: " + s);
|
|
397
|
+
return {
|
|
398
|
+
pollHash: m[1],
|
|
399
|
+
poll: m[2],
|
|
400
|
+
vote: m[3]
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
export const buildDisputeAuthenticityContent = ({ hash, confidence, reliabilityPolicy }) => {
|
|
404
|
+
const content = "\n" +
|
|
405
|
+
"\t" + "Type: Dispute statement authenticity" + "\n" +
|
|
406
|
+
"\t" + "Description: We think that the referenced statement is not authentic.\n" +
|
|
407
|
+
"\t" + "Hash of referenced statement: " + hash + "\n" +
|
|
408
|
+
(confidence ? "\t" + "Confidence: " + confidence + "\n" : "") +
|
|
409
|
+
(reliabilityPolicy ? "\t" + "Reliability policy: " + reliabilityPolicy + "\n" : "") +
|
|
410
|
+
"";
|
|
411
|
+
return content;
|
|
412
|
+
};
|
|
413
|
+
export const parseDisputeAuthenticity = (s) => {
|
|
414
|
+
const disputeRegex = new RegExp(''
|
|
415
|
+
+ /^\n\tType: Dispute statement authenticity\n/.source
|
|
416
|
+
+ /\tDescription: We think that the referenced statement is not authentic.\n/.source
|
|
417
|
+
+ /\tHash of referenced statement: (?<hash>[^\n]+?)\n/.source
|
|
418
|
+
+ /(?:\tConfidence: (?<confidence>[^\n]*?)\n)?/.source
|
|
419
|
+
+ /(?:\tReliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source
|
|
420
|
+
+ /$/.source);
|
|
421
|
+
const m = s.match(disputeRegex);
|
|
422
|
+
if (!m)
|
|
423
|
+
throw new Error("Invalid dispute authenticity format: " + s);
|
|
424
|
+
return {
|
|
425
|
+
hash: m[1],
|
|
426
|
+
confidence: m[2] ? parseFloat(m[2]) : undefined,
|
|
427
|
+
reliabilityPolicy: m[3]
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
export const buildDisputeContentContent = ({ hash, confidence, reliabilityPolicy }) => {
|
|
431
|
+
const content = "\n" +
|
|
432
|
+
"\t" + "Type: Dispute statement content" + "\n" +
|
|
433
|
+
"\t" + "Description: We think that the content of the referenced statement is false.\n" +
|
|
434
|
+
"\t" + "Hash of referenced statement: " + hash + "\n" +
|
|
435
|
+
(confidence ? "\t" + "Confidence: " + confidence + "\n" : "") +
|
|
436
|
+
(reliabilityPolicy ? "\t" + "Reliability policy: " + reliabilityPolicy + "\n" : "") +
|
|
437
|
+
"";
|
|
438
|
+
return content;
|
|
439
|
+
};
|
|
440
|
+
export const parseDisputeContent = (s) => {
|
|
441
|
+
const disputeRegex = new RegExp(''
|
|
442
|
+
+ /^\n\tType: Dispute statement content\n/.source
|
|
443
|
+
+ /\tDescription: We think that the content of the referenced statement is false.\n/.source
|
|
444
|
+
+ /\tHash of referenced statement: (?<hash>[^\n]+?)\n/.source
|
|
445
|
+
+ /(?:\tConfidence: (?<confidence>[^\n]*?)\n)?/.source
|
|
446
|
+
+ /(?:\tReliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source
|
|
447
|
+
+ /$/.source);
|
|
448
|
+
const m = s.match(disputeRegex);
|
|
449
|
+
if (!m)
|
|
450
|
+
throw new Error("Invalid dispute content format: " + s);
|
|
451
|
+
return {
|
|
452
|
+
hash: m[1],
|
|
453
|
+
confidence: m[2] ? parseFloat(m[2]) : undefined,
|
|
454
|
+
reliabilityPolicy: m[3]
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
export const buildResponseContent = ({ hash, response }) => {
|
|
458
|
+
const content = "\n" +
|
|
459
|
+
"\t" + "Type: Response" + "\n" +
|
|
460
|
+
"\t" + "Hash of referenced statement: " + hash + "\n" +
|
|
461
|
+
"\t" + "Response: " + response + "\n" +
|
|
462
|
+
"";
|
|
463
|
+
return content;
|
|
464
|
+
};
|
|
465
|
+
export const parseResponseContent = (s) => {
|
|
466
|
+
const disputeRegex = new RegExp(''
|
|
467
|
+
+ /^\n\tType: Response\n/.source
|
|
468
|
+
+ /\tHash of referenced statement: (?<hash>[^\n]+?)\n/.source
|
|
469
|
+
+ /\tResponse: (?<response>[^\n]*?)\n/.source
|
|
470
|
+
+ /$/.source);
|
|
471
|
+
const m = s.match(disputeRegex);
|
|
472
|
+
if (!m)
|
|
473
|
+
throw new Error("Invalid response content format: " + s);
|
|
474
|
+
return {
|
|
475
|
+
hash: m[1],
|
|
476
|
+
response: m[2]
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
export const buildPDFSigningContent = ({ hash }) => {
|
|
480
|
+
const content = "\n" +
|
|
481
|
+
"\t" + "Type: Sign PDF" + "\n" +
|
|
482
|
+
"\t" + "Description: We hereby digitally sign the referenced PDF file.\n" +
|
|
483
|
+
"\t" + "PDF file hash: " + hash + "\n" +
|
|
484
|
+
"";
|
|
485
|
+
return content;
|
|
486
|
+
};
|
|
487
|
+
export const parsePDFSigning = (s) => {
|
|
488
|
+
const signingRegex = new RegExp(''
|
|
489
|
+
+ /^\n\tType: Sign PDF\n/.source
|
|
490
|
+
+ /\tDescription: We hereby digitally sign the referenced PDF file.\n/.source
|
|
491
|
+
+ /\tPDF file hash: (?<hash>[^\n]+?)\n/.source
|
|
492
|
+
+ /$/.source);
|
|
493
|
+
const m = s.match(signingRegex);
|
|
494
|
+
if (!m)
|
|
495
|
+
throw new Error("Invalid PDF signing format: " + s);
|
|
496
|
+
return {
|
|
497
|
+
hash: m[1]
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
export const buildRating = ({ subjectName, subjectType, subjectReference, documentFileHash, rating, quality, comment }) => {
|
|
501
|
+
if (![1, 2, 3, 4, 5].includes(rating))
|
|
502
|
+
throw new Error("Invalid rating: " + rating);
|
|
503
|
+
const content = "\n" +
|
|
504
|
+
"\t" + "Type: Rating" + "\n" +
|
|
505
|
+
(subjectType ? "\t" + "Subject type: " + subjectType + "\n" : "") +
|
|
506
|
+
"\t" + "Subject name: " + subjectName + "\n" +
|
|
507
|
+
(subjectReference ? "\t" + "URL that identifies the subject: " + subjectReference + "\n" : "") +
|
|
508
|
+
(documentFileHash ? "\t" + "Document file hash: " + documentFileHash + "\n" : "") +
|
|
509
|
+
(quality ? "\t" + "Rated quality: " + quality + "\n" : "") +
|
|
510
|
+
"\t" + "Our rating: " + rating + "/5 Stars\n" +
|
|
511
|
+
(comment ? "\t" + "Comment: " + comment + "\n" : "") +
|
|
512
|
+
"";
|
|
513
|
+
return content;
|
|
514
|
+
};
|
|
515
|
+
export const parseRating = (s) => {
|
|
516
|
+
const ratingRegex = new RegExp(''
|
|
517
|
+
+ /^\n\tType: Rating\n/.source
|
|
518
|
+
+ /(?:\tSubject type: (?<subjectType>[^\n]*?)\n)?/.source
|
|
519
|
+
+ /\tSubject name: (?<subjectName>[^\n]*?)\n/.source
|
|
520
|
+
+ /(?:\tURL that identifies the subject: (?<subjectReference>[^\n]*?)\n)?/.source
|
|
521
|
+
+ /(?:\tDocument file hash: (?<documentFileHash>[^\n]*?)\n)?/.source
|
|
522
|
+
+ /(?:\tRated quality: (?<quality>[^\n]*?)\n)?/.source
|
|
523
|
+
+ /\tOur rating: (?<rating>[1-5])\/5 Stars\n/.source
|
|
524
|
+
+ /(?:\tComment: (?<comment>[\s\S]+?)\n)?/.source
|
|
525
|
+
+ /$/.source);
|
|
526
|
+
const m = s.match(ratingRegex);
|
|
527
|
+
if (!m)
|
|
528
|
+
throw new Error("Invalid rating format: " + s);
|
|
529
|
+
const rating = parseInt(m[6]);
|
|
530
|
+
if (![1, 2, 3, 4, 5].includes(rating))
|
|
531
|
+
throw new Error("Invalid rating: " + m[6]);
|
|
532
|
+
if (m[1] && !['Organisation', 'Policy proposal', 'Regulation',
|
|
533
|
+
'Treaty draft', 'Product', 'Research publication'].includes(m[1]))
|
|
534
|
+
throw new Error("Invalid subject type: " + m[1]);
|
|
535
|
+
if (!m[2])
|
|
536
|
+
throw new Error("Missing subject name");
|
|
537
|
+
return {
|
|
538
|
+
subjectType: m[1],
|
|
539
|
+
subjectName: m[2],
|
|
540
|
+
subjectReference: m[3],
|
|
541
|
+
documentFileHash: m[4],
|
|
542
|
+
quality: m[5],
|
|
543
|
+
rating,
|
|
544
|
+
comment: m[7]
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
export const buildBounty = ({ motivation, bounty, reward, judge, judgePay }) => {
|
|
548
|
+
const content = "\n" +
|
|
549
|
+
"\t" + "Type: Bounty" + "\n" +
|
|
550
|
+
(motivation ? "\t" + "In order to: " + motivation + "\n" : "") +
|
|
551
|
+
"\t" + "We will reward any entity that: " + bounty + "\n" +
|
|
552
|
+
"\t" + "The reward is: " + reward + "\n" +
|
|
553
|
+
"\t" + "In case of dispute, bounty claims are judged by: " + judge + "\n" +
|
|
554
|
+
(judgePay ? "\t" + "The judge will be paid per investigated case with a maxium of: " + judgePay + "\n" : "") +
|
|
555
|
+
"";
|
|
556
|
+
return content;
|
|
557
|
+
};
|
|
558
|
+
export const parseBounty = (s) => {
|
|
559
|
+
const bountyRegex = new RegExp(''
|
|
560
|
+
+ /^\n\tType: Bounty\n/.source
|
|
561
|
+
+ /(?:\tIn order to: (?<motivation>[^\n]*?)\n)?/.source
|
|
562
|
+
+ /\tWe will reward any entity that: (?<bounty>[^\n]*?)\n/.source
|
|
563
|
+
+ /\tThe reward is: (?<reward>[^\n]*?)\n/.source
|
|
564
|
+
+ /\tIn case of dispute, bounty claims are judged by: (?<judge>[^\n]*?)\n/.source
|
|
565
|
+
+ /(?:\tThe judge will be paid per investigated case with a maxium of: (?<judgePay>[^\n]*?)\n)?/.source
|
|
566
|
+
+ /$/.source);
|
|
567
|
+
const m = s.match(bountyRegex);
|
|
568
|
+
if (!m)
|
|
569
|
+
throw new Error("Invalid bounty format: " + s);
|
|
570
|
+
return {
|
|
571
|
+
motivation: m[1],
|
|
572
|
+
bounty: m[2],
|
|
573
|
+
reward: m[3],
|
|
574
|
+
judge: m[4],
|
|
575
|
+
judgePay: m[5]
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
export const buildObservation = ({ approach, confidence, reliabilityPolicy, subject, subjectReference, observationReference, property, value }) => {
|
|
579
|
+
const content = "\n" +
|
|
580
|
+
"\t" + "Type: Observation" + "\n" +
|
|
581
|
+
(approach ? "\t" + "Approach: " + approach + "\n" : "") +
|
|
582
|
+
(confidence ? "\t" + "Confidence: " + confidence + "\n" : "") +
|
|
583
|
+
(reliabilityPolicy ? "\t" + "Reliability policy: " + reliabilityPolicy + "\n" : "") +
|
|
584
|
+
"\t" + "Subject: " + subject + "\n" +
|
|
585
|
+
(subjectReference ? "\t" + "Subject identity reference: " + subjectReference + "\n" : "") +
|
|
586
|
+
(observationReference ? "\t" + "Observation reference: " + observationReference + "\n" : "") +
|
|
587
|
+
"\t" + "Observed property: " + property + "\n" +
|
|
588
|
+
(value ? "\t" + "Observed value: " + value + "\n" : "") +
|
|
589
|
+
"";
|
|
590
|
+
return content;
|
|
591
|
+
};
|
|
592
|
+
export const parseObservation = (s) => {
|
|
593
|
+
const observationRegex = new RegExp(''
|
|
594
|
+
+ /^\n\tType: Observation\n/.source
|
|
595
|
+
+ /(?:\tApproach: (?<approach>[^\n]*?)\n)?/.source
|
|
596
|
+
+ /(?:\tConfidence: (?<confidence>[^\n]*?)\n)?/.source
|
|
597
|
+
+ /(?:\tReliability policy: (?<reliabilityPolicy>[^\n]+?)\n)?/.source
|
|
598
|
+
+ /\tSubject: (?<subject>[^\n]*?)\n/.source
|
|
599
|
+
+ /(?:\tSubject identity reference: (?<subjectReference>[^\n]*?)\n)?/.source
|
|
600
|
+
+ /(?:\tObservation reference: (?<observationReference>[^\n]*?)\n)?/.source
|
|
601
|
+
+ /\tObserved property: (?<property>[^\n]*?)\n/.source
|
|
602
|
+
+ /(?:\tObserved value: (?<value>[\s\S]+?)\n)?/.source
|
|
603
|
+
+ /$/.source);
|
|
604
|
+
const m = s.match(observationRegex);
|
|
605
|
+
if (!m)
|
|
606
|
+
throw new Error("Invalid observation format: " + s);
|
|
607
|
+
return {
|
|
608
|
+
approach: m[1],
|
|
609
|
+
confidence: m[2] ? parseFloat(m[2]) : undefined,
|
|
610
|
+
reliabilityPolicy: m[3],
|
|
611
|
+
subject: m[4],
|
|
612
|
+
subjectReference: m[5],
|
|
613
|
+
observationReference: m[6],
|
|
614
|
+
property: m[7],
|
|
615
|
+
value: m[8]
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
export const buildBoycott = ({ description, subject, subjectReference }) => {
|
|
619
|
+
const content = "\n" +
|
|
620
|
+
"\t" + "Type: Boycott" + "\n" +
|
|
621
|
+
(description ? "\t" + "Description: " + description + "\n" : "") +
|
|
622
|
+
"\t" + "Subject: " + subject + "\n" +
|
|
623
|
+
(subjectReference ? "\t" + "Subject identity reference: " + subjectReference + "\n" : "") +
|
|
624
|
+
"";
|
|
625
|
+
return content;
|
|
626
|
+
};
|
|
627
|
+
export const parseBoycott = (s) => {
|
|
628
|
+
const observationRegex = new RegExp(''
|
|
629
|
+
+ /^\n\tType: Boycott\n/.source
|
|
630
|
+
+ /(?:\tDescription: (?<description>[^\n]*?)\n)?/.source
|
|
631
|
+
+ /\tSubject: (?<subject>[^\n]*?)\n/.source
|
|
632
|
+
+ /(?:\tSubject identity reference: (?<subjectReference>[^\n]*?)\n)?/.source
|
|
633
|
+
+ /$/.source);
|
|
634
|
+
const m = s.match(observationRegex);
|
|
635
|
+
if (!m)
|
|
636
|
+
throw new Error("Invalid observation format: " + s);
|
|
637
|
+
return {
|
|
638
|
+
description: m[1],
|
|
639
|
+
subject: m[2],
|
|
640
|
+
subjectReference: m[3],
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
//# sourceMappingURL=index.js.map
|