@condorcet.vote/cef-writer 1.2.0
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/LICENSE +21 -0
- package/README.md +419 -0
- package/dist/Cef.d.ts +188 -0
- package/dist/Cef.d.ts.map +1 -0
- package/dist/Cef.js +291 -0
- package/dist/CefFormat.d.ts +57 -0
- package/dist/CefFormat.d.ts.map +1 -0
- package/dist/CefFormat.js +133 -0
- package/dist/CommentLine.d.ts +18 -0
- package/dist/CommentLine.d.ts.map +1 -0
- package/dist/CommentLine.js +27 -0
- package/dist/Exception/CefFormatException.d.ts +16 -0
- package/dist/Exception/CefFormatException.d.ts.map +1 -0
- package/dist/Exception/CefFormatException.js +19 -0
- package/dist/Exception/CefWriteException.d.ts +12 -0
- package/dist/Exception/CefWriteException.d.ts.map +1 -0
- package/dist/Exception/CefWriteException.js +13 -0
- package/dist/Exception/DuplicateCandidateException.d.ts +9 -0
- package/dist/Exception/DuplicateCandidateException.d.ts.map +1 -0
- package/dist/Exception/DuplicateCandidateException.js +8 -0
- package/dist/Exception/InvalidUtf8Exception.d.ts +13 -0
- package/dist/Exception/InvalidUtf8Exception.d.ts.map +1 -0
- package/dist/Exception/InvalidUtf8Exception.js +12 -0
- package/dist/Exception/InvalidValueException.d.ts +15 -0
- package/dist/Exception/InvalidValueException.d.ts.map +1 -0
- package/dist/Exception/InvalidValueException.js +14 -0
- package/dist/Exception/InvalidWriterStateException.d.ts +14 -0
- package/dist/Exception/InvalidWriterStateException.d.ts.map +1 -0
- package/dist/Exception/InvalidWriterStateException.js +13 -0
- package/dist/Exception/ReservedCharacterException.d.ts +12 -0
- package/dist/Exception/ReservedCharacterException.d.ts.map +1 -0
- package/dist/Exception/ReservedCharacterException.js +11 -0
- package/dist/Exception/index.d.ts +8 -0
- package/dist/Exception/index.d.ts.map +1 -0
- package/dist/Exception/index.js +7 -0
- package/dist/FileWriteTarget.d.ts +27 -0
- package/dist/FileWriteTarget.d.ts.map +1 -0
- package/dist/FileWriteTarget.js +35 -0
- package/dist/Parameter/CandidatesParameter.d.ts +20 -0
- package/dist/Parameter/CandidatesParameter.d.ts.map +1 -0
- package/dist/Parameter/CandidatesParameter.js +39 -0
- package/dist/Parameter/CustomParameter.d.ts +19 -0
- package/dist/Parameter/CustomParameter.d.ts.map +1 -0
- package/dist/Parameter/CustomParameter.js +35 -0
- package/dist/Parameter/ImplicitRankingParameter.d.ts +11 -0
- package/dist/Parameter/ImplicitRankingParameter.d.ts.map +1 -0
- package/dist/Parameter/ImplicitRankingParameter.js +16 -0
- package/dist/Parameter/NumberOfSeatsParameter.d.ts +14 -0
- package/dist/Parameter/NumberOfSeatsParameter.d.ts.map +1 -0
- package/dist/Parameter/NumberOfSeatsParameter.js +23 -0
- package/dist/Parameter/ParameterInterface.d.ts +20 -0
- package/dist/Parameter/ParameterInterface.d.ts.map +1 -0
- package/dist/Parameter/ParameterInterface.js +1 -0
- package/dist/Parameter/StandardParameter.d.ts +14 -0
- package/dist/Parameter/StandardParameter.d.ts.map +1 -0
- package/dist/Parameter/StandardParameter.js +14 -0
- package/dist/Parameter/VotingMethodsParameter.d.ts +16 -0
- package/dist/Parameter/VotingMethodsParameter.d.ts.map +1 -0
- package/dist/Parameter/VotingMethodsParameter.js +29 -0
- package/dist/Parameter/WeightAllowedParameter.d.ts +11 -0
- package/dist/Parameter/WeightAllowedParameter.d.ts.map +1 -0
- package/dist/Parameter/WeightAllowedParameter.js +16 -0
- package/dist/Parameter/index.d.ts +9 -0
- package/dist/Parameter/index.d.ts.map +1 -0
- package/dist/Parameter/index.js +7 -0
- package/dist/Ranking.d.ts +91 -0
- package/dist/Ranking.d.ts.map +1 -0
- package/dist/Ranking.js +162 -0
- package/dist/VoteLine.d.ts +156 -0
- package/dist/VoteLine.d.ts.map +1 -0
- package/dist/VoteLine.js +289 -0
- package/dist/index.browser.d.ts +17 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.node.d.ts +19 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +25 -0
- package/package.json +79 -0
- package/src/Cef.ts +405 -0
- package/src/CefFormat.ts +152 -0
- package/src/CommentLine.ts +32 -0
- package/src/Exception/CefFormatException.ts +19 -0
- package/src/Exception/CefWriteException.ts +13 -0
- package/src/Exception/DuplicateCandidateException.ts +8 -0
- package/src/Exception/InvalidUtf8Exception.ts +12 -0
- package/src/Exception/InvalidValueException.ts +14 -0
- package/src/Exception/InvalidWriterStateException.ts +13 -0
- package/src/Exception/ReservedCharacterException.ts +11 -0
- package/src/Exception/index.ts +7 -0
- package/src/FileWriteTarget.ts +42 -0
- package/src/Parameter/CandidatesParameter.ts +49 -0
- package/src/Parameter/CustomParameter.ts +45 -0
- package/src/Parameter/ImplicitRankingParameter.ts +17 -0
- package/src/Parameter/NumberOfSeatsParameter.ts +25 -0
- package/src/Parameter/ParameterInterface.ts +20 -0
- package/src/Parameter/StandardParameter.ts +13 -0
- package/src/Parameter/VotingMethodsParameter.ts +36 -0
- package/src/Parameter/WeightAllowedParameter.ts +17 -0
- package/src/Parameter/index.ts +8 -0
- package/src/Ranking.ts +197 -0
- package/src/VoteLine.ts +398 -0
- package/src/index.browser.ts +36 -0
- package/src/index.node.ts +47 -0
- package/src/index.ts +8 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a value is structurally impossible at the CEF level — regardless
|
|
4
|
+
* of which reserved/UTF-8 rule it would otherwise hit.
|
|
5
|
+
*
|
|
6
|
+
* Typical triggers:
|
|
7
|
+
* - empty string where one is required (candidate name, tag, parameter name);
|
|
8
|
+
* - embedded line break or null byte;
|
|
9
|
+
* - non-positive `weight` or `quantifier`;
|
|
10
|
+
* - empty list when one or more entries are required (candidates, methods);
|
|
11
|
+
* - empty rank inside a ranking.
|
|
12
|
+
*/
|
|
13
|
+
export declare class InvalidValueException extends CefFormatException {
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=InvalidValueException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidValueException.d.ts","sourceRoot":"","sources":["../../src/Exception/InvalidValueException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,qBAAa,qBAAsB,SAAQ,kBAAkB;CAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a value is structurally impossible at the CEF level — regardless
|
|
4
|
+
* of which reserved/UTF-8 rule it would otherwise hit.
|
|
5
|
+
*
|
|
6
|
+
* Typical triggers:
|
|
7
|
+
* - empty string where one is required (candidate name, tag, parameter name);
|
|
8
|
+
* - embedded line break or null byte;
|
|
9
|
+
* - non-positive `weight` or `quantifier`;
|
|
10
|
+
* - empty list when one or more entries are required (candidates, methods);
|
|
11
|
+
* - empty rank inside a ranking.
|
|
12
|
+
*/
|
|
13
|
+
export class InvalidValueException extends CefFormatException {
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the streaming writer is asked to perform an operation that does
|
|
4
|
+
* not fit its current internal state.
|
|
5
|
+
*
|
|
6
|
+
* Typical triggers:
|
|
7
|
+
* - adding a parameter after the first vote has been emitted;
|
|
8
|
+
* - constructing a `Cef` with neither a file nor a string target, or with
|
|
9
|
+
* both at once;
|
|
10
|
+
* - parsing a vote-line string that ends up without a ranking.
|
|
11
|
+
*/
|
|
12
|
+
export declare class InvalidWriterStateException extends CefFormatException {
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=InvalidWriterStateException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidWriterStateException.d.ts","sourceRoot":"","sources":["../../src/Exception/InvalidWriterStateException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;GASG;AACH,qBAAa,2BAA4B,SAAQ,kBAAkB;CAAG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the streaming writer is asked to perform an operation that does
|
|
4
|
+
* not fit its current internal state.
|
|
5
|
+
*
|
|
6
|
+
* Typical triggers:
|
|
7
|
+
* - adding a parameter after the first vote has been emitted;
|
|
8
|
+
* - constructing a `Cef` with neither a file nor a string target, or with
|
|
9
|
+
* both at once;
|
|
10
|
+
* - parsing a vote-line string that ends up without a ranking.
|
|
11
|
+
*/
|
|
12
|
+
export class InvalidWriterStateException extends CefFormatException {
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a value contains a character that the CEF format reserves for
|
|
4
|
+
* structural use and therefore forbids inside any value.
|
|
5
|
+
*
|
|
6
|
+
* Covers the eight spec-listed reserved characters (`> = ; , # / * ^`) as well
|
|
7
|
+
* as the secondary syntactic separators the library enforces: `:` in a custom
|
|
8
|
+
* parameter name, `||` in a tag, and a leading `#` on a raw vote line.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ReservedCharacterException extends CefFormatException {
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ReservedCharacterException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReservedCharacterException.d.ts","sourceRoot":"","sources":["../../src/Exception/ReservedCharacterException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;GAOG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB;CAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CefFormatException } from './CefFormatException';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a value contains a character that the CEF format reserves for
|
|
4
|
+
* structural use and therefore forbids inside any value.
|
|
5
|
+
*
|
|
6
|
+
* Covers the eight spec-listed reserved characters (`> = ; , # / * ^`) as well
|
|
7
|
+
* as the secondary syntactic separators the library enforces: `:` in a custom
|
|
8
|
+
* parameter name, `||` in a tag, and a leading `#` on a raw vote line.
|
|
9
|
+
*/
|
|
10
|
+
export class ReservedCharacterException extends CefFormatException {
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { CefFormatException } from './CefFormatException';
|
|
2
|
+
export { CefWriteException } from './CefWriteException';
|
|
3
|
+
export { DuplicateCandidateException } from './DuplicateCandidateException';
|
|
4
|
+
export { InvalidUtf8Exception } from './InvalidUtf8Exception';
|
|
5
|
+
export { InvalidValueException } from './InvalidValueException';
|
|
6
|
+
export { InvalidWriterStateException } from './InvalidWriterStateException';
|
|
7
|
+
export { ReservedCharacterException } from './ReservedCharacterException';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Exception/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CefFormatException } from './CefFormatException';
|
|
2
|
+
export { CefWriteException } from './CefWriteException';
|
|
3
|
+
export { DuplicateCandidateException } from './DuplicateCandidateException';
|
|
4
|
+
export { InvalidUtf8Exception } from './InvalidUtf8Exception';
|
|
5
|
+
export { InvalidValueException } from './InvalidValueException';
|
|
6
|
+
export { InvalidWriterStateException } from './InvalidWriterStateException';
|
|
7
|
+
export { ReservedCharacterException } from './ReservedCharacterException';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WriteTarget } from './Cef';
|
|
2
|
+
/**
|
|
3
|
+
* A {@link WriteTarget} backed by a real file descriptor, opened in truncating
|
|
4
|
+
* write mode. Created automatically when a filesystem path is passed to the
|
|
5
|
+
* {@link Cef} constructor in Node.js environments.
|
|
6
|
+
*
|
|
7
|
+
* **Note**: This class is only available in Node.js environments. Browser users
|
|
8
|
+
* must use {@link StringBuffer} or provide a custom {@link WriteTarget}.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Cef, FileWriteTarget } from '@condorcet.vote/cef-writer';
|
|
13
|
+
*
|
|
14
|
+
* const target = new FileWriteTarget('/tmp/election.cvotes');
|
|
15
|
+
* const cef = new Cef({ file: target });
|
|
16
|
+
* // ... add parameters and votes
|
|
17
|
+
* cef.close();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class FileWriteTarget implements WriteTarget {
|
|
21
|
+
private readonly fd;
|
|
22
|
+
private closed;
|
|
23
|
+
constructor(path: string);
|
|
24
|
+
write(chunk: string): number;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=FileWriteTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileWriteTarget.d.ts","sourceRoot":"","sources":["../src/FileWriteTarget.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAE5B,OAAO,CAAC,MAAM,CAAS;gBAEJ,IAAI,EAAE,MAAM;IAIxB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI5B,KAAK,IAAI,IAAI;CAMrB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* A {@link WriteTarget} backed by a real file descriptor, opened in truncating
|
|
4
|
+
* write mode. Created automatically when a filesystem path is passed to the
|
|
5
|
+
* {@link Cef} constructor in Node.js environments.
|
|
6
|
+
*
|
|
7
|
+
* **Note**: This class is only available in Node.js environments. Browser users
|
|
8
|
+
* must use {@link StringBuffer} or provide a custom {@link WriteTarget}.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Cef, FileWriteTarget } from '@condorcet.vote/cef-writer';
|
|
13
|
+
*
|
|
14
|
+
* const target = new FileWriteTarget('/tmp/election.cvotes');
|
|
15
|
+
* const cef = new Cef({ file: target });
|
|
16
|
+
* // ... add parameters and votes
|
|
17
|
+
* cef.close();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class FileWriteTarget {
|
|
21
|
+
fd;
|
|
22
|
+
closed = false;
|
|
23
|
+
constructor(path) {
|
|
24
|
+
this.fd = fs.openSync(path, 'w');
|
|
25
|
+
}
|
|
26
|
+
write(chunk) {
|
|
27
|
+
return fs.writeSync(this.fd, Buffer.from(chunk, 'utf-8'));
|
|
28
|
+
}
|
|
29
|
+
close() {
|
|
30
|
+
if (!this.closed) {
|
|
31
|
+
fs.closeSync(this.fd);
|
|
32
|
+
this.closed = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Candidates:` parameter — declares the official list of candidates.
|
|
4
|
+
*
|
|
5
|
+
* Candidate names are written separated by `;`. With auto-format on, the
|
|
6
|
+
* separator is padded with spaces (`A ; B ; C`) for readability; otherwise the
|
|
7
|
+
* most compact form (`A;B;C`) is used.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CandidatesParameter implements ParameterInterface {
|
|
10
|
+
readonly candidates: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* @param candidates non-empty list of distinct candidate names
|
|
13
|
+
*
|
|
14
|
+
* @throws {CefFormatException}
|
|
15
|
+
*/
|
|
16
|
+
constructor(candidates: readonly string[]);
|
|
17
|
+
getName(): string;
|
|
18
|
+
getFormattedValue(autoFormat?: boolean): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=CandidatesParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CandidatesParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/CandidatesParameter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAC5D,SAAgB,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAE9C;;;;OAIG;gBACgB,UAAU,EAAE,SAAS,MAAM,EAAE;IAqBzC,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,UAAU,UAAO,GAAG,MAAM;CAGpD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CefFormat } from '../CefFormat';
|
|
2
|
+
import { DuplicateCandidateException, InvalidValueException } from '../Exception';
|
|
3
|
+
import { StandardParameter } from './StandardParameter';
|
|
4
|
+
/**
|
|
5
|
+
* `#/Candidates:` parameter — declares the official list of candidates.
|
|
6
|
+
*
|
|
7
|
+
* Candidate names are written separated by `;`. With auto-format on, the
|
|
8
|
+
* separator is padded with spaces (`A ; B ; C`) for readability; otherwise the
|
|
9
|
+
* most compact form (`A;B;C`) is used.
|
|
10
|
+
*/
|
|
11
|
+
export class CandidatesParameter {
|
|
12
|
+
candidates;
|
|
13
|
+
/**
|
|
14
|
+
* @param candidates non-empty list of distinct candidate names
|
|
15
|
+
*
|
|
16
|
+
* @throws {CefFormatException}
|
|
17
|
+
*/
|
|
18
|
+
constructor(candidates) {
|
|
19
|
+
if (candidates.length === 0) {
|
|
20
|
+
throw new InvalidValueException('Candidates list cannot be empty.');
|
|
21
|
+
}
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
for (const candidate of candidates) {
|
|
24
|
+
const trimmed = candidate.trim();
|
|
25
|
+
CefFormat.assertValueIsClean(trimmed, 'Candidate name');
|
|
26
|
+
if (seen.has(trimmed)) {
|
|
27
|
+
throw new DuplicateCandidateException(`Duplicate candidate "${trimmed}".`);
|
|
28
|
+
}
|
|
29
|
+
seen.add(trimmed);
|
|
30
|
+
}
|
|
31
|
+
this.candidates = candidates.map((candidate) => candidate.trim());
|
|
32
|
+
}
|
|
33
|
+
getName() {
|
|
34
|
+
return StandardParameter.Candidates;
|
|
35
|
+
}
|
|
36
|
+
getFormattedValue(autoFormat = true) {
|
|
37
|
+
return this.candidates.join(autoFormat ? ' ; ' : ';');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* Free-form parameter for tooling that extends CEF with project-specific keys.
|
|
4
|
+
*
|
|
5
|
+
* The name must avoid every reserved character and `:`, since `:` separates a
|
|
6
|
+
* parameter from its value. The value must avoid line breaks but is otherwise
|
|
7
|
+
* free-form (the spec only reserves characters for *structured* values).
|
|
8
|
+
*/
|
|
9
|
+
export declare class CustomParameter implements ParameterInterface {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly value: string;
|
|
12
|
+
/**
|
|
13
|
+
* @throws {CefFormatException}
|
|
14
|
+
*/
|
|
15
|
+
constructor(name: string, value: string);
|
|
16
|
+
getName(): string;
|
|
17
|
+
getFormattedValue(_autoFormat?: boolean): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=CustomParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/CustomParameter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAE9B;;OAEG;gBACgB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAkBvC,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,WAAW,UAAO,GAAG,MAAM;CAGrD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CefFormat } from '../CefFormat';
|
|
2
|
+
import { InvalidValueException, ReservedCharacterException } from '../Exception';
|
|
3
|
+
/**
|
|
4
|
+
* Free-form parameter for tooling that extends CEF with project-specific keys.
|
|
5
|
+
*
|
|
6
|
+
* The name must avoid every reserved character and `:`, since `:` separates a
|
|
7
|
+
* parameter from its value. The value must avoid line breaks but is otherwise
|
|
8
|
+
* free-form (the spec only reserves characters for *structured* values).
|
|
9
|
+
*/
|
|
10
|
+
export class CustomParameter {
|
|
11
|
+
name;
|
|
12
|
+
value;
|
|
13
|
+
/**
|
|
14
|
+
* @throws {CefFormatException}
|
|
15
|
+
*/
|
|
16
|
+
constructor(name, value) {
|
|
17
|
+
const trimmedName = name.trim();
|
|
18
|
+
if (trimmedName === '') {
|
|
19
|
+
throw new InvalidValueException('Custom parameter name cannot be empty.');
|
|
20
|
+
}
|
|
21
|
+
if (trimmedName.includes(':')) {
|
|
22
|
+
throw new ReservedCharacterException('Custom parameter name cannot contain ":".');
|
|
23
|
+
}
|
|
24
|
+
CefFormat.assertValueIsClean(trimmedName, 'Custom parameter name');
|
|
25
|
+
CefFormat.assertNoReservedNorLineBreak(value, 'Custom parameter value');
|
|
26
|
+
this.name = trimmedName;
|
|
27
|
+
this.value = value;
|
|
28
|
+
}
|
|
29
|
+
getName() {
|
|
30
|
+
return this.name;
|
|
31
|
+
}
|
|
32
|
+
getFormattedValue(_autoFormat = true) {
|
|
33
|
+
return this.value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Implicit Ranking:` parameter — boolean toggle.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ImplicitRankingParameter implements ParameterInterface {
|
|
6
|
+
readonly enabled: boolean;
|
|
7
|
+
constructor(enabled: boolean);
|
|
8
|
+
getName(): string;
|
|
9
|
+
getFormattedValue(_autoFormat?: boolean): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ImplicitRankingParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImplicitRankingParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/ImplicitRankingParameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;GAEG;AACH,qBAAa,wBAAyB,YAAW,kBAAkB;aAC9B,OAAO,EAAE,OAAO;gBAAhB,OAAO,EAAE,OAAO;IAE5C,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,WAAW,UAAO,GAAG,MAAM;CAGrD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StandardParameter } from './StandardParameter';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Implicit Ranking:` parameter — boolean toggle.
|
|
4
|
+
*/
|
|
5
|
+
export class ImplicitRankingParameter {
|
|
6
|
+
enabled;
|
|
7
|
+
constructor(enabled) {
|
|
8
|
+
this.enabled = enabled;
|
|
9
|
+
}
|
|
10
|
+
getName() {
|
|
11
|
+
return StandardParameter.ImplicitRanking;
|
|
12
|
+
}
|
|
13
|
+
getFormattedValue(_autoFormat = true) {
|
|
14
|
+
return this.enabled ? 'true' : 'false';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Number of Seats:` parameter — strictly positive integer.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NumberOfSeatsParameter implements ParameterInterface {
|
|
6
|
+
readonly seats: number;
|
|
7
|
+
/**
|
|
8
|
+
* @throws {CefFormatException}
|
|
9
|
+
*/
|
|
10
|
+
constructor(seats: number);
|
|
11
|
+
getName(): string;
|
|
12
|
+
getFormattedValue(_autoFormat?: boolean): string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=NumberOfSeatsParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NumberOfSeatsParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/NumberOfSeatsParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;GAEG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;aAI5B,KAAK,EAAE,MAAM;IAHhD;;OAEG;gBACgC,KAAK,EAAE,MAAM;IAMzC,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,WAAW,UAAO,GAAG,MAAM;CAGrD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InvalidValueException } from '../Exception';
|
|
2
|
+
import { StandardParameter } from './StandardParameter';
|
|
3
|
+
/**
|
|
4
|
+
* `#/Number of Seats:` parameter — strictly positive integer.
|
|
5
|
+
*/
|
|
6
|
+
export class NumberOfSeatsParameter {
|
|
7
|
+
seats;
|
|
8
|
+
/**
|
|
9
|
+
* @throws {CefFormatException}
|
|
10
|
+
*/
|
|
11
|
+
constructor(seats) {
|
|
12
|
+
this.seats = seats;
|
|
13
|
+
if (!Number.isInteger(seats) || seats < 1) {
|
|
14
|
+
throw new InvalidValueException('Number of seats must be a positive integer.');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getName() {
|
|
18
|
+
return StandardParameter.NumberOfSeats;
|
|
19
|
+
}
|
|
20
|
+
getFormattedValue(_autoFormat = true) {
|
|
21
|
+
return String(this.seats);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract every parameter object (standard or custom) must implement.
|
|
3
|
+
*
|
|
4
|
+
* A parameter knows how to render its own *name* and *value* but not how to
|
|
5
|
+
* assemble the final line: line assembly is the responsibility of the writer,
|
|
6
|
+
* which decides spacing based on the `autoFormat` flag.
|
|
7
|
+
*/
|
|
8
|
+
export interface ParameterInterface {
|
|
9
|
+
/**
|
|
10
|
+
* The parameter name, as it must appear after the `#/` prefix.
|
|
11
|
+
*/
|
|
12
|
+
getName(): string;
|
|
13
|
+
/**
|
|
14
|
+
* The parameter value, already serialized but **without** the surrounding
|
|
15
|
+
* `#/Name: ` prefix. The boolean `autoFormat` flag lets the parameter choose
|
|
16
|
+
* whether to expand its value with optional whitespace.
|
|
17
|
+
*/
|
|
18
|
+
getFormattedValue(autoFormat?: boolean): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ParameterInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParameterInterface.d.ts","sourceRoot":"","sources":["../../src/Parameter/ParameterInterface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;;;OAIG;IACH,iBAAiB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of the parameter names defined by the CEF specification.
|
|
3
|
+
*
|
|
4
|
+
* The string value of each case is the exact, case-correct name that must
|
|
5
|
+
* appear after the `#/` prefix in the generated file.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum StandardParameter {
|
|
8
|
+
Candidates = "Candidates",
|
|
9
|
+
NumberOfSeats = "Number of Seats",
|
|
10
|
+
ImplicitRanking = "Implicit Ranking",
|
|
11
|
+
VotingMethods = "Voting Methods",
|
|
12
|
+
WeightAllowed = "Weight Allowed"
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=StandardParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/StandardParameter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,iBAAiB;IAC3B,UAAU,eAAe;IACzB,aAAa,oBAAoB;IACjC,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;CACjC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of the parameter names defined by the CEF specification.
|
|
3
|
+
*
|
|
4
|
+
* The string value of each case is the exact, case-correct name that must
|
|
5
|
+
* appear after the `#/` prefix in the generated file.
|
|
6
|
+
*/
|
|
7
|
+
export var StandardParameter;
|
|
8
|
+
(function (StandardParameter) {
|
|
9
|
+
StandardParameter["Candidates"] = "Candidates";
|
|
10
|
+
StandardParameter["NumberOfSeats"] = "Number of Seats";
|
|
11
|
+
StandardParameter["ImplicitRanking"] = "Implicit Ranking";
|
|
12
|
+
StandardParameter["VotingMethods"] = "Voting Methods";
|
|
13
|
+
StandardParameter["WeightAllowed"] = "Weight Allowed";
|
|
14
|
+
})(StandardParameter || (StandardParameter = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Voting Methods:` parameter — list of method identifiers separated by `;`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class VotingMethodsParameter implements ParameterInterface {
|
|
6
|
+
readonly methods: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* @param methods non-empty list of method names
|
|
9
|
+
*
|
|
10
|
+
* @throws {CefFormatException}
|
|
11
|
+
*/
|
|
12
|
+
constructor(methods: readonly string[]);
|
|
13
|
+
getName(): string;
|
|
14
|
+
getFormattedValue(autoFormat?: boolean): string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=VotingMethodsParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VotingMethodsParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/VotingMethodsParameter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;GAEG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D,SAAgB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAE3C;;;;OAIG;gBACgB,OAAO,EAAE,SAAS,MAAM,EAAE;IAYtC,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,UAAU,UAAO,GAAG,MAAM;CAGpD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CefFormat } from '../CefFormat';
|
|
2
|
+
import { InvalidValueException } from '../Exception';
|
|
3
|
+
import { StandardParameter } from './StandardParameter';
|
|
4
|
+
/**
|
|
5
|
+
* `#/Voting Methods:` parameter — list of method identifiers separated by `;`.
|
|
6
|
+
*/
|
|
7
|
+
export class VotingMethodsParameter {
|
|
8
|
+
methods;
|
|
9
|
+
/**
|
|
10
|
+
* @param methods non-empty list of method names
|
|
11
|
+
*
|
|
12
|
+
* @throws {CefFormatException}
|
|
13
|
+
*/
|
|
14
|
+
constructor(methods) {
|
|
15
|
+
if (methods.length === 0) {
|
|
16
|
+
throw new InvalidValueException('Voting methods list cannot be empty.');
|
|
17
|
+
}
|
|
18
|
+
for (const method of methods) {
|
|
19
|
+
CefFormat.assertValueIsClean(method.trim(), 'Voting method name');
|
|
20
|
+
}
|
|
21
|
+
this.methods = methods.map((method) => method.trim());
|
|
22
|
+
}
|
|
23
|
+
getName() {
|
|
24
|
+
return StandardParameter.VotingMethods;
|
|
25
|
+
}
|
|
26
|
+
getFormattedValue(autoFormat = true) {
|
|
27
|
+
return this.methods.join(autoFormat ? ' ; ' : ';');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParameterInterface } from './ParameterInterface';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Weight Allowed:` parameter — boolean toggle.
|
|
4
|
+
*/
|
|
5
|
+
export declare class WeightAllowedParameter implements ParameterInterface {
|
|
6
|
+
readonly enabled: boolean;
|
|
7
|
+
constructor(enabled: boolean);
|
|
8
|
+
getName(): string;
|
|
9
|
+
getFormattedValue(_autoFormat?: boolean): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=WeightAllowedParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WeightAllowedParameter.d.ts","sourceRoot":"","sources":["../../src/Parameter/WeightAllowedParameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;GAEG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;aAC5B,OAAO,EAAE,OAAO;gBAAhB,OAAO,EAAE,OAAO;IAE5C,OAAO,IAAI,MAAM;IAIjB,iBAAiB,CAAC,WAAW,UAAO,GAAG,MAAM;CAGrD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StandardParameter } from './StandardParameter';
|
|
2
|
+
/**
|
|
3
|
+
* `#/Weight Allowed:` parameter — boolean toggle.
|
|
4
|
+
*/
|
|
5
|
+
export class WeightAllowedParameter {
|
|
6
|
+
enabled;
|
|
7
|
+
constructor(enabled) {
|
|
8
|
+
this.enabled = enabled;
|
|
9
|
+
}
|
|
10
|
+
getName() {
|
|
11
|
+
return StandardParameter.WeightAllowed;
|
|
12
|
+
}
|
|
13
|
+
getFormattedValue(_autoFormat = true) {
|
|
14
|
+
return this.enabled ? 'true' : 'false';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CandidatesParameter } from './CandidatesParameter';
|
|
2
|
+
export { CustomParameter } from './CustomParameter';
|
|
3
|
+
export { ImplicitRankingParameter } from './ImplicitRankingParameter';
|
|
4
|
+
export { NumberOfSeatsParameter } from './NumberOfSeatsParameter';
|
|
5
|
+
export type { ParameterInterface } from './ParameterInterface';
|
|
6
|
+
export { StandardParameter } from './StandardParameter';
|
|
7
|
+
export { VotingMethodsParameter } from './VotingMethodsParameter';
|
|
8
|
+
export { WeightAllowedParameter } from './WeightAllowedParameter';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Parameter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CandidatesParameter } from './CandidatesParameter';
|
|
2
|
+
export { CustomParameter } from './CustomParameter';
|
|
3
|
+
export { ImplicitRankingParameter } from './ImplicitRankingParameter';
|
|
4
|
+
export { NumberOfSeatsParameter } from './NumberOfSeatsParameter';
|
|
5
|
+
export { StandardParameter } from './StandardParameter';
|
|
6
|
+
export { VotingMethodsParameter } from './VotingMethodsParameter';
|
|
7
|
+
export { WeightAllowedParameter } from './WeightAllowedParameter';
|