Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Convert .p8 files to .js files for use in other projects.
This simple command-line converter is intended to be used in build pipelines, CLI tools, and any
other context where converting from .p8
to .js
is useful.
With npx
:
npx p8-to-js cart.p8 cart.js
Using npm install
:
npm install -g p8-to-js
p8-to-js cart.p8 cart.js
You can export ready-to-use JavaScript in a variety of different styles -- pick the one that best suits your codebase from the list below.
(If none of these options meets your needs, you might consider using the API instead of the CLI -- see the API documentation below.)
Command line:
npx p8-to-js cart.p8 cart.js
npx p8-to-js cart.p8 cart.js --export default
Output:
export default { gfx: '....', lua: '....', sfx: '....', music: '....' };
Usage:
import Cart from './cart';
Command line:
npx p8-to-js cart.p8 cart.js --export Cart
Output:
export const Cart = { gfx: '....', lua: '....', sfx: '....', music: '....' };
Usage:
import { Cart } from './cart';
Command line:
npx p8-to-js cart.p8 cart.js --export commonjs
Output:
module.exports = { gfx: '....', lua: '....', sfx: '....', music: '....' };
Usage:
const Cart = require('./cart');
Command line:
npx p8-to-js cart.p8 cart.json --export json
Output:
{
"gfx": "....",
"lua": "....",
"sfx": "....",
"music": "...."
}
Usage:
const Cart = require("./cart.json");
Specify hex
or base64
encoding. Hex is the default (the output looks exactly like the .p8
file).
Note: choosing
base64
encoding means the output strings will be the base64-encoded versions of the binary string represented by the original hex string. That is, if thegfx
section is"000000"
, then thebase64
representation is"AAA"
. Once unencoded, this is"\u0000\u0000\u0000"
.
Specify one or more sections to include in the output (use commas to specify more than one).
For example, to export only the sfx
and music
sections:
npx p8-to-js cart.p8 cart.js --sections sfx,music
Convert a file (async):
const p8tojs = require('p8-to-js');
await p8tojs.convertFile('cart.p8', 'cart.js');
Convert a file (sync):
const p8tojs = require('p8-to-js');
p8tojs.convertFileSync('cart.p8', 'cart.js');
Convert a PICO-8 cartridge string into JavaScript output:
const p8tojs = require('p8-to-js');
console.log(p8tojs.convert(fs.readFileSync('cart.p8')));
All of the options supported by the CLI are available in the API. For example:
const p8tojs = require('p8-to-js');
let input = fs.readFileSync('cart.p8');
let output = p8tojs.convert(input, {
export: 'Song',
encoding: 'base64',
sections: ['sfx', 'music']
});
console.log(`
// Generated by my fancy build script.
${output}
`);
The output:
// Generated by my fancy build script.
export const Song = { sfx: 'ARaplo532AARRJara3==', music: 'ARJvvAAAAAAAA=' };
Pull requests welcome!
To run unit tests locally:
npm install
npm test
FAQs
Convert .p8 files to .js files for use in other projects.
The npm package p8-to-js receives a total of 0 weekly downloads. As such, p8-to-js popularity was classified as not popular.
We found that p8-to-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.