Skip to content

Commit

Permalink
Merge pull request #2 from TheRealBarenziah/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TheRealBarenziah authored Aug 17, 2020
2 parents c01ad0a + 2449995 commit 9685b88
Show file tree
Hide file tree
Showing 21 changed files with 7,288 additions and 261 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
.env
/lib
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 80,
"trailingComma": "all",
"singleQuote": false,
"semi": true,
"tabWidth": 2,
"useTabs": false
}
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- lts/*
install: npm install
script: npm run build && npm run test
env:
secure: lzEN89Zt8Bbz8TZKXt7fqkvQ/+uhTeAQiWQt73Goo+5v2pA62/zdMvEqoXo8gmMXL5X4ixbd4frhqA8n0GShsQBYWrEZilzc/bvuMV2scFRl1ALfdY5ygIXfkReFpfeIvNlJgxl9q/mBPRyeHkDWF3oLyAFrXTOO5EHToLUHA3aL15ZGRwiuSY1iDY53YNiCQ32OUK7TYfszXdBsL0TWpPKetV8b4JBeu/51nkQ9SoXe95PwIGBficMsyUoQ/cDLiNOmFwCpfxogm2ZUwPS7YTghPci98oW0wtFlEq76d4Cdg6wwSJmh9LOZdbYgi8u6kZRcPme1B3/h4W8I7rW01X0TqPtnAOXxpVkySXMqIIdNPgsHAs20OcyaN1IvHlHCs4aeU7jLhhKO2ThS4gIOiotV77sMNQEbhXo9MP4DC9SeeXDPtd/b+pydl4kCii6bAe69IRo41J2FhT366kd8Ou9HsE0ABY8lYLKB+iJgYBFLEgY/vqtUVFAB0aopmotool891jhz3IdDgT713zeo0Pk7QPwssKB3/BQ6BmrsbRXJUNDwgPTIw/fOuQj0VL2PMXKDVNIHjwitc6b48FckaNW/tRau3POhS0yAcYnyC+EnHqF1dDmQVicT1LCPSES0sDffJqFFRRbS2E7EEJ3+dXZrKhDLwmaS3RpoVnmq4kQ=
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 1.1.0

Module overhaul:
Seeing some people found this module useful made me glad, so I decided to give it some love.

- Becomes dependency-free
The respectable `request` module was the only external dependency, but now that's unsupported, as `npm install` spams everytime, it's problematic.
While I could have replaced it with Axios, I preferred reinventing that wheel using standard node `https`. It should hold for the years to come.

- TypeScript support
TypeScript is all the rage and I'm still in the process of learning it. That's why I thought it was interesting to make this module TS compatible, **without breaking compatibility** for the `require();` users.

- Better integration for VSCode
I've discovered JSDoc since then. It should benefit even non-TypeScript users.

- Change code style
I have semi colons everywhere except in this little module. Fixed that. Long live semi colons :)

- Upgraded file architecture & CI
[This is the resource](https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c) that guided me through the TS/Jest stack, it was an interesting adventure.
I made my best to ensure this update won't break anything for you, but if it is the case, please open an issue :)

Todo:
Write more in CONTRIBUTING.md so this module remains easy to fork & tweak. It may look more bloated than before, but I'm convinced decent documentation should fix it.

Making .mjs import work. Hopefully soon
Supporting browsers (afterall why not)
Supporting passing filename parameter
Supporting arrays (in the very bottom of the list tbh)

# 1.0.1

Fix README

# 1.0.0

Replace `var` and `function` with proper ES6 syntax & update README
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# tl;dr

- Clone project
- `npm i`
- compile the code in `src` into `lib` folder: `npm run build`
- run the tests defined in `src/__tests__`: `npm run test`
- typical combo while tweaking: `npm run build && npm run test`

See more scrpits in package.json

If you don't know the purpose of some config files, [this excellent resource](https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c) should guide you through.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# imgbb-uploader
Lightweight Nodejs module to upload local pictures files to imgbb API and get display URLs in response.

Lightweight Nodejs module to upload local pictures files to imgbb API and get display URLs in response.
Primary use is letting imgBB handle the hosting & serving of images.

[![https://nodei.co/npm/imgbb-uploader.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/imgbb-uploader.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/imgbb-uploader)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Known Vulnerabilities](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader/badge.svg?targetFile=package.json)](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader?targetFile=package.json)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Build Status](https://travis-ci.org/TheRealBarenziah/imgbb-uploader.svg?branch=master)](https://travis-ci.org/TheRealBarenziah/imgbb-uploader)

## Compatibility:

## Compatibility:
**Node >= 8** ( [this module uses async/await](https://node.green/) )
*Care: this module uses `fs` under the hood. It means it WON'T work outside the node environment !*
*To upload pictures from your frontend please check the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) instead*
_Care: this module uses `fs` under the hood. It means **it WON'T work outside the node environment !**_
_To upload pictures from your frontend please check the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) instead_

## Install

`npm install imgbb-uploader`

## Use
- I) [Get a free API key from imgbb](https://api.imgbb.com/) ( estimated time : ~1 minute )

- I) [Get a free API key from imgbb](https://api.imgbb.com/) ( estimated time ~1 minute )
- II) (facultative) [Put that in an environment variable](https://www.npmjs.com/package/dotenv)
- III) **imgbbUploader takes *exactly two* String arguments** : your API key, and the absolute path of your image :
- III) **imgbbUploader takes _exactly two_ String arguments** : your API key, and the absolute path of your image :

```
var imgbbUploader = require('imgbb-uploader');
Expand All @@ -27,6 +33,7 @@ imgbbUploader("your-imgbb-api-key-string", "home/absolute/path/to/your/image/ima
```

## `.then(response => console.log(response))` output example :

```
{
id: '5jKj6XV',
Expand Down Expand Up @@ -59,21 +66,23 @@ This async function returns a promise, so this is normal :
`console.log(imgbbUploader(myKey, myPath)) // output : Promise { <pending> }`
Your data is available in `.then(response => response)` as shown above.

**This module is ~20 lines long & totally unlicensed: to better fit your need, feel free to edit !**
**This module is tiny & totally unlicensed: to better fit your need, feel free to fork !**
[Basic instructions for tweaking](https://github.com/TheRealBarenziah/imgbb-uploader/blob/master/CONTRIBUTING.md)

## Learn more
This module doesn't support array uploads. For heavy duty, you'll probably have to work with [fs.readdir](https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback) and [async forEach](https://www.npmjs.com/package/async-foreach) (you may also be interested in [path](https://nodejs.org/api/path.html#path_path) ).

This module doesn't support array uploads. For heavy duty, you'll probably have to work with [fs.readdir](https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback) and [async forEach](https://www.npmjs.com/package/async-foreach) (you may also be interested in [path](https://nodejs.org/api/path.html#path_path) ).

For example, you can create a `baseDir.js` file wherever it suits you:

```
// baseDir.js
const path = require('path');
const dirPath = path.join(__dirname);
module.exports = dirPath;
```

Then you can require this file elsewhere and use something like `path.join(myDirpath, "subfolder", subsubfolder)` to dig into directories programmatically. Once there, you can f.e. `fs.readdir` and iterate `forEach` file of that directory.
See `fs` documentation and Stack Overflow for more inspiration on the matter.
See `fs` documentation and Stack Overflow for more inspiration on the matter.

## Changelog
0.2.1 => 1.0.0 (Replace `var` and `function` with proper ES6 syntax & update README)
1.0.0 => 1.0.1 (Fix README)
[CHANGELOG](https://github.com/TheRealBarenziah/imgbb-uploader/blob/master/CHANGELOG.md)
28 changes: 0 additions & 28 deletions index.js

This file was deleted.

9 changes: 9 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"verbose": false,
"setupFiles": ["dotenv/config"]
}
Loading

0 comments on commit 9685b88

Please sign in to comment.