open-index/open-npm huggingface dataset:
npm package: @floss/bounce
Description: Lets you build chained encoder/decoder functions.
Author: Carl Viktor Svensson
Latest version: 0.1.2

# @floss/bounce

An implementation of the _command design pattern_. Takes an arbitrary list of undoable actions and combines them into one undoable action.

## Installation

```bash
yarn add @floss/bounce
```

```bash
npm install @floss/bounce
```

## Usage

```javascript
import bounce from "@floss/bounce";
const action = bounce([
  {
    apply: (x) => x + 1,
    restore: (y) => y - 1,
  },
  {
    apply: (x) => x * 2,
    restore: (y) => y / 2,
  },
]);
console.log(action.apply(1)); // => 4
console.log(action.restore(4)); // => 1
```

## Example

We're going to construct a module that converts any input to to base64.

**# 1:** Define two objects, each implementing an `apply()` and a `restore()` method. Anything that `apply()` does must be undone by `restore()`.

```javascript
const ToJson = {
  apply: (value) => JSON.stringify(value),
  restore: (value) => JSON.parse(value),
};
const ToBase64 = {
  apply: (value) => Buffer.from(value, "utf8").toString("base64"),
  restore: (value) => Buffer.from(value, "base64").toString("utf8"),
};
```

**# 2:** Create a Bounce instance and try it out!

```javascript
const encoder = bounce([ToJson, ToBase64]);

const encoded = bounce.apply({hello: 10});
// => eyJoZWxsbyI6MTB9
const restored = bounce.restore(encoded);
// => {hello: 10}
```
npm package: @floss/sleep
Description: Synchronous and asynchronous sleep(), with zero dependencies.
Author: Carl Viktor Svensson
Latest version: 0.1.1

# @floss/sleep

Zero dependencies, Promise-based, sleep utility function. And a synchronous, thread-blocking version.

## Installation

```bash
yarn add @floss/sleep
npm -i @floss/sleep
```

## Usage

Simply call `sleep()`, specifying the number of milliseconds to wait. `sleep()` returns a Promise that resolves to `void` when the specified time has passed.

```javascript
import sleep from "@floss/sleep"

;(async () => {
  // do something
  // sleep for 10 seconds
  await sleep(10000)
  // do something else
})
```

Here's a demonstration of blocking vs. non-blocking Javascript, using `sleep()` aswell as the synchronous (blocking) function named `paralyze()`.

```javascript
import {sleep, paralyze} from "@floss/sleep";

// Setup interval and keep ID.
const id = setInterval((o) => console.log(++o[0]), 0, [0]);

// The asyncronous sleep shouldn't affect the
// timer. But after 2 seconds the timeout has
// been reached...
sleep(2000).then(() => {

  // ... and the synchronous function is called,
  // leading to complete silence for 2 seconds.
  paralyze(2000);

  // And now, let's wait for another 2 seconds
  // asynchronously. The thread is no longer
  // blocked, so our interval is now allowed to
  // proceed.
  sleep(2000).then(() => clearInterval(id));

});
```
npm package: @floss/yolo
Description: Does it throw an error? I don't know. YOLO.
Author: Carl Viktor Svensson
Latest version: 0.1.0

# @floss/yolo

Checklist to see if this is for you:

1. I want to run some code
2. I give no less than zero nasty words about any errors
3. Give me whatever is returned or keep quiet

```javascript
import yolo from "@floss/yolo";
const response = yolo(function () {
  let result;
  // here lies some dark stuff...
  return result
});
console.log(response); 
// Alt 1. undefined (if an error was thrown)
// Alt 2. anything (if your code was somehow error-free)
```