Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@votingworks/ballot-encoder
Advanced tools
Provides encoding and decoding services for completed ballots.
To use within VS Code:
yarn install
yarn pnpify --sdk
In dev ballot-encoder
dir, run yarn tsc
to generate JavaScript files.
In the PROJECT you wish to use this dev version of ballot-encoder
:
cd path/to/PROJECT/node_modules/@votingworks
rm -rf ballot-encoder
ln -s path/to/ballot-encoder ballot-encoder
npm version [major|minor|patch]
yarn prepare
(or yarn tsc
)yarn 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
.yarn 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 6 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.