Arbitrary data encoder/decoder that matches python rencode
.
npm install python-rencode
const { encode, decode } = require('python-rencode');
// Could be basically any data that would convert correctly to JSON
const thing = 1;
// Encode some data into a Buffer
const encoded = encode(thing);
// Decode a Buffer into some data
const decoded = decode(encoded);
If you'd rather not use the versions published to npm, you can easily install from github directly with:
npm install cinderblock/python-rencode # Defaults to master
npm install cinderblock/python-rencode#branch # Use a named branch
npm install cinderblock/python-rencode#v1.4.0 # Use a tagged version
npm install cinderblock/python-rencode#hash # Use a hash directly
v1.4.0
slightly changed the API.
undefined
has been replaced withnull
.undefined
is no longer allowed as a value and will now throw. This behavior might change in the future. Make an issue to discuss.
- Export data type:
RencodableData
- Add TypeScript Support
- Decode UTF8 by default
yarn setup
Run the jest test suite against TypeScript sources.
yarn test
yarn test --coverage # Generate coverage reports
yarn test --watchAll # Watch mode
yarn test --watchAll --coverage # Combined
The test suite can also be run against any arbitrary copy of the library by setting the environment variable JEST_IMPORT_OVERRIDE
.
This is useful for testing against the compiled JavaScript dist
folder or a git dependency.
Both of these use cases are tested automatically in Github Actions.
Ensure code is formatted with our style.
yarn format --check
yarn format --write
This is generally unnecessary with "Format On Save" features of most editors. VS Code should work automatically because of workspace settings.
Start a repl with functions encode
and decode
loaded into the running context.
yarn repl
Just run any single npm/yarn version command.
# Any of these work. Other variations work too.
yarn version
yarn version --minor
npm version major
Version bumps trigger a publish to npm on Github Actions.
We build a dist
folder to publish from.
The published version has a simplified README.md
and package.json
.
We build a dist
folder to actually publish from.
yarn build
This builds the TypeScript, copies this README with development sections removed, and copies a simplified version of the package.json for Npm.