# dpaste-ts

> Nodejs wrapper for dpaste.com written using Typescript

Latest version **3.0.0** (published 2023-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install dpaste-ts
pnpm add dpaste-ts
yarn add dpaste-ts
bun add dpaste-ts
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-11-28 |
| First published | 2021-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18 |
| Dependencies | 0 |
| Unpacked size | 42.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | MRDGH2821 |
| Maintainers | mrdgh2821 |
| Keywords | dpaste, pastebin, wrapper |

## Links

- npm: https://www.npmjs.com/package/dpaste-ts
- Repository: https://github.com/MRDGH2821/dpaste-ts
- Homepage: https://github.com/MRDGH2821/dpaste-ts#readme
- Issues: https://github.com/MRDGH2821/dpaste-ts/issues
- Funding: https://ko-fi.com/mrdgh2821
- npm.io page: https://npm.io/package/dpaste-ts

## Recent versions

- 3.0.0 (latest) — 2023-11-28
- 2.0.0 — 2022-11-05
- 1.0.4 — 2021-11-20
- 1.0.3 — 2021-11-19
- 1.0.2 — 2021-11-19
- 1.0.1 — 2021-11-19
- 1.0.0 — 2021-11-19

## README

# dpaste-ts

[![codecov](https://codecov.io/gh/MRDGH2821/dpaste-ts/branch/master/graph/badge.svg?token=6LKVVGGYN2)](https://codecov.io/gh/MRDGH2821/dpaste-ts)

[![NPM](https://nodei.co/npm/dpaste-ts.png)](https://npmjs.org/package/dpaste-ts)

Nodejs wrapper for [dpaste.com](https://dpaste.com/) written using Typescript.
Creates & Gets pastes anonymously.

Now with Authentication support!

## Usage

The functions are [promise](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/promise) based. Use them inside `async` functions or you may use `.then().catch()`.

All functions have an internal delay of 1 second. This is to prevent abuse of [dpaste.com API](https://dpaste.com/api/v2/)

### Disable delay

Set the environment variable as follows -

```sh
DPASTE_DISABLE_DELAY = true
```

**Note:** if the rate of requests exceeds 1 request per second, then you will be blocked from API to create new pastes. Same applies for reading pastes.

### Authentication

_Read more [here](https://dpaste.com/api/v2/) under Authentication section._

Generate an API token key from your [dashboard](https://dpaste.com/dashboard).

Set it into your environment with the variable name as `DPASTE_API_TOKEN`

### Import

```js
const { createPaste, getRawPaste } = require('dpaste-ts'); // in CJS style

import { createPaste, getRawPaste } from 'dpaste-ts'; // in ESM style
```

### Create Paste

Returns URL of dpaste.

There are 5 arguments:

| Arguments   | Type   | Range/Limit                                             | Default values                                                      | Required? |
| ----------- | ------ | ------------------------------------------------------- | ------------------------------------------------------------------- | --------- |
| content     | string | `250,000 bytes`                                         | Not Applicable                                                      | `true`    |
| title       | string | First 100 characters                                    | date & time of paste creation in UTC                                | `false`   |
| syntax      | string | [Check here](https://dpaste.com/api/v2/syntax-choices/) | `'text'`                                                            | `false`   |
| expiry_days | number | `1` to `365`                                            | `7`                                                                 | `false`   |
| APIToken    | string | Not Applicable                                          | Value set in environment variable `DPASTE_API_TOKEN` or `undefined` | `false`   |

When inside async function:

```js
const options = {
  content: 'sample input',
  title: 'sample title',
  syntax: 'text',
  expiry_days: 10,
};

// Will return dpaste link when successful
let url = await createPaste(options);
console.log(url);
```

Using `.then()`

```js
// Will return dpaste link to console
createPaste(options).then(console.log);
```

### Get Raw Paste

Returns Raw data of dpaste.

There are 2 arguments:

| Arguments | Type   | Required? |
| --------- | ------ | --------- |
| url/id    | string | `true`    |
| APIToken  | string | `false`   |

You can either provide complete URL of the dpaste or the ID of the paste.

When inside async function:

```js
// Will return "sample input" as raw data
let rawData = await getRawPaste(url);
console.log(rawData);
```

Using `.then()`

```js
// Will return raw data to console
getRawPaste(url).then(console.log);
```

### Complete example

```js
const { createPaste, getRawPaste } = require('dpaste-ts');

const options = {
  content: 'sample input',
  title: 'sample title',
  syntax: 'text',
  expiry_days: 10,
  APIToken: 'qwerty12345ag',
};
// This will set the API token into environment variable
process.env.DPASTE_API_TOKEN = options.APIToken;

// This will **not** disable internal delay of 1 second. Set it to true if you wish to disable it.
process.env.DPASTE_DISABLE_DELAY = 'false';

// Use the below code snippet inside async functions to get the data.

// Will return dpaste link when successful
let url = await createPaste(options);
console.log(url);

// Will return "sample input" as raw data
let rawData = await getRawPaste(url);
console.log(rawData);

// Use the below snippets if you wish to use .then()
// Put .catch() to catch any potential errors

// Will return dpaste link to console
createPaste(options).then(console.log);

// Will return raw data to console
getRawPaste(url).then(console.log);
```

## Licence

[MIT](./licence)

---
_Source: https://npm.io/package/dpaste-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
