Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@votingworks/ballot-encoder
Advanced tools
Provides encoding and decoding services for completed ballots.
Provides encoding and decoding services for completed ballots.
To use within VS Code:
pnpm install
npm version [major|minor|patch]
pnpm prepare
(or pnpx tsc
)npm publish --access=public
Optionally, deprecate a previous version. For example:
npm deprecate -f '@votingworks/ballot-encoder@1.3.1' "Poor translations"
import {
CompletedBallot,
decodeBallot,
electionSample as election,
encodeBallot,
getContests,
vote,
} from '@votingworks/ballot-encoder'
const ballotStyle = election.ballotStyles[0]
const precinct = election.precincts[0]
const ballotId = 'abcde'
const contests = getContests({ ballotStyle, election })
const votes = vote(contests, {
'judicial-robert-demergue': 'yes',
'judicial-elmer-hull': 'yes',
'question-a': 'yes',
'question-b': 'no',
'question-c': 'yes',
'proposition-1': 'yes',
'measure-101': 'no',
'102': 'yes',
})
const ballot: CompletedBallot = {
ballotId,
ballotStyle,
precinct,
votes,
}
console.log(encodeBallot(ballot))
/*
Uint8Array [
86, 88, 1, 2, 49, 50, 2,
50, 51, 0, 15, 254, 208, 86,
22, 38, 54, 70, 80
]
*/
console.log(decodeBallot(election, encodeBallot(ballot)).ballot.votes)
/*
{
'102': 'yes',
'judicial-robert-demergue': 'yes',
'judicial-elmer-hull': 'yes',
'question-a': 'yes',
'question-b': 'no',
'question-c': 'yes',
'proposition-1': 'yes',
'measure-101': 'no'
}
*/
To encode a ballot, simply pass an election and a completed ballot object to
encodeBallot
. You'll get back a buffer that may be stored or transmitted and
later passed to decodeBallot
with the same election
data given to
encodeBallot
.
There are multiple encoder versions and by default the latest will be used when
encoding. To specify the version, pass the EncoderVersion
as the second
parameter to encodeBallot
:
import { encodeBallot, EncoderVersion } from '@votingworks/ballot-encoder'
const encodedBallot = encodeBallot(ballot, EncoderVersion.v1)
When decoding, you may pass an EncoderVersion
or you may allow decodeBallot
to detect the encoder version:
import { decodeBallot, EncoderVersion } from '@votingworks/ballot-encoder'
// automatically detect version
const result = decodeBallot(election, encodedBallot)
console.log('Ballot version:', result.version)
console.log('Ballot:', result.ballot)
// specify version
const result = decodeBallot(election, encodedBallot, EncoderVersion.v0)
console.log('Ballot version:', result.version)
console.log('Ballot:', result.ballot)
If you only want to detect the version, you can simply use detect
:
import { detect } from '@votingworks/ballot-encoder'
const version = detect(encodedBallot)
console.log('Ballot version:', version)
This project uses the Angular Commit Message Format convention. How to publish a new version:
BUMP
.npm version $BUMP
.pnpm publish:npm
.git push -u origin HEAD && git push --tags
.FAQs
Provides encoding and decoding services for completed ballots.
The npm package @votingworks/ballot-encoder receives a total of 23 weekly downloads. As such, @votingworks/ballot-encoder popularity was classified as not popular.
We found that @votingworks/ballot-encoder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.