-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tsc errors; raise TypeError on decode; CLI
- Loading branch information
Showing
11 changed files
with
2,555 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.