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
package/src/types.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
export type StatementTypeValue =
|
|
2
|
+
| 'statement'
|
|
3
|
+
| 'quotation'
|
|
4
|
+
| 'organisation_verification'
|
|
5
|
+
| 'person_verification'
|
|
6
|
+
| 'poll'
|
|
7
|
+
| 'vote'
|
|
8
|
+
| 'response'
|
|
9
|
+
| 'dispute_statement_content'
|
|
10
|
+
| 'dispute_statement_authenticity'
|
|
11
|
+
| 'boycott'
|
|
12
|
+
| 'observation'
|
|
13
|
+
| 'rating'
|
|
14
|
+
| 'sign_pdf'
|
|
15
|
+
| 'bounty'
|
|
16
|
+
|
|
17
|
+
export type Statement = {
|
|
18
|
+
domain: string
|
|
19
|
+
author: string
|
|
20
|
+
time: Date
|
|
21
|
+
tags?: string[]
|
|
22
|
+
content: string
|
|
23
|
+
representative?: string
|
|
24
|
+
supersededStatement?: string
|
|
25
|
+
formatVersion?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type Quotation = {
|
|
29
|
+
originalAuthor: string
|
|
30
|
+
authorVerification: string
|
|
31
|
+
originalTime?: string
|
|
32
|
+
source?: string
|
|
33
|
+
quotation?: string
|
|
34
|
+
paraphrasedStatement?: string
|
|
35
|
+
picture?: string
|
|
36
|
+
confidence?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Poll = {
|
|
40
|
+
country: string | undefined
|
|
41
|
+
city: string | undefined
|
|
42
|
+
legalEntity: string | undefined
|
|
43
|
+
domainScope: string[] | undefined
|
|
44
|
+
judges?: string
|
|
45
|
+
deadline: Date | undefined
|
|
46
|
+
poll: string
|
|
47
|
+
scopeDescription?: string
|
|
48
|
+
scopeQueryLink?: string
|
|
49
|
+
options: string[]
|
|
50
|
+
allowArbitraryVote?: boolean
|
|
51
|
+
requiredProperty?: string
|
|
52
|
+
requiredPropertyValue?: string
|
|
53
|
+
requiredPropertyObserver?: string
|
|
54
|
+
requiredMinConfidence?: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type OrganisationVerification = {
|
|
58
|
+
name: string
|
|
59
|
+
englishName?: string
|
|
60
|
+
country: string
|
|
61
|
+
city: string
|
|
62
|
+
province: string
|
|
63
|
+
legalForm: string
|
|
64
|
+
department?: string
|
|
65
|
+
domain: string
|
|
66
|
+
foreignDomain: string
|
|
67
|
+
serialNumber: string
|
|
68
|
+
confidence?: number
|
|
69
|
+
reliabilityPolicy?: string
|
|
70
|
+
employeeCount?: string
|
|
71
|
+
pictureHash?: string
|
|
72
|
+
latitude?: number
|
|
73
|
+
longitude?: number
|
|
74
|
+
population?: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type withOwnDomain = {
|
|
78
|
+
ownDomain: string
|
|
79
|
+
foreignDomain?: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type withForeignDomain = {
|
|
83
|
+
foreignDomain: string
|
|
84
|
+
ownDomain?: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type PersonVerification = {
|
|
88
|
+
name: string
|
|
89
|
+
countryOfBirth: string
|
|
90
|
+
cityOfBirth: string
|
|
91
|
+
dateOfBirth: Date
|
|
92
|
+
jobTitle?: string
|
|
93
|
+
employer?: string
|
|
94
|
+
verificationMethod?: string
|
|
95
|
+
confidence?: number
|
|
96
|
+
picture?: string
|
|
97
|
+
reliabilityPolicy?: string
|
|
98
|
+
} & (withOwnDomain | withForeignDomain)
|
|
99
|
+
|
|
100
|
+
export type Vote = {
|
|
101
|
+
pollHash: string
|
|
102
|
+
poll: string
|
|
103
|
+
vote: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type DisputeAuthenticity = {
|
|
107
|
+
hash: string
|
|
108
|
+
confidence?: number
|
|
109
|
+
reliabilityPolicy?: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type DisputeContent = {
|
|
113
|
+
hash: string
|
|
114
|
+
confidence?: number
|
|
115
|
+
reliabilityPolicy?: string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type ResponseContent = {
|
|
119
|
+
hash: string
|
|
120
|
+
response: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type PDFSigning = {
|
|
124
|
+
hash: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type RatingSubjectTypeValue =
|
|
128
|
+
| 'Organisation'
|
|
129
|
+
| 'Policy proposal'
|
|
130
|
+
| 'Treaty draft'
|
|
131
|
+
| 'Research publication'
|
|
132
|
+
| 'Regulation'
|
|
133
|
+
| 'Product'
|
|
134
|
+
|
|
135
|
+
export type Rating = {
|
|
136
|
+
subjectType?: RatingSubjectTypeValue
|
|
137
|
+
subjectName: string
|
|
138
|
+
subjectReference?: string
|
|
139
|
+
documentFileHash?: string
|
|
140
|
+
rating: number
|
|
141
|
+
quality?: string
|
|
142
|
+
comment?: string
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type Bounty = {
|
|
146
|
+
motivation?: string
|
|
147
|
+
bounty: string
|
|
148
|
+
reward: string
|
|
149
|
+
judge: string
|
|
150
|
+
judgePay?: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type Observation = {
|
|
154
|
+
description?: string
|
|
155
|
+
approach?: string
|
|
156
|
+
confidence?: number
|
|
157
|
+
reliabilityPolicy?: string
|
|
158
|
+
subject: string
|
|
159
|
+
subjectReference?: string
|
|
160
|
+
observationReference?: string
|
|
161
|
+
property: string
|
|
162
|
+
value?: string
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type PollV3 = {
|
|
166
|
+
country: string | undefined
|
|
167
|
+
city: string | undefined
|
|
168
|
+
legalEntity: string | undefined
|
|
169
|
+
domainScope: string[] | undefined
|
|
170
|
+
judges?: string
|
|
171
|
+
deadline: Date
|
|
172
|
+
poll: string
|
|
173
|
+
scopeDescription?: string
|
|
174
|
+
scopeQueryLink?: string
|
|
175
|
+
scopeProperty?: string
|
|
176
|
+
propertyScopeObserver?: string
|
|
177
|
+
pollType?: string
|
|
178
|
+
options: string[]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type Boycott = {
|
|
182
|
+
description?: string
|
|
183
|
+
reliabilityPolicy?: string
|
|
184
|
+
subject: string
|
|
185
|
+
subjectReference?: string
|
|
186
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { peopleCountBuckets } from './constants'
|
|
2
|
+
|
|
3
|
+
export const minPeopleCountToRange = (n: number): string | undefined => {
|
|
4
|
+
if (n >= 10000000) return peopleCountBuckets["10000000"]
|
|
5
|
+
if (n >= 1000000) return peopleCountBuckets["1000000"]
|
|
6
|
+
if (n >= 100000) return peopleCountBuckets["100000"]
|
|
7
|
+
if (n >= 10000) return peopleCountBuckets["10000"]
|
|
8
|
+
if (n >= 1000) return peopleCountBuckets["1000"]
|
|
9
|
+
if (n >= 100) return peopleCountBuckets["100"]
|
|
10
|
+
if (n >= 10) return peopleCountBuckets["10"]
|
|
11
|
+
if (n >= 0) return peopleCountBuckets["0"]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const monthIndex = (month: string): number =>
|
|
15
|
+
["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
|
|
16
|
+
.indexOf(month.toLowerCase().substr(0, 3))
|
|
17
|
+
|
|
18
|
+
export const birthDateFormat: RegExp = /(?<d>\d{1,2})\s(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?<y>\d{4})/
|
package/src/v3.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { UTCFormat } from './constants'
|
|
2
|
+
import { Poll } from './types'
|
|
3
|
+
|
|
4
|
+
export const parsePollV3 = (s: string, version?: string): Poll & { pollType: string } => {
|
|
5
|
+
const pollRegex = new RegExp(''
|
|
6
|
+
+ /^\n\tType: Poll\n/.source
|
|
7
|
+
+ /(?:\tPoll type: (?<pollType>[^\n]+?)\n)?/.source
|
|
8
|
+
+ /(?:\tWho can vote: (?<scopeDescription>[^\n]+?)\n)?/.source
|
|
9
|
+
+ /(?:\tLink to query defining who can vote: (?<scopeQueryLink>[^\n]+?)\n)?/.source
|
|
10
|
+
+ /(?:\tCountry scope: (?<country>[^\n]+?)\n)?/.source
|
|
11
|
+
+ /(?:\tCity scope: (?<city>[^\n]+?)\n)?/.source
|
|
12
|
+
+ /(?:\tLegal form scope: (?<legalEntity>[^\n]+?)\n)?/.source
|
|
13
|
+
+ /(?:\tDomain scope: (?<domainScope>[^\n]+?)\n)?/.source
|
|
14
|
+
+ /(?:\tThe decision is finalized when the following nodes agree: (?<judges>[^\n]+?)\n)?/.source
|
|
15
|
+
+ /(?:\tVoting deadline: (?<deadline>[^\n]+?)\n)?/.source
|
|
16
|
+
+ /\tPoll: (?<poll>[^\n]+?)\n/.source
|
|
17
|
+
+ /(?:\tOption 1: (?<option1>[^\n]+?)\n)?/.source
|
|
18
|
+
+ /(?:\tOption 2: (?<option2>[^\n]+?)\n)?/.source
|
|
19
|
+
+ /(?:\tOption 3: (?<option3>[^\n]+?)\n)?/.source
|
|
20
|
+
+ /(?:\tOption 4: (?<option4>[^\n]+?)\n)?/.source
|
|
21
|
+
+ /(?:\tOption 5: (?<option5>[^\n]+?)\n)?/.source
|
|
22
|
+
+ /$/.source)
|
|
23
|
+
const match = s.match(pollRegex)
|
|
24
|
+
if (!match) throw new Error("Invalid poll format: " + s)
|
|
25
|
+
|
|
26
|
+
const m = {
|
|
27
|
+
pollType: match[1],
|
|
28
|
+
scopeDescription: match[2],
|
|
29
|
+
scopeQueryLink: match[3],
|
|
30
|
+
country: match[4],
|
|
31
|
+
city: match[5],
|
|
32
|
+
legalEntity: match[6],
|
|
33
|
+
domainScope: match[7],
|
|
34
|
+
judges: match[8],
|
|
35
|
+
deadline: match[9],
|
|
36
|
+
poll: match[10],
|
|
37
|
+
option1: match[11],
|
|
38
|
+
option2: match[12],
|
|
39
|
+
option3: match[13],
|
|
40
|
+
option4: match[14],
|
|
41
|
+
option5: match[15]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const options = [m.option1, m.option2, m.option3, m.option4, m.option5].filter(o => o)
|
|
45
|
+
const domainScope = m.domainScope?.split(', ')
|
|
46
|
+
const deadlineStr = m.deadline
|
|
47
|
+
if (!deadlineStr.match(UTCFormat)) throw new Error("Invalid poll, deadline must be in UTC: " + deadlineStr)
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
pollType: m['pollType'],
|
|
51
|
+
country: m['country'],
|
|
52
|
+
scopeDescription: m['scopeDescription'],
|
|
53
|
+
scopeQueryLink: m['scopeQueryLink'],
|
|
54
|
+
city: m['city'],
|
|
55
|
+
legalEntity: m['legalEntity'],
|
|
56
|
+
domainScope: (domainScope && domainScope.length > 0) ? domainScope : undefined,
|
|
57
|
+
judges: m['judges'],
|
|
58
|
+
deadline: new Date(deadlineStr),
|
|
59
|
+
poll: m['poll'],
|
|
60
|
+
options
|
|
61
|
+
}
|
|
62
|
+
}
|