Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Apr 23, 2023
1 parent 6e60c82 commit 7f8d8e7
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 340 deletions.
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extension": ["ts"],
"node-option": ["experimental-loader=ts-node/esm"]
"$schema": "https://json.schemastore.org/mocharc",
"spec": ["test/**/*.test.ts"],
"require": ["ts-node/register"]
}
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ quoteProps: consistent
trailingComma: none
bracketSpacing: true
arrowParens: avoid
parser: require("@typescript-eslint/typescript-estree")
parser: typescript
endOfLine: lf
74 changes: 73 additions & 1 deletion bin/decodeme.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
#!/usr/bin/env node
require("../dist/cli")(process.argv.slice(2), "decode");
"use strict";
const fs = require("fs");
const path = require("path");
const { program } = require("commander");
const dencodeme = require("../dist");

const encodingOption = program
.createOption("-e, --encoding <format>", "The encoding to write the output data in")
.default("utf8")
.choices(["ascii", "binary", "latin1", "ucs2", "utf8", "utf16le"]);
const fileFlag = program
.createOption("-f, --file", "Interprets the input as a file path and decodes the file at the path");
const inputArgument = program
.createArgument("<input>", "The input data to decode");
const outOption = program
.createOption("-o, --out <path>", "The file path to write the output data to");

program.name("decodeme")
.usage("[command] [options]")
.description("Decode data using various encoding schemes.")
.version(require("../package.json").version, "-v, --version", "Outputs the current version")
.helpOption("-h, --help", "Outputs this help menu")
.addHelpCommand("help [command]", "Outputs help for command");

program.command("base")
.description("Decodes the specified input data from the specified base/radix")
.usage("<radix> [options] <input>")
.argument("<radix>", "The base/radix to decode from, clamped to range 2-36", x => {
const parsed = parseInt(x, 10);
return Number.isNaN(parsed) ? program.error("Base/Radix is not a valid base 10 number") : parsed;
})
.addArgument(inputArgument)
.addOption(encodingOption)
.addOption(fileFlag)
.addOption(outOption)
.alias("radix")
.action((radix, input, options) => {
try {
const output = dencodeme.base(radix).decode(options.file ?
fs.readFileSync(path.resolve(process.cwd(), input), "utf8") : input);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output, options.encoding) :
process.stdout.write(output.toString(options.encoding));
} catch (err) {
program.error(String(err));
}
});

// Create a command for each base/radix in the dencodeme object
for (const [command, base] of Object.entries(dencodeme).map(x => [x[0], typeof x[1] == "function" ? NaN : x[1].radix])
.filter(x => !Number.isNaN(x[1]))) {
program.command(command)
.summary(`Decodes the specified input data from base ${base}`)
.description(`Decodes the specified input data from a base/radix of ${base}`)
.usage("[options] <input>")
.addArgument(inputArgument)
.addOption(encodingOption)
.addOption(fileFlag)
.addOption(outOption)
.aliases(command.startsWith("base") ? [`b${command.slice(4)}`] : [command.slice(0, 3), `base${base}`, `b${base}`])
.action((input, options) => {
try {
const output = dencodeme[command].decode(options.file ?
fs.readFileSync(path.resolve(process.cwd(), input), "utf8") : input);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output, options.encoding) :
process.stdout.write(output.toString(options.encoding));
} catch (err) {
program.error(String(err));
}
});
}

// Parse the given arguments and run the program
program.parse(process.argv.slice(2), { from: "user" });
74 changes: 73 additions & 1 deletion bin/encodeme.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
#!/usr/bin/env node
require("../dist/cli")(process.argv.slice(2), "encode");
"use strict";
const fs = require("fs");
const path = require("path");
const { program } = require("commander");
const dencodeme = require("../dist");

const encodingOption = program
.createOption("-e, --encoding <format>", "The encoding to read the input data in")
.default("utf8")
.choices(["ascii", "binary", "latin1", "ucs2", "utf8", "utf16le"]);
const fileFlag = program
.createOption("-f, --file", "Interprets the input as a file path and encodes the file at the path");
const inputArgument = program
.createArgument("<input>", "The input data to encode");
const outOption = program
.createOption("-o, --out <path>", "The file path to write the output data to");

program.name("encodeme")
.usage("[command] [options]")
.description("Encode data using various encoding schemes.")
.version(require("../package.json").version, "-v, --version", "Outputs the current version")
.helpOption("-h, --help", "Outputs this help menu")
.addHelpCommand("help [command]", "Outputs help for command");

program.command("base")
.description("Encodes the specified input data with the specified base/radix")
.usage("<radix> [options] <input>")
.argument("<radix>", "The base/radix to encode with, clamped to range 2-36", x => {
const parsed = parseInt(x, 10);
return Number.isNaN(parsed) ? program.error("Base/Radix is not a valid base 10 number") : parsed;
})
.addArgument(inputArgument)
.addOption(encodingOption)
.addOption(fileFlag)
.addOption(outOption)
.alias("radix")
.action((radix, input, options) => {
try {
const output = dencodeme.base(radix).encode(options.file ?
fs.readFileSync(path.resolve(process.cwd(), input), options.encoding) : input);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output, options.encoding) :
process.stdout.write(output.toString(options.encoding));
} catch (err) {
program.error(String(err));
}
});

// Create a command for each base/radix in the dencodeme object
for (const [command, base] of Object.entries(dencodeme).map(x => [x[0], typeof x[1] == "function" ? NaN : x[1].radix])
.filter(x => !Number.isNaN(x[1]))) {
program.command(command)
.summary(`Encodes the specified input data with base ${base}`)
.description(`Encodes the specified input data with a base/radix of ${base}`)
.usage("[options] <input>")
.addArgument(inputArgument)
.addOption(encodingOption)
.addOption(fileFlag)
.addOption(outOption)
.aliases(command.startsWith("base") ? [`b${command.slice(4)}`] : [command.slice(0, 3), `base${base}`, `b${base}`])
.action((input, options) => {
try {
const output = dencodeme[command].encode(options.file ?
fs.readFileSync(path.resolve(process.cwd(), input), options.encoding) : input);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output, options.encoding) :
process.stdout.write(output.toString(options.encoding));
} catch (err) {
program.error(String(err));
}
});
}

// Parse the given arguments and run the program
program.parse(process.argv.slice(2), { from: "user" });
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dencodeme",
"version": "1.0.2",
"version": "1.0.3",
"description": "Encode/Decode data using various encoding schemes.",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand All @@ -27,26 +27,25 @@
"homepage": "https://crackabottle.js.org/dencodeme",
"scripts": {
"build": "tsup",
"docs": "typedoc src --exclude src/cli.ts --includeVersion",
"test": "ts-mocha test",
"docs": "typedoc src/index.ts --includeVersion",
"test": "mocha",
"lint": "prettier . -w",
"prepare": "pnpm build"
},
"engines": {
"node": ">=16.0.0"
},
"dependencies": {
"commander": "^10.0.0"
"commander": "^10.0.1"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.3",
"@types/node": "^18.15.13",
"mocha": "^10.2.0",
"prettier": "^2.8.4",
"ts-mocha": "^10.0.0",
"prettier": "^2.8.7",
"ts-node": "^10.9.1",
"tsup": "^6.7.0",
"typedoc": "^0.24.1",
"typescript": "^5.0.2"
"typedoc": "^0.24.4",
"typescript": "^5.0.4"
}
}
Loading

0 comments on commit 7f8d8e7

Please sign in to comment.