2.0.5 • Published 19 days ago

sxcu.api v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
19 days ago

sxcu.api

Node.js library to interact with the sxcu.net API. (A cli is also included!)

sxcu.api was created to allow any developer of any skill set to easily create images, links, etc on sxcu.net without the hassle of learning the sxcu.net documentation directly.

This module has 0 dependencies. (excluding dev) Check for yourself!

Links

sxcu.api: Docs / Github / npm

sxcu.net: Website / API Docs / Discord / Donate

Updating to v2.0.0 from v1.x.x

The guide for doing so can be found here.

Installation

You can install sxcu.api using npm.

npm install sxcu.api

Example Usage

Here is an example of uploading a file.

// Import the package.
import * as sxcu from 'sxcu.api';

// Set the request user agent to the default.
// This will be done for you on the first request if you don't do it yourself.
sxcu.UserAgent.useDefault();

// Upload the file and log the response.
sxcu.uploadFile('image.png')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

In v2.0.0 we made the switch to ESM and TypeScript. However, we still support CommonJS.

// Use CommonJS's require method.
const { uploadFile, UserAgent, categorizeImports } = require('sxcu.api');

UserAgent.useDefault();

uploadFile('your-img')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

If you preferred categorized imports, then you can use categorizeImports. This works with ESM and CommonJS.

// Import the package.
import { categorizeImports } from 'sxcu.api';

// Categorize imports.
const sxcu = categorizeImports();

// Set the request user agent to the default.
sxcu.userAgent.useDefault();

// Upload the file and log the response.
sxcu.files
    .uploadFile('image.png')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

Respecting rate limits has been made extremely easy, all you need to do is enable the request queue.

// Import methods.
import { toggleRequestQueue } from 'sxcu.api';

// Enable the request queue.
toggleRequestQueue(true, true);

Need to make a custom request? It's pretty simple as well. The request method allows you to make requests that respect rate limits as well (as long as toggleRequestQueue is used beforehand).

// Import methods.
import { request, toggleRequestQueue } from 'sxcu.api';

// Enable the request queue.
toggleRequestQueue(true, true);

// Create your own request.
const response = await request({
    type: 'GET',
    statusErrors: [400, 429],
    baseUrl: 'https://sxcu.net/api/',
    path: `files/abc123`,
}).catch((error) => {
    throw resolveError(error);
});

Contributors

2.0.5

19 days ago

2.0.4-fix

20 days ago

2.0.4

20 days ago

2.0.3

1 month ago

2.0.2

1 month ago

2.0.1

2 months ago

2.0.0

2 months ago

1.2.5

11 months ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago