From 4bcfdb66e47baad4ec90fccf1e3cb675b2fd319e Mon Sep 17 00:00:00 2001 From: Jake Walker Date: Fri, 22 Mar 2019 19:46:33 +0000 Subject: [PATCH] Add 'from NPM' section and module docs --- .editorconfig | 9 ++++++++ README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a62086 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/README.md b/README.md index 531d258..5b0c889 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,34 @@ A CLI application for interacting with ttm.sh. -## Installation +*Although this is mainly a CLI application, there is also a [module](#3-module) that you can use in your own projects!* + + + +- [1. Installation](#1-installation) + - [1.1. From NPM](#11-from-npm) + - [1.2. From Source](#12-from-source) +- [2. Usage](#2-usage) + - [2.1. Shorten](#21-shorten) + - [2.2. Upload](#22-upload) +- [3. Module](#3-module) +- [4. Contributing](#4-contributing) + + + +## 1. Installation + +### 1.1. From NPM + +This method is recommended as there is less setup. + +```sh +npm install -g ttmsh +# now you can use the command 'ttmsh' +``` + +### 1.2. From Source -### From Source ```sh git clone https://tildegit.org/jakew/ttmsh-cli.git cd ttmsh-cli @@ -13,9 +38,9 @@ npm link # now you can use the command 'ttmsh' or 'node ./cli.js' or './cli.js' (only on nix) ``` -## Usage +## 2. Usage -### Shorten +### 2.1. Shorten You can either include the URL in your command: @@ -34,7 +59,7 @@ jakew@tilde:~$ ttmsh shorten *Note: You will be asked again if you pass in an invalid URL.* -### Upload +### 2.2. Upload Like with [shorten](#shorten), you can either include a file path in your command: @@ -51,6 +76,28 @@ jakew@tilde:~$ ttmsh upload √ https://ttm.sh/j0.txt ``` -## Contributing +## 3. Module + +You can also use the mini API wrapper in your application. Here's some example code on how to use it. + +```js +const ttmsh = require("ttmsh"); + +// upload a file to ttm.sh +ttmsh.do("upload", "/path/to/file/to/upload.txt").then((result) => { + console.log(`Here's your link: ${result}`); +}).catch((err) => { + console.error("Something went wrong.", err); +}); + +// shorten a link with ttm.sh +ttmsh.do("shorten", "https://example.com/this/is/a/long/url").then((result) => { + console.log(`Here's your link: ${result}`); +}).catch((err) => { + console.error("Something went wrong.", err); +}); +``` + +## 4. Contributing I'd love for people to add in new features and improve on my current work so feel free to open a pull request! \ No newline at end of file