# u3-utils-rn

> U3 utils

Latest version **0.0.4** (published 2018-11-29) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install u3-utils-rn
pnpm add u3-utils-rn
yarn add u3-utils-rn
bun add u3-utils-rn
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2018-11-29 |
| First published | 2018-11-29 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 20 |
| Unpacked size | 141.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | benyasin |
| Maintainers | robin001 |

## Links

- npm: https://www.npmjs.com/package/u3-utils-rn
- Repository: https://github.com/ultrain-os/u3-utils-rn
- Homepage: https://github.com/ultrain-os/u3-utils-rn#readme
- Issues: https://github.com/ultrain-os/u3-utils-rn/issues
- npm.io page: https://npm.io/package/u3-utils-rn

## Dependencies (20)

- [bigi](https://npm.io/package/bigi.md) ^1.4.2
- [bip39](https://npm.io/package/bip39.md) ^2.5.0
- [clone](https://npm.io/package/clone.md) ^2.1.1
- [ecurve](https://npm.io/package/ecurve.md) ^1.0.5
- [bs58-rn](https://npm.io/package/bs58-rn.md) ^0.0.3
- [is-node](https://npm.io/package/is-node.md) 1.0.2
- [binaryen](https://npm.io/package/binaryen.md) ^37.0.0
- [fcbuffer](https://npm.io/package/fcbuffer.md) ^2.2.1
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [bytebuffer](https://npm.io/package/bytebuffer.md) ^5.0.1
- [camel-case](https://npm.io/package/camel-case.md) ^3.0.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^1.0.1
- [create-hash](https://npm.io/package/create-hash.md) ^1.1.3
- [create-hmac](https://npm.io/package/create-hmac.md) ^1.1.6
- [randombytes](https://npm.io/package/randombytes.md) ^2.0.5
- [babel-runtime](https://npm.io/package/babel-runtime.md) 6.26.0
- [browserify-aes](https://npm.io/package/browserify-aes.md) ^1.0.6
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^4.4.0
- [lodash.isstring](https://npm.io/package/lodash.isstring.md) ^4.0.1
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1

## Recent versions

- 0.0.4 (latest) — 2018-11-29
- 0.0.3 — 2018-11-29
- 0.0.2 — 2018-11-29
- 0.0.1 — 2018-11-29

## README

# u3-utils-rn
sets of utilities for ultrain

* ecc
* test

## Installation

  ```sh
$ npm install u3-utils-rn
```

  ```javascript
var U3Utils = require('u3-utils-rn/src');
```

## wait()

Waits until the given time has expired and then resolves.

  ```javascript
it('should wait', async() => {
    await U3Utils.test.wait(200);
    console.log('200 ms is over');
});
```

## waitUntil()

Waits until the given predicate-function returns true. Throws if the optional timeout has passed before.

  ```javascript
it('should wait until server is online', async() => {
    const checkServer = async() => {
        try{
            await fetch('http://example.com/api/');
            return true;
        }catch(){
            return false;
        }
    };
    await U3Utils.test.waitUntil(checkServer);
});
```

With timeout:

  ```javascript
it('should wait until server is online (maxtime: 1000ms)', async() => {
    const checkServer = async() => {
        try{
            await fetch('http://example.com/api/');
            return true;
        }catch(){
            return false;
        }
    };
    await U3Utils.test.waitUntil(checkServer, 1000);
});
```

## assertThrows()

Async-Form of [assert.throws](https://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). Asserts that the given function throws with the defined error, throws if not.

```javascript
// with error-type
it('should throw because route does not exist', async() => {
    const getServerVersion = async() => {
        const response = await fetch('http://example.com/foobar/');
        return response;
    };
    await U3Utils.test.assertThrows(
        () => getServerVersion(),       // function that throws (required)
        Error                   // Error-type           (optional)
    );
});

// with error-text-flag
it('should throw because route does not exist', async() => {
    const pingServer = async() => {
        try{
            await fetch('http://example.com/foobar/');            
        }catch(err){
            throw new Error('route not reachable');
        }
    };
    await U3Utils.test.assertThrows(
        () => pingServer(),       // function that throws                                    (required)
        Error,                    // Error-type                                              (optional)
        'reachable'               // text-flag, throw if error-message does not include this (optional)  
    );
});

// assertThrows returns the error
it('should have the custom error-property', async() => {
    const throwingFunction = async()=>{
        const error = new Error('error message');
        error.foo = 'bar';
        throw error;
    }
    const thrown = await U3Utils.test.assertThrows(
        () => pingServer(),       // function that throws                                    (required)
        Error,                    // Error-type                                              (optional)
        'message'               // text-flag, throw if error-message does not include this (optional)  
    );
    assert.equal(thrown.foo, 'bar');
});
```

## isPromise()
Returns true if the given value is a `Promise`;

```javascript

const is = U3Utils.test.isPromise(myAsyncFunction()); // true
const is = U3Utils.test.isPromise('foobar'); // false

```

## promisify

Transforms the given value to a promise if it was no promise before.

  ``` javascript

const ensurePromise = U3Utils.test.isPromise(maybeAsyncFunction());

// now you are sure this is a promise
ensurePromise.then(/* ... */)

```

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