open-index/open-npm huggingface dataset:
npm package: @opdime/bus
Description: A JavaScript implementation of an Event-Bus.
Author: Jörn Neumeyer
Latest version: 0.2.1

# Bus-JS
---
Bus-JS is a simple library which offers a simple implementation of an event bus to structure your code around the publish-subscribe pattern.
The following code snippets show, what functionality the library offers, and how it should be used.

### Bus
A `Bus` is an object to which a function may subscribe, unsubscribe, and which can publish data to its subscribers. So, the usage of a `Bus` may look as follows:
```javascript
const { Bus } = require('@opdime/bus');

const bus = new Bus();

function someSubscriber(message) {
  console.log('bus-message payload:', message.payload);
}

bus.subscribe(someSubscriber);

bus.publish({
  payload: 'a bus message!'
});
```

A `Bus` subscriber will receive an `IBusMessage` as its first argument. Such a message consists of a `payload` and an optional `channel`. The exact TypeScript definition of an `IBusMessage` object looks as follows:

```typescript
export interface IBusMessage {
  readonly channel?: string;
  readonly payload: any;
}
```

The `publish` method of the `Bus` expects an `IBusMessage` to be passed as its only argument. That exact message is then going to be passed to each of the subscribers of the `Bus`. Note that you should not modify the message, because it is going to be the same referenced object for each subscriber!

Each of the methods of a `Bus` returns the instance on which the method has been called. This enables you to set up a multitude of subscribers for a `Bus` in one chained call.

### BusManager
The `BusManager` makes it easy to use multiple `Bus`es in your application which are bound to specific channels.

##### `BusManager.getChannelBus(channel)`
With this method, the `BusManager` will may the `Bus` which has been created for this channel. Note that this function potentially return undefined if no bus is registered on the given channel!

##### `BusManager.channel(channel)`
This method guarantees to return a `Bus`. In case you want to get the `Bus` of a channel which has not been registered, it will be created.

##### `BusManager.publish(message)`
This method accepts an object which implements the interface `IBusMessage`. The provided message is going to be sent to each of the global subscribers. In case a channel has been defined in the message, that provided channel bus will then send the message on to its subscribers.
npm package: @opdime/delay
Description: A Promise wrapper for setTimeout.
Author: Jörn Neumeyer
Latest version: 0.4.1


# Delay-JS

---
Delay-JS is a library which enables you to delay functions, iterables, iterators, and generators.
__Note!__ Asynchronous generators are not supported yet but will be supported soon.

#### `delay(milliseconds)`

Creates a `Promise` which resolves earliest after the given milliseconds.

All of the following delay functions can also be curried. An example for this currying will be shown in the documentation for the function `delayFunction`.

#### `delayFunction(milliseconds[, func])`

Creates a new function which returns a `Promise` that resolves earliest after the given milliseconds.

```javascript
import { delayFunction } from '@opdime/delay';
// invoking the delayFunction directly
const logAfterOneSecond = delayFunction(1000, console.log);

logAfterOneSecond('some text');

// curry delayFunction
const delayFunctionForOneSecond = delayFunction(1000);
// then create functions which are delayed for one second
const logAfterOneSecond = delayFunctionForOneSecond(console.log);

logAfterOneSecond('some text');
```

#### `delayGenerator(milliseconds[, generator])`

Creates a new async generator function from the given generator function. __Each element__ of the new generator will be resolved after the given milliseconds.

```typescript
import { delayGenerator } from '@opdime/delay';
function someGenerator*() {
  yield 1;
  yield 2;
  yield 3;
}

const someDelayedGenerator(200, someGenerator);

// each iteration will take 200ms
for await (const value of someDelayedGenerator()) {
  console.log(value);
}
// reached after at least 600ms (200ms for each generator item)
```

#### `delayIterable(milliseconds[, iterable])`

Creates the same output as `delayGenerator`, but expects an iterable instead of a generator.

#### `delayThrow(milliseconds[, value])`

Returns a `Promise` which will be rejected after the given time. The provided value is going to be passed to the catch statement.

```typescript
import { delayThrow } from '@opdime/delay';

delayThrow(200)
  .then(() => console.log('everything is fine'))
  .catch(() => console.log('actually not!'));
```

#### `delayValue(milliseconds[, value])`

Returns a `Promise` which resolves to the given value after the given milliseconds have passed.
npm package: @opdime/mysql-promises
Description: A promise wrapper around the mysql module.
Author: Jörn Neumeyer
Latest version: 0.1.0

# MySQL-Promises-JS
---
MySQL-Promises-JS is a simple wrapper arount the __mysql__ package, which earases the callbacks from the API and replaces them with `Promise`s.

```javascript
const { MysqlPromises } = require('@opdime/mysql-promises');
// or
import { MysqlPromises } from '.';

const connection = MysqlPromises.createConnection({
  database: 'example',
  host: 'localhost',
  password: 'root',
  user: 'root'
});

connection
  .connect()
  .then(x => x.query('SELECT * FROM tbl_user;'))
  .then(({ result }) => console.log(result))
  .then(() => connection.end())
  .catch(e => console.error(e));
```

#### `static MysqlPromises.createConnection(config = undefined)`
Creates a new `MysqlPomises` instance. The configuration is the same as usually used with the __mysql__ package.

#### `async MysqlPromises.beginTransaction()`
Starts a new transaction.

#### `async MysqlPromises.commit()`
Commits the current transaction.

#### `MysqlPromises.config()`
Exposes the underlying configuration of the `Connection` instance.

#### `async MysqlPromises.connect()`
Initializes the connection to the configured endpoint. This method returns a `Promise` which contains the connected `MysqlPromises` instance.

#### `MysqlPromises.destroy()`
Closes the current `Connection` instance immediatly, terminating all pending tasks.

#### `async MysqlPromises.end()`
Closes the current `Connection` instance soft. So, all pending tasks will be executed.

#### `MysqlPromises.getRawConnection()`
Exposes the Exposes the underlying `Connection` instance.

#### `async MysqlPromises.query(query, params = [])`
Executes the provided query. The result is going to be an object of the type `QueryResult` which has the following TypeScript definition:
```typescript
export type QueryResult<T> = Promise<{ fields?: Array<FieldInfo>; result: T }>;
```
As shown in the code above, the result may be of any type. In case you use TypeScript, you can also specify the type of the result. So, a query call in TypeScript could look like this:
```typescript

interface IUser {
  username: string;
  dataOfBirth: Date;
}

connection
  .connect()
  .then(x => x.query<Array<IUser>>('SELECT * FROM tbl_user;'))
  .then(({ result }) => console.log(result))
  .then(() => connection.end())
  .catch(e => console.error(e));
```

#### `async MysqlPromises.rollback()`
Performs a rollback on the current transaction.
npm package: @opdime/range
Description: A JavaScript implementation of Python's range function.
Author: Jörn Neumeyer
Latest version: 0.1.1

# Range-JS
---
Range-JS offers a similar implementation to Python's `range` function. It offers the ability to generate numeric arrays in a variety of ways. The numeric arrays returned by this function will always only contain integers and it never returns floating point numbers.
So let's have a look at some examples:

### Importing
Range-JS has a names export `range`. That results in the following ways of importing the function:
```javascript
const range = require('@opdime/range').range;
// or
const { range } = require('@opdime/range');
// or
import { range } from '@opdime/range';
```
The function accepts one to three arguments and therefore it may be called in to following three ways:
#### range(limit)
By creating a range in that manner, the range will go from 0 to the given limit. In that case, the limit is an __exclusive__ value, so it nicer to use it with arrays.
```javascript
const r = range(5);
// evaluates to:
// [0, 1, 2, 3, 4]
```
#### range(start, limit)
By creating a range in that manner, the range will go from the start to the given limit. In that case, the start is an __inclusive__ value, al well as the limit!
```javascript
const r = range(3, 5);
// evaluates to:
// [3, 4, 5]
```
#### range(start, limit, step)
By creating a range in that manner, the range will go from the start to the given limit. In that case, the start is an __inclusive__ value, al well as the limit.
Also, the resulting array will only contain multiples of the step, offset by the value of the start.
```javascript
const r = range(0, 6, 2);
// evaluates to:
// [0, 2, 4, 6]
```