Skip to content

Commit

Permalink
Fix tsc errors; raise TypeError on decode; CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
NCPlayz committed Jan 23, 2021
1 parent 16378ce commit 709c0f7
Show file tree
Hide file tree
Showing 11 changed files with 2,555 additions and 18 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,40 @@ $ npm i bottomify
$ yarn add bottomify
```

### Deno:
### Deno:

```ts
import { encode, decode } from "https://deno.land/x/bottomify@0.2.0/deno.ts"
import { encode, decode } from "https://deno.land/x/bottomify@0.3.0/deno.ts";
```

### Browser:

```html
<!-- unpkg -->
<script src="https://unpkg.com/bottomify@0.1.0/dist/bottomify.js"></script>
<script src="https://unpkg.com/bottomify@0.3.0/dist/bottomify.js"></script>
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/bottomify@0.1.0/dist/bottomify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bottomify@0.3.0/dist/bottomify.js"></script>

<!-- Minified -->

<!-- unpkg -->
<script src="https://unpkg.com/bottomify@0.1.0/dist/bottomify.min.js"></script>
<script src="https://unpkg.com/bottomify@0.3.0/dist/bottomify.min.js"></script>
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bottomify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bottomify.min.js"></script>
```

## Command-line Interface

> Currently this is not available for Deno users.
```sh
$ bottomify --bottomify test
💖💖✨🥺,👉👈💖💖,👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈
$ bottomify --regress 💖💖✨🥺,👉👈💖💖,👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈
test
$ bottomify --bottomify --input test.top
💖💖✨🥺,👉👈💖💖,👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈
$ bottomify --bottomify test --output test.btm
```

## Examples
Expand Down
7 changes: 3 additions & 4 deletions dist/bottomify.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ function encodeChar(charValue) {
var _a = __read(CHARACTER_VALUES.find(function (_a) {
var _b = __read(_a, 1), val = _b[0];
return charValue >= val;
}) ||
CHARACTER_VALUES.find(function () { return 0; }), 2), val = _a[0], currentCase = _a[1];
}) || CHARACTER_VALUES[-1], 2), val = _a[0], currentCase = _a[1];
return "" + currentCase + encodeChar(charValue - val);
}
function encode(value) {
Expand All @@ -66,9 +65,9 @@ function decode(value) {
var _a = __read(CHARACTER_VALUES.find(function (_a) {
var _b = __read(_a, 2), _ = _b[0], em = _b[1];
return em == character;
}), 2), value = _a[0], emoji = _a[1];
}) || [-1, ""], 2), value = _a[0], emoji = _a[1];
if (!emoji) {
throw TypeError("Invalid bottom text: '" + value + "'");
throw new TypeError("Invalid bottom text: '" + character + "'");
}
return value;
})
Expand Down
2 changes: 1 addition & 1 deletion dist/bottomify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};
83 changes: 83 additions & 0 deletions dist/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var yargs = __importStar(require("yargs"));
yargs
.scriptName("Bottom translator [JavaScript] 0.3.0")
.version("0.3.0")
.usage("$0 <cmd> [args]")
.command("$0", "Nadir <[email protected]>\nFantastic (maybe) CLI for translating between bottom and human-readable text", function (yargs) {
yargs
.option("bottomify", {
type: "boolean",
default: false,
description: "Translate text to bottom",
alias: "b",
})
.option("regress", {
type: "boolean",
default: false,
description: "Translate bottom to human-readable text (futile)",
alias: "r",
})
.positional("input", {
type: "string",
default: "",
description: "Input file [Default: stdin]",
alias: "i",
})
.positional("output", {
type: "string",
default: "",
description: "Output file [Default: stdout]",
alias: "o",
})
.check(function (argv) {
if ((!argv._.length && !argv.input) ||
(argv._.length && argv.input)) {
throw new Error("Error: Either input text or the --input options must be provided.");
}
if (argv.bottomify && argv.regress) {
throw new Error("Error: must not pass more than one of the following: --bottomify --regress");
}
return true;
});
}, function (argv) {
var bottomify = require("./bottomify");
var fs = require("fs");
function getText() {
if (argv._.length) {
return argv._[0].toString();
}
if (argv.input) {
return fs.readFileSync(argv.input, "utf8").toString();
}
}
function write(text) {
if (argv.output) {
fs.writeFileSync(argv.output, Buffer.from(text));
}
else {
console.log(text);
}
}
if (argv.bottomify) {
write(bottomify.encode(getText()));
}
else if (argv.regress) {
try {
write(bottomify.decode(getText()));
}
catch (err) {
console.error(err.toString());
}
}
})
.help().argv;
Loading

0 comments on commit 709c0f7

Please sign in to comment.