diff --git a/.npmignore b/.npmignore index b7865f0..012a3cd 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1 @@ index.js -test.js diff --git a/create-card.js b/create-card.js index c910aa2..669735e 100644 --- a/create-card.js +++ b/create-card.js @@ -1,5 +1,4 @@ const fetch = require("node-fetch"); -const fs = require("fs"); const path = require("path"); const { createCanvas, loadImage, registerFont } = require("canvas"); diff --git a/package-lock.json b/package-lock.json index 85a436f..6feb1e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "shit", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index dee9355..9b83481 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,13 @@ { "name": "xiv-character-cards", - "version": "1.0.0", + "description": "API to create fancy cards for FFXIV characters based on their Lodestone data, hosted at https://ffxiv-character-cards.herokuapp.com.", + "version": "1.1.0", "main": "create-card.js", "license": "MIT", + "keywords": [ + "ffxiv", + "xivapi" + ], "scripts": { "start": "node index.js", "dev": "nodemon index.js" diff --git a/readme.md b/readme.md index d890207..39197a5 100644 --- a/readme.md +++ b/readme.md @@ -32,4 +32,45 @@ The API will reply with its status, and in case of success, the URL to the final ## Using in your application -You can use the ``create-card.js`` file in any NodeJS project. It will return a PNG-buffer for you to use in your bot or application.
Check ``index.js`` for usage examples. +``` +yarn add xiv-character-cards +# or +npm i xiv-character-cards +``` + +You will receive a PNG-buffer for you to use in your bot or application.
Check ``index.js`` for other usage examples. + +### Example + +```js +const { CardCreator } = require("xiv-character-cards"); +const fs = require("fs"); + +const card = new CardCreator(); +const lodestoneid = "13821878"; + +function example(cb) { + card.ensureInit() + .then( + () => card.createCard(lodestoneid), + (reason) => cb("Init failed: " + reason, null) + ) + .then((image) => + cb(null, { + binary: { + image: image, + }, + }) + ) + .catch((reason) => cb("createCard failed: " + reason, null)); +} + +example((err, response) => { + const buffer = response.binary.image; + fs.writeFileSync(`./${lodestoneid}.png`, response.binary.image, (err) => { + if (err) { + console.log(err); + } + }); +}); +``` diff --git a/test.js b/test.js deleted file mode 100644 index 9ed6e3e..0000000 --- a/test.js +++ /dev/null @@ -1,18 +0,0 @@ -const fs = require("fs"); -const createCard = require("./create-card").createCard; - -createCard("9575452", (png) => { - const data = png.replace(/^data:image\/\w+;base64,/, ""); - const buf = Buffer.from(data, "base64"); - fs.writeFile('test.png', buf, (err) => { - console.log(err) - }) - }); - -createCard("13821878", (png) => { - const data = png.replace(/^data:image\/\w+;base64,/, ""); - const buf = Buffer.from(data, "base64"); - fs.writeFile('image.png', buf, (err) => { - console.log(err) - }) -});