diff --git a/README.md b/README.md index 1075981..d627176 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Prray -- "Promisified" Array, compatible with normal array, but comes with async > Prray aims to replace normal Array in some cases for convenience 😄😜 ```javascript -import { prray } from 'prray' -const prr = prray(['www.google.com', 'npmjs.org']) +import Prray from 'prray' +const prr = Prray.from(['www.google.com', 'npmjs.org']) const responses = await prr.mapAsync(fetch) ``` @@ -79,10 +79,10 @@ yarn add prray Prray is compatible with normal array. That means you can safely replace normal Array with Prray. And there are [a lots of unit tests](https://github.com/Bin-Huang/prray/tree/master/test) for prray to test compatibility with normal array. ```javascript -import { prray, Prray } from 'prray' +import Prray from 'prray' const arr = [1, 2, 3] -const prr = prray(arr) +const prr = Prray.from(arr) prr[0] // 1 prr[prr.length - 1] // 3 @@ -133,37 +133,21 @@ arr instanceof Prray // false ## Methods -### Package methods - -- [prray(array)](#prrayarray) -- [new Prray()](#new-prray) - -#### prray(array) - -The prray() method creates and returns a new Prray instance with every element in the array. - -```javascript -import { prray } from 'prray' - -const prr = prray([1, 2, 3]) -console.log(prr[0]) // 1 -``` - -#### new Prray() +### Class Prray The class `Prray`. You can think of it as class `Array`. ```javascript -import { Prray } from 'prray' +import Prray from 'prray' const p1 = new Prray() -const p2 = new Prray(1) -const p3 = new Prray('a', 'b') +const p2 = new Prray('a', 'b') +const p3 = Prray.from([1, 2, 3, 4]) -console.log(p3[0]) // 'a' +console.log(p2[0]) // 'a' ``` -> **Instead `new Prray()`, use methods `prray`, `Prray.from` or `Prray.of` if you want to create a new prray instance**. Because the class Prray is so compatible with class Array, some "weird" behaviors that exists in `new Array()` can also occurs: when you calling `new Array(1)`, you get `[ <1 empty item> ]` instead of expected `[ 1 ]`. +**Instead `new Prray()`, use `Prray.from` or `Prray.of` if you want to create a new prray instance**. Because the class Prray is so compatible with class Array, some "weird" behaviors that exists in `new Array()` can also occurs: when you calling `new Array(1)`, you get `[ <1 empty item> ]` instead of expected `[ 1 ]`. ### Static methods of Class Prray @@ -178,7 +162,7 @@ _Compatible with [`Array.from`](https://developer.mozilla.org/en-US/docs/Web/Jav The Prray.from() method creates a new, shallow-copied Prray instance from an array-like or iterable object. ```javascript -import { Prray } from 'prray' +import Prray from 'prray' const prr = Prray.from([1, 2, 3, 4]) ``` @@ -190,7 +174,7 @@ _Compatible with [`Array.of`](https://developer.mozilla.org/en-US/docs/Web/JavaS The Prray.of() method creates a new Prray instance from a variable number of arguments, regardless of number or type of the arguments. ```javascript -import { Prray } from 'prray' +import Prray from 'prray' const prr = Prray.of(1, 2, 3, 4) ``` @@ -200,7 +184,7 @@ const prr = Prray.of(1, 2, 3, 4) The Prray.isArray() method determines whether the passed value is a Prray instance. ```javascript -import { Prray } from 'prray' +import Prray from 'prray' Prray.isPrray([1, 2, 3]) // false Prray.isPrray(new Prray(1, 2, 3)) // true @@ -243,7 +227,7 @@ The provided async function is called on every element concurrently. - `concurrency` Number of concurrently pending promises returned by provided function. Default: `Infinity` ```javascript -const urls = prray([ +const urls = Prray.from([ /* urls */ ]) @@ -265,7 +249,7 @@ The provided async function is called on every element concurrently. - `concurrency` Number of concurrently pending promises returned by provided function. Default: `Infinity` ```javascript -const files = prray([ +const files = Prray.from([ /* filenames */ ]) @@ -281,7 +265,7 @@ _Think of it as an async version of method `reduce`_ The reduceAsync() method executes a async reducer function (that you provide) on each element of the prray, resulting in a single output value resolved by a promise. ```javascript -const productIds = prray([ +const productIds = Prray.from([ /* ids */ ]) @@ -298,7 +282,7 @@ _Think of it as an async version of method `reduceRight`_ The reduceRightAsync() method applies an async function against an accumulator and each value of the prray (from right-to-left) to reduce it to a single value. ```javascript -const productIds = prray([ +const productIds = Prray.from([ /* ids */ ]) @@ -315,7 +299,7 @@ _Think of it as an async version of method `find`_ The findAsync() method returns a promise resolved with the first element in the prray that satisfies the provided async testing function. ```javascript -const workers = prray([ +const workers = Prray.from([ /* workers */ ]) @@ -329,7 +313,7 @@ _Think of it as an async version of method `findIndex`_ The findIndexAsync() method returns a promise resolved with the index of the first element in the prray that satisfies the provided async testing function. Otherwise, it returns promise resolved with -1, indicating that no element passed the test. ```javascript -const workers = prray([ +const workers = Prray.from([ /* workers */ ]) const ix = await workers.findIndexAsync(checkHealth) @@ -349,7 +333,7 @@ The provided async function is called on every element concurrently. - `concurrency` Number of concurrently pending promises returned by provided function. Default: `Infinity` ```javascript -const filenames = prray([ +const filenames = Prray.from([ /* filenames */ ]) @@ -372,7 +356,7 @@ The provided async function is called on every element concurrently. - `concurrency` Number of concurrently pending promises returned by provided function. Default: `Infinity` ```javascript -const filenames = prray([ +const filenames = Prray.from([ /* filenames */ ]) @@ -389,7 +373,7 @@ _Think of it as an async version of method `sort`_ The sortAsync() method sorts the elements of a prray in place and returns a promise resolved with the sorted prray. The provided function can be an async function that returns a promise resolved with a number. ```javascript -const students = prray([/* ids */]) +const students = Prray.from([/* ids */]) const rank = await students.sortAsync((a, b) => { const scoreA = await getScore(a) @@ -409,7 +393,7 @@ The forEachAsync() method executes a provided async function once for each prray - `concurrency` Number of concurrently pending promises returned by provided function. Default: `Infinity` ```javascript -const emails = prray([ +const emails = Prray.from([ /* emails */ ]) await emails.forEachAsync(sendAsync) diff --git a/src/index.ts b/src/index.ts index d29ddf2..42b900a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,9 @@ * 2019-10-01 */ -import { Prray, prray } from './prray' +import Prray from './prray' -export { prray, Prray } +export default Prray + +module.exports = Prray +module.exports.default = Prray diff --git a/src/methods.ts b/src/methods.ts index 1af87f8..c698ec1 100644 --- a/src/methods.ts +++ b/src/methods.ts @@ -1,4 +1,4 @@ -import { Prray } from './prray' +import Prray from './prray' export async function mapAsync( arr: Prray, diff --git a/src/prray.ts b/src/prray.ts index 450452f..1a42ad2 100644 --- a/src/prray.ts +++ b/src/prray.ts @@ -3,7 +3,7 @@ import * as methods from './methods' // TODO: thisArg -export class Prray extends Array { +export default class Prray extends Array { static of(...args: T[]): Prray { return Prray.from(args) } @@ -197,10 +197,6 @@ export class Prray extends Array { } } -export function prray(arr: T[]): Prray { - return Prray.from(arr) -} - export function _ensurePrray(arr: T[]): Prray { if (arr instanceof Prray) { return arr diff --git a/src/prraypromise.ts b/src/prraypromise.ts index 50e14ff..fcc441b 100644 --- a/src/prraypromise.ts +++ b/src/prraypromise.ts @@ -1,4 +1,4 @@ -import { Prray } from './prray' +import Prray from './prray' export class PrrayPromise extends Promise> { constructor(executor: (resolve: (prray: Prray) => any, reject: (err: Error) => any) => any) { diff --git a/test/_ensurePrray.test.ts b/test/_ensurePrray.test.ts index 1429aac..eab5535 100644 --- a/test/_ensurePrray.test.ts +++ b/test/_ensurePrray.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { _ensurePrray, Prray } from '../src/prray' +import Prray, { _ensurePrray } from '../src/prray' test('_ensurePrray', async t => { const arr = new Array() diff --git a/test/compatibility.test.ts b/test/compatibility.test.ts index 31ea3da..8bbc77a 100644 --- a/test/compatibility.test.ts +++ b/test/compatibility.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { Prray } from '../src/prray' +import Prray from '../src/prray' test('Compatibility with array: indexing', async t => { const arr = [1, 2, 3, 4] diff --git a/test/concat.test.ts b/test/concat.test.ts index 4832693..89fe76a 100644 --- a/test/concat.test.ts +++ b/test/concat.test.ts @@ -1,25 +1,25 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray concat', async t => { - t.deepEqual(prray([1, 2]).concat([3, 4]), prray([1, 2, 3, 4])) - t.deepEqual(prray([1, 2]).concat([3, 4], [5, 6]), prray([1, 2, 3, 4, 5, 6])) - t.deepEqual(prray([1, 2]).concat(3, [4, 5]), prray([1, 2, 3, 4, 5])) - t.deepEqual(prray([[1]]).concat([2, [3]] as any), prray([[1], 2, [3]])) - t.deepEqual(prray([[1]]).concat(4 as any, [5, [6]] as any), prray([[1], 4, 5, [6]])) + t.deepEqual(Prray.from([1, 2]).concat([3, 4]), Prray.from([1, 2, 3, 4])) + t.deepEqual(Prray.from([1, 2]).concat([3, 4], [5, 6]), Prray.from([1, 2, 3, 4, 5, 6])) + t.deepEqual(Prray.from([1, 2]).concat(3, [4, 5]), Prray.from([1, 2, 3, 4, 5])) + t.deepEqual(Prray.from([[1]]).concat([2, [3]] as any), Prray.from([[1], 2, [3]])) + t.deepEqual(Prray.from([[1]]).concat(4 as any, [5, [6]] as any), Prray.from([[1], 4, 5, [6]])) - const prr = prray([1, 2]) + const prr = Prray.from([1, 2]) t.not(prr.concat([3, 4]), prr) // Immutable }) test('prraypromise concat', async t => { - t.deepEqual(await toPrrayPromise([1, 2]).concat([3, 4]), prray([1, 2, 3, 4])) - t.deepEqual(await toPrrayPromise([1, 2]).concat([3, 4], [5, 6]), prray([1, 2, 3, 4, 5, 6])) - t.deepEqual(await toPrrayPromise([1, 2]).concat(3, [4, 5]), prray([1, 2, 3, 4, 5])) - t.deepEqual(await toPrrayPromise([[1]]).concat([2, [3]] as any), prray([[1], 2, [3]])) - t.deepEqual(await toPrrayPromise([[1]]).concat(4 as any, [5, [6]] as any), prray([[1], 4, 5, [6]])) + t.deepEqual(await toPrrayPromise([1, 2]).concat([3, 4]), Prray.from([1, 2, 3, 4])) + t.deepEqual(await toPrrayPromise([1, 2]).concat([3, 4], [5, 6]), Prray.from([1, 2, 3, 4, 5, 6])) + t.deepEqual(await toPrrayPromise([1, 2]).concat(3, [4, 5]), Prray.from([1, 2, 3, 4, 5])) + t.deepEqual(await toPrrayPromise([[1]]).concat([2, [3]] as any), Prray.from([[1], 2, [3]])) + t.deepEqual(await toPrrayPromise([[1]]).concat(4 as any, [5, [6]] as any), Prray.from([[1], 4, 5, [6]])) - const prr = prray([1, 2]) + const prr = Prray.from([1, 2]) t.not(await toPrrayPromise(prr).concat([3, 4]), prr) // Immutable }) diff --git a/test/copyWithin.test.ts b/test/copyWithin.test.ts index 0c4f134..4906401 100644 --- a/test/copyWithin.test.ts +++ b/test/copyWithin.test.ts @@ -1,31 +1,31 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray copyWithin', async t => { const arr = [1, 2, 3, 4, 5] - const prr = prray([1, 2, 3, 4, 5]) + const prr = Prray.from([1, 2, 3, 4, 5]) t.is(prr.copyWithin(-2, 0), prr) - t.deepEqual(prr.copyWithin(-2, 0), prray(arr.copyWithin(-2, 0))) - t.deepEqual(prr.copyWithin(0, 3), prray(arr.copyWithin(0, 3))) - t.deepEqual(prr.copyWithin(0, 3, 4), prray(arr.copyWithin(0, 3, 4))) - t.deepEqual(prr.copyWithin(-2, -3, -1), prray(arr.copyWithin(-2, -3, -1))) + t.deepEqual(prr.copyWithin(-2, 0), Prray.from(arr.copyWithin(-2, 0))) + t.deepEqual(prr.copyWithin(0, 3), Prray.from(arr.copyWithin(0, 3))) + t.deepEqual(prr.copyWithin(0, 3, 4), Prray.from(arr.copyWithin(0, 3, 4))) + t.deepEqual(prr.copyWithin(-2, -3, -1), Prray.from(arr.copyWithin(-2, -3, -1))) t.is(prr.copyWithin(-2, -3, -1), prr) // mutable }) test('prraypromise copyWithin', async t => { const arr = [1, 2, 3, 4, 5] - const prr = prray([1, 2, 3, 4, 5]) + const prr = Prray.from([1, 2, 3, 4, 5]) t.is(await toPrrayPromise(prr).copyWithin(-2, 0), prr) - t.deepEqual(await toPrrayPromise(prr).copyWithin(-2, 0), prray(arr.copyWithin(-2, 0))) - t.deepEqual(await toPrrayPromise(prr).copyWithin(0, 3), prray(arr.copyWithin(0, 3))) - t.deepEqual(await toPrrayPromise(prr).copyWithin(0, 3, 4), prray(arr.copyWithin(0, 3, 4))) - t.deepEqual(await toPrrayPromise(prr).copyWithin(-2, -3, -1), prray(arr.copyWithin(-2, -3, -1))) + t.deepEqual(await toPrrayPromise(prr).copyWithin(-2, 0), Prray.from(arr.copyWithin(-2, 0))) + t.deepEqual(await toPrrayPromise(prr).copyWithin(0, 3), Prray.from(arr.copyWithin(0, 3))) + t.deepEqual(await toPrrayPromise(prr).copyWithin(0, 3, 4), Prray.from(arr.copyWithin(0, 3, 4))) + t.deepEqual(await toPrrayPromise(prr).copyWithin(-2, -3, -1), Prray.from(arr.copyWithin(-2, -3, -1))) t.is(await toPrrayPromise(prr).copyWithin(-2, -3, -1), prr) // mutable }) diff --git a/test/entries.test.ts b/test/entries.test.ts index 49a4250..19ac26f 100644 --- a/test/entries.test.ts +++ b/test/entries.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] -const p = prray(arr) +const p = Prray.from(arr) const pp = toPrrayPromise(arr) test('prray entries', async t => { diff --git a/test/every.test.ts b/test/every.test.ts index 71c999e..4045e48 100644 --- a/test/every.test.ts +++ b/test/every.test.ts @@ -1,11 +1,11 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isEven } from './test-utils' test('prray every', async t => { - t.is(prray([2, 4, 6]).every(isEven), true) - t.is(prray([1, 2, 3]).every(isEven), false) + t.is(Prray.from([2, 4, 6]).every(isEven), true) + t.is(Prray.from([1, 2, 3]).every(isEven), false) }) test('prraypromise every', async t => { @@ -15,7 +15,7 @@ test('prraypromise every', async t => { test('prray every compatibility 1', async t => { const func = sinon.fake(() => true) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) prr.every(func) t.is(func.called, true) @@ -36,7 +36,7 @@ test('prray every compatibility 1', async t => { test('prray every compatibility 2', async t => { const func = sinon.fake(() => false) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) prr.every(func) t.is(func.callCount, 1) @@ -44,7 +44,7 @@ test('prray every compatibility 2', async t => { test('prraypromise every compatibility 1', async t => { const func = sinon.fake(() => true) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const pp = toPrrayPromise(prr) await pp.every(func) @@ -66,7 +66,7 @@ test('prraypromise every compatibility 1', async t => { test('prraypromise every compatibility 2', async t => { const func = sinon.fake(() => false) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const pp = toPrrayPromise(prr) await pp.every(func) diff --git a/test/everyAsync.test.ts b/test/everyAsync.test.ts index c9fe8ab..223a45d 100644 --- a/test/everyAsync.test.ts +++ b/test/everyAsync.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isGte3, isGte3Async } from './test-utils' -const p1 = prray([3, 4]) -const p2 = prray([1, 2, 3]) +const p1 = Prray.from([3, 4]) +const p2 = Prray.from([1, 2, 3]) const pp1 = toPrrayPromise([3, 4]) const pp2 = toPrrayPromise([1, 2, 3]) diff --git a/test/fill.test.ts b/test/fill.test.ts index 408ff58..6dd3e77 100644 --- a/test/fill.test.ts +++ b/test/fill.test.ts @@ -1,49 +1,49 @@ import test from 'ava' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray fill', async t => { - t.deepEqual(prray([1, 2, 3]).fill(4), prray([4, 4, 4])) - t.deepEqual(prray([1, 2, 3]).fill(4, 1), prray([1, 4, 4])) - t.deepEqual(prray([1, 2, 3]).fill(4, 1, 2), prray([1, 4, 3])) - t.deepEqual(prray([1, 2, 3]).fill(4, 1, 1), prray([1, 2, 3])) - t.deepEqual(prray([1, 2, 3]).fill(4, 3, 3), prray([1, 2, 3])) - t.deepEqual(prray([1, 2, 3]).fill(4, -3, -2), prray([4, 2, 3])) - t.deepEqual(prray([1, 2, 3]).fill(4, NaN, NaN), prray([1, 2, 3])) - t.deepEqual(prray([1, 2, 3]).fill(4, 3, 5), prray([1, 2, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4), Prray.from([4, 4, 4])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, 1), Prray.from([1, 4, 4])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, 1, 2), Prray.from([1, 4, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, 1, 1), Prray.from([1, 2, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, 3, 3), Prray.from([1, 2, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, -3, -2), Prray.from([4, 2, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, NaN, NaN), Prray.from([1, 2, 3])) + t.deepEqual(Prray.from([1, 2, 3]).fill(4, 3, 5), Prray.from([1, 2, 3])) - t.deepEqual(new Prray(3).fill(4), prray([4, 4, 4])) + t.deepEqual(new Prray(3).fill(4), Prray.from([4, 4, 4])) const prr = new Prray(3).fill({}) // [{}, {}, {}]; - t.deepEqual(prr, prray([{}, {}, {}])) + t.deepEqual(prr, Prray.from([{}, {}, {}])) ;(prr[0] as any).hi = 'hi' - t.deepEqual(prr, prray([{ hi: 'hi' }, { hi: 'hi' }, { hi: 'hi' }])) + t.deepEqual(prr, Prray.from([{ hi: 'hi' }, { hi: 'hi' }, { hi: 'hi' }])) }) test('prray fill: mutable', async t => { - const prr = prray([1, 2, 3]) + const prr = Prray.from([1, 2, 3]) t.is(prr.fill(4), prr) }) test('prraypromise fill', async t => { - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4), prray([4, 4, 4])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1), prray([1, 4, 4])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1, 2), prray([1, 4, 3])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1, 1), prray([1, 2, 3])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 3, 3), prray([1, 2, 3])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, -3, -2), prray([4, 2, 3])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, NaN, NaN), prray([1, 2, 3])) - t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 3, 5), prray([1, 2, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4), Prray.from([4, 4, 4])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1), Prray.from([1, 4, 4])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1, 2), Prray.from([1, 4, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 1, 1), Prray.from([1, 2, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 3, 3), Prray.from([1, 2, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, -3, -2), Prray.from([4, 2, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, NaN, NaN), Prray.from([1, 2, 3])) + t.deepEqual(await toPrrayPromise([1, 2, 3]).fill(4, 3, 5), Prray.from([1, 2, 3])) - t.deepEqual(await toPrrayPromise(new Array(3)).fill(4), prray([4, 4, 4])) + t.deepEqual(await toPrrayPromise(new Array(3)).fill(4), Prray.from([4, 4, 4])) const prr = await toPrrayPromise(new Array(3)).fill({}) // [{}, {}, {}]; - t.deepEqual(prr, prray([{}, {}, {}])) + t.deepEqual(prr, Prray.from([{}, {}, {}])) ;(prr[0] as any).hi = 'hi' - t.deepEqual(prr, prray([{ hi: 'hi' }, { hi: 'hi' }, { hi: 'hi' }])) + t.deepEqual(prr, Prray.from([{ hi: 'hi' }, { hi: 'hi' }, { hi: 'hi' }])) }) test('prraypromise fill: mutable', async t => { - const prr = prray([1, 2, 3]) + const prr = Prray.from([1, 2, 3]) t.is(await toPrrayPromise(prr).fill(4), prr) }) diff --git a/test/filter.test.ts b/test/filter.test.ts index b0bfb00..6b5299f 100644 --- a/test/filter.test.ts +++ b/test/filter.test.ts @@ -1,15 +1,15 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise, isEven } from './test-utils' test('prray filter', async t => { - const p = prray([1, 2, 3, 4]) + const p = Prray.from([1, 2, 3, 4]) const result = p.filter(isEven) t.true(result instanceof Prray) - t.deepEqual(result, prray([2, 4])) + t.deepEqual(result, Prray.from([2, 4])) }) test('prraypromise filter', async t => { @@ -17,11 +17,11 @@ test('prraypromise filter', async t => { const result = pp.filter(isEven) t.true(result instanceof PrrayPromise) - t.deepEqual(await result, prray([2, 4])) + t.deepEqual(await result, Prray.from([2, 4])) }) test('prray filter detail', async t => { - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const func = sinon.fake() prr.filter(func) @@ -41,7 +41,7 @@ test('prray filter detail', async t => { }) test('prraypromise filter detail', async t => { - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const prom = toPrrayPromise(prr) const func = sinon.fake() diff --git a/test/filterAsync.test.ts b/test/filterAsync.test.ts index 7a3c7db..046f30c 100644 --- a/test/filterAsync.test.ts +++ b/test/filterAsync.test.ts @@ -1,18 +1,18 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise, isEven, isEvenAsync } from './test-utils' test('prray filterAsync', async t => { - const p = prray([1, 2, 3, 4]) + const p = Prray.from([1, 2, 3, 4]) t.true(p.filterAsync(isEvenAsync) instanceof PrrayPromise) t.true(p.filterAsync(isEven) instanceof PrrayPromise) - t.deepEqual(await p.filterAsync(isEvenAsync), prray([2, 4])) - t.deepEqual(await p.filterAsync(isEven), prray([2, 4])) + t.deepEqual(await p.filterAsync(isEvenAsync), Prray.from([2, 4])) + t.deepEqual(await p.filterAsync(isEven), Prray.from([2, 4])) - t.deepEqual(await p.filterAsync(isEvenAsync, { concurrency: 1 }), prray([2, 4])) + t.deepEqual(await p.filterAsync(isEvenAsync, { concurrency: 1 }), Prray.from([2, 4])) }) test('prraypromise filterAsync', async t => { @@ -21,8 +21,8 @@ test('prraypromise filterAsync', async t => { t.true(pp.filterAsync(isEvenAsync) instanceof PrrayPromise) t.true(pp.filterAsync(isEven) instanceof PrrayPromise) - t.deepEqual(await pp.filterAsync(isEvenAsync), prray([2, 4])) - t.deepEqual(await pp.filterAsync(isEven), prray([2, 4])) + t.deepEqual(await pp.filterAsync(isEvenAsync), Prray.from([2, 4])) + t.deepEqual(await pp.filterAsync(isEven), Prray.from([2, 4])) - t.deepEqual(await pp.filterAsync(isEvenAsync, { concurrency: 1 }), prray([2, 4])) + t.deepEqual(await pp.filterAsync(isEvenAsync, { concurrency: 1 }), Prray.from([2, 4])) }) diff --git a/test/find.test.ts b/test/find.test.ts index 817ff13..a54a4ce 100644 --- a/test/find.test.ts +++ b/test/find.test.ts @@ -1,15 +1,15 @@ import test from 'ava' import { toPrrayPromise } from './test-utils' -import { prray } from '../src/prray' +import Prray from '../src/prray' test('prray find', async t => { - const prr = prray([1, 2, 3, 4]) + const prr = Prray.from([1, 2, 3, 4]) t.is(prr.find(x => x === 2), 2) t.is(prr.find(x => x === 10), undefined) }) test('prray find: order', async t => { - const prr = prray([{ a: 1 }, { a: 2 }]) + const prr = Prray.from([{ a: 1 }, { a: 2 }]) t.deepEqual(prr.find(x => x.a > 0), { a: 1 }) t.is(prr.find(x => x.a > 10), undefined) }) diff --git a/test/findAsync.test.ts b/test/findAsync.test.ts index ecd0c6b..ec60f4c 100644 --- a/test/findAsync.test.ts +++ b/test/findAsync.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isGte3, isGte3Async } from './test-utils' -const p1 = prray([1, 2, 3]) -const p2 = prray([0, 2]) +const p1 = Prray.from([1, 2, 3]) +const p2 = Prray.from([0, 2]) const pp1 = toPrrayPromise([1, 2, 3]) const pp2 = toPrrayPromise([0, 2]) diff --git a/test/findIndex.test.ts b/test/findIndex.test.ts index 09adbdd..0e97ed1 100644 --- a/test/findIndex.test.ts +++ b/test/findIndex.test.ts @@ -1,15 +1,15 @@ import test from 'ava' import { toPrrayPromise } from './test-utils' -import { prray } from '../src/prray' +import Prray from '../src/prray' test('prray findIndex', async t => { - const prr = prray([1, 2, 3, 4]) + const prr = Prray.from([1, 2, 3, 4]) t.is(prr.findIndex(x => x === 2), 1) t.is(prr.findIndex(x => x === 10), -1) }) test('prray findIndex: order', async t => { - const prr = prray([{ a: 1 }, { a: 2 }]) + const prr = Prray.from([{ a: 1 }, { a: 2 }]) t.deepEqual(prr.findIndex(x => x.a > 0), 0) t.is(prr.findIndex(x => x.a > 10), -1) }) diff --git a/test/findIndexAsync.test.ts b/test/findIndexAsync.test.ts index 0b10f56..5f63f4e 100644 --- a/test/findIndexAsync.test.ts +++ b/test/findIndexAsync.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isGte3, isGte3Async } from './test-utils' -const p1 = prray([1, 2, 3]) -const p2 = prray([0, 2]) +const p1 = Prray.from([1, 2, 3]) +const p2 = Prray.from([0, 2]) const pp1 = toPrrayPromise([1, 2, 3]) const pp2 = toPrrayPromise([0, 2]) diff --git a/test/forEach.test.ts b/test/forEach.test.ts index d2f916d..ef8b3a1 100644 --- a/test/forEach.test.ts +++ b/test/forEach.test.ts @@ -1,11 +1,11 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray forEach compatibility', async t => { const func = sinon.fake() - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) prr.forEach(func) t.is(func.called, true) @@ -34,13 +34,13 @@ test('prraypromise forEach compatibility', async t => { t.is(func.args[0][0], 'a') t.is(func.args[0][1], 0) - t.deepEqual(func.args[0][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[0][2], Prray.from(['a', 'b', 'c'])) t.is(func.args[1][0], 'b') t.is(func.args[1][1], 1) - t.deepEqual(func.args[1][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[1][2], Prray.from(['a', 'b', 'c'])) t.is(func.args[2][0], 'c') t.is(func.args[2][1], 2) - t.deepEqual(func.args[2][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[2][2], Prray.from(['a', 'b', 'c'])) }) diff --git a/test/forEachAsync.test.ts b/test/forEachAsync.test.ts index 9020db8..fe641db 100644 --- a/test/forEachAsync.test.ts +++ b/test/forEachAsync.test.ts @@ -1,23 +1,23 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, delay } from './test-utils' test('prray forEachAsync', async t => { const result1: number[] = [] - await prray([1, 2, 3]).forEachAsync(async v => { + await Prray.from([1, 2, 3]).forEachAsync(async v => { await delay(100) result1.push(v + 1) }) t.deepEqual(result1, [2, 3, 4]) const result2: number[] = [] - await prray([1, 2, 3]).forEachAsync(v => { + await Prray.from([1, 2, 3]).forEachAsync(v => { result2.push(v + 1) }) t.deepEqual(result2, [2, 3, 4]) - await prray([1, 2, 3]).forEachAsync( + await Prray.from([1, 2, 3]).forEachAsync( async v => { await delay(100) result1.push(v + 1) @@ -43,7 +43,7 @@ test('prraypromise forEachAsync', async t => { test('prray forEachAsync compatibility', async t => { const func = sinon.fake() - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) await prr.forEachAsync(func) t.is(func.called, true) @@ -72,15 +72,15 @@ test('prraypromise forEachAsync compatibility', async t => { t.is(func.args[0][0], 'a') t.is(func.args[0][1], 0) - t.deepEqual(func.args[0][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[0][2], Prray.from(['a', 'b', 'c'])) t.is(func.args[1][0], 'b') t.is(func.args[1][1], 1) - t.deepEqual(func.args[1][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[1][2], Prray.from(['a', 'b', 'c'])) t.is(func.args[2][0], 'c') t.is(func.args[2][1], 2) - t.deepEqual(func.args[2][2], prray(['a', 'b', 'c'])) + t.deepEqual(func.args[2][2], Prray.from(['a', 'b', 'c'])) await p.forEachAsync(func, { concurrency: 2 }) }) diff --git a/test/from.test.ts b/test/from.test.ts index 2192dbb..c9cf249 100644 --- a/test/from.test.ts +++ b/test/from.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { Prray } from '../src/prray' +import Prray from '../src/prray' test('prray from', async t => { const p1 = Prray.from('foo') diff --git a/test/isPrray.test.ts b/test/isPrray.test.ts index 4ead7aa..003ddcb 100644 --- a/test/isPrray.test.ts +++ b/test/isPrray.test.ts @@ -1,11 +1,11 @@ import test from 'ava' -import { Prray, prray } from '../src/prray' +import Prray from '../src/prray' test('prray isPrray', async t => { t.true(Prray.isPrray(new Prray(1, 2, 3))) t.true(Prray.isPrray(Prray.of(1, 2, 3))) t.true(Prray.isPrray(Prray.from([1, 2, 3]))) - t.true(Prray.isPrray(prray([1, 2, 3]))) + t.true(Prray.isPrray(Prray.from([1, 2, 3]))) t.false(Prray.isPrray([1, 2, 3])) t.false(Prray.isPrray(new Array(1, 2, 3))) diff --git a/test/join.test.ts b/test/join.test.ts index 5b8edc6..0544bef 100644 --- a/test/join.test.ts +++ b/test/join.test.ts @@ -1,8 +1,8 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' -const p = prray([1, 2, 3, 4]) +const p = Prray.from([1, 2, 3, 4]) const pp = toPrrayPromise([1, 2, 3, 4]) test('prray join', async t => { diff --git a/test/keys.test.ts b/test/keys.test.ts index 32df1ad..c5b1039 100644 --- a/test/keys.test.ts +++ b/test/keys.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] -const p = prray(arr) +const p = Prray.from(arr) const pp = toPrrayPromise(arr) test('prray keys', async t => { diff --git a/test/lastIndexOf.test.ts b/test/lastIndexOf.test.ts index dbc9055..bcf2568 100644 --- a/test/lastIndexOf.test.ts +++ b/test/lastIndexOf.test.ts @@ -1,8 +1,8 @@ import test from 'ava' import { toPrrayPromise } from './test-utils' -import { prray } from '../src/prray' +import Prray from '../src/prray' -const p = prray(['a', 'b', 'c', 'd']) +const p = Prray.from(['a', 'b', 'c', 'd']) const pp = toPrrayPromise(['a', 'b', 'c', 'd']) test('prray lastIndexOf', async t => { diff --git a/test/loop.test.ts b/test/loop.test.ts index b752368..78d5609 100644 --- a/test/loop.test.ts +++ b/test/loop.test.ts @@ -1,11 +1,11 @@ import test from 'ava' import * as sinon from 'sinon' import { delay, genRandArr, timer, isClose } from './test-utils' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { loop } from '../src/methods' test('loop with concurrency 100', async t => { - const prr = prray(genRandArr(1000)) + const prr = Prray.from(genRandArr(1000)) const record = timer() let running = 0 await loop( @@ -22,21 +22,21 @@ test('loop with concurrency 100', async t => { }) test('loop with concurrency infinity', async t => { - const prr = prray(genRandArr(1000)) + const prr = Prray.from(genRandArr(1000)) const record = timer() await loop(prr, () => delay(100), {}) t.true(isClose(record(), 100)) }) test('loop with concurrency 1', async t => { - const prr = prray(genRandArr(100)) + const prr = Prray.from(genRandArr(100)) const record = timer() await loop(prr, () => delay(10), { concurrency: 1 }) t.true(isClose(record(), 10 * 100, { threshold: 200 })) }) test('loop with break', async t => { - const prr = prray([false, false, false, false, false, false, false, false]) // length 8 + const prr = Prray.from([false, false, false, false, false, false, false, false]) // length 8 const record = timer() await loop( prr, @@ -51,11 +51,11 @@ test('loop with break', async t => { { concurrency: 2 }, ) t.true(isClose(record(), 300)) - t.deepEqual(prr, prray([true, true, true, true, true, true, false, false])) + t.deepEqual(prr, Prray.from([true, true, true, true, true, true, false, false])) }) test('loop with unhandled error', async t => { - const arr = prray([false, false, false, false, false, false, false, false]) // length 8 + const arr = Prray.from([false, false, false, false, false, false, false, false]) // length 8 let isThrown = false const record = timer() try { @@ -74,24 +74,24 @@ test('loop with unhandled error', async t => { isThrown = true } t.true(isClose(record(), 300)) - t.deepEqual(arr, prray([true, true, true, true, true, true, false, false])) + t.deepEqual(arr, Prray.from([true, true, true, true, true, true, false, false])) t.true(isThrown) }) test('loop with empty array', async t => { const record = timer() - await loop(prray([]), () => delay(100), { concurrency: 10 }) + await loop(Prray.from([]), () => delay(100), { concurrency: 10 }) t.true(isClose(record(), 0)) }) test('loop with empty array, concurrency Infinity', async t => { const record = timer() - await loop(prray([]), () => delay(100), {}) + await loop(Prray.from([]), () => delay(100), {}) t.true(isClose(record(), 0)) }) test('loop detail', async t => { - const prr = prray(['a', 'b', 'c', 'd', 'e', 'f']) + const prr = Prray.from(['a', 'b', 'c', 'd', 'e', 'f']) const func = sinon.fake() await loop(prr, func, { concurrency: 2 }) diff --git a/test/map.test.ts b/test/map.test.ts index 012ca06..8e15aa0 100644 --- a/test/map.test.ts +++ b/test/map.test.ts @@ -1,19 +1,19 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise, addOneAsync, addOne } from './test-utils' test('prray map', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) const result = p.map(addOne) t.true(result instanceof Prray) - t.deepEqual(result, prray([2, 3, 4])) + t.deepEqual(result, Prray.from([2, 3, 4])) }) test('prray map with async callback', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) const result = p.map(addOneAsync) t.true(result instanceof Prray) @@ -26,7 +26,7 @@ test('prraypromise map', async t => { const result = pp.map(addOne) t.true(result instanceof PrrayPromise) - t.deepEqual(await result, prray([2, 3, 4])) + t.deepEqual(await result, Prray.from([2, 3, 4])) }) test('prraypromise map with async callback', async t => { @@ -39,7 +39,7 @@ test('prraypromise map with async callback', async t => { }) test('prray map detail', async t => { - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const func = sinon.fake() prr.map(func) @@ -59,7 +59,7 @@ test('prray map detail', async t => { }) test('prraypromise map detail', async t => { - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const prom = toPrrayPromise(prr) const func = sinon.fake() diff --git a/test/mapAsync.test.ts b/test/mapAsync.test.ts index 4931cc0..321fe5f 100644 --- a/test/mapAsync.test.ts +++ b/test/mapAsync.test.ts @@ -1,18 +1,18 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise, addOneAsync, addOne } from './test-utils' test('prray mapAsync', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.true(p.mapAsync(addOneAsync) instanceof PrrayPromise) t.true(p.mapAsync(addOne) instanceof PrrayPromise) - t.deepEqual(await p.mapAsync(addOneAsync), prray([2, 3, 4])) - t.deepEqual(await p.mapAsync(addOne), prray([2, 3, 4])) + t.deepEqual(await p.mapAsync(addOneAsync), Prray.from([2, 3, 4])) + t.deepEqual(await p.mapAsync(addOne), Prray.from([2, 3, 4])) - t.deepEqual(await p.mapAsync(addOneAsync, { concurrency: 2 }), prray([2, 3, 4])) + t.deepEqual(await p.mapAsync(addOneAsync, { concurrency: 2 }), Prray.from([2, 3, 4])) }) test('prraypromise mapAsync', async t => { @@ -21,8 +21,8 @@ test('prraypromise mapAsync', async t => { t.true(pp.mapAsync(addOneAsync) instanceof PrrayPromise) t.true(pp.mapAsync(addOne) instanceof PrrayPromise) - t.deepEqual(await pp.mapAsync(addOneAsync), prray([2, 3, 4])) - t.deepEqual(await pp.mapAsync(addOne), prray([2, 3, 4])) + t.deepEqual(await pp.mapAsync(addOneAsync), Prray.from([2, 3, 4])) + t.deepEqual(await pp.mapAsync(addOne), Prray.from([2, 3, 4])) - t.deepEqual(await pp.mapAsync(addOneAsync, { concurrency: 2 }), prray([2, 3, 4])) + t.deepEqual(await pp.mapAsync(addOneAsync, { concurrency: 2 }), Prray.from([2, 3, 4])) }) diff --git a/test/of.test.ts b/test/of.test.ts index 7e844d4..1024723 100644 --- a/test/of.test.ts +++ b/test/of.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { Prray } from '../src/prray' +import Prray from '../src/prray' test('prray of', async t => { const p1 = Prray.of(1) diff --git a/test/pop.test.ts b/test/pop.test.ts index 65bf43e..01589ca 100644 --- a/test/pop.test.ts +++ b/test/pop.test.ts @@ -1,11 +1,11 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] test('prray pop', async t => { - const p = prray(arr) + const p = Prray.from(arr) t.is(p.pop(), 'd') t.is(p.pop(), 'c') @@ -13,7 +13,7 @@ test('prray pop', async t => { t.is(p.pop(), 'a') t.is(p.pop(), undefined) - t.deepEqual(p, prray([])) // mutable + t.deepEqual(p, Prray.from([])) // mutable }) test('prraypromise pop', async t => { @@ -25,5 +25,5 @@ test('prraypromise pop', async t => { t.is(await pp.pop(), 'a') t.is(await pp.pop(), undefined) - t.deepEqual(await pp, prray([])) // mutable + t.deepEqual(await pp, Prray.from([])) // mutable }) diff --git a/test/push.test.ts b/test/push.test.ts index be43934..29d04e1 100644 --- a/test/push.test.ts +++ b/test/push.test.ts @@ -1,22 +1,22 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b'] test('prray push', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) t.is(prr.push('c'), 3) t.is(prr.push('d', 'e'), 5) - t.deepEqual(prr, prray(['a', 'b', 'c', 'd', 'e'])) + t.deepEqual(prr, Prray.from(['a', 'b', 'c', 'd', 'e'])) }) test('prraypromise push', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) const pp = toPrrayPromise(prr) t.is(await pp.push('c'), 3) t.is(await pp.push('d', 'e'), 5) - t.deepEqual(prr, prray(['a', 'b', 'c', 'd', 'e'])) + t.deepEqual(prr, Prray.from(['a', 'b', 'c', 'd', 'e'])) }) diff --git a/test/real-word.test.ts b/test/real-word.test.ts index 7a2b9b8..1f819bd 100644 --- a/test/real-word.test.ts +++ b/test/real-word.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/index' +import Prray from '../src/index' import { delay } from './test-utils' test('Real world test 1', async t => { - const p = await prray([1, 2, 3]) + const p = await Prray.from([1, 2, 3]) .map(v => v + 1) .mapAsync(v => delay(100).then(() => v + 2)) .concat([4, 5, 6]) @@ -18,7 +18,7 @@ test('Real world test 1', async t => { }) test('Real world test 2', async t => { - const p = await prray(['e', 'a', 'f', 'd']) + const p = await Prray.from(['e', 'a', 'f', 'd']) .mapAsync(v => v + v) .sortAsync() .join('---') diff --git a/test/reduce.test.ts b/test/reduce.test.ts index f50bdee..7b6091a 100644 --- a/test/reduce.test.ts +++ b/test/reduce.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const func1 = (pre: number, c: number) => pre + c @@ -10,19 +10,19 @@ const func2 = (pre: number[], c: number) => { } test('prray reduce 1', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduce(func1), [1, 2, 3].reduce(func1)) t.deepEqual(p.reduce(func1, 10), [1, 2, 3].reduce(func1, 10)) }) test('prray reduce 2', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduce(func2, []), [1, 2, 3].reduce(func2, [])) t.deepEqual(p.reduce(func2, []), [1, 2, 3].reduce(func2, [])) }) test('prray reduce 3', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduce(func2, new Prray()), [1, 2, 3].reduce(func2, new Prray())) t.deepEqual(p.reduce(func2, new Prray()), [1, 2, 3].reduce(func2, new Prray())) }) diff --git a/test/reduceAsync.test.ts b/test/reduceAsync.test.ts index e8aaa72..890a78d 100644 --- a/test/reduceAsync.test.ts +++ b/test/reduceAsync.test.ts @@ -1,6 +1,6 @@ import test from 'ava' import 'source-map-support/register' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, delay } from './test-utils' const asyncFunc1 = (pre: number, c: number) => delay(100).then(() => pre + c) @@ -17,14 +17,14 @@ const func2 = (pre: number[], c: number) => { } test('prray reduceAsync 1', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.true(p.reduceAsync(asyncFunc1) instanceof Promise) t.deepEqual(await p.reduceAsync(asyncFunc1), [1, 2, 3].reduce(func1)) t.deepEqual(await p.reduceAsync(asyncFunc1, 10), [1, 2, 3].reduce(func1, 10)) }) test('prray reduceAsync 2', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.true(p.reduceAsync(asyncFunc2, []) instanceof Promise) t.deepEqual(await p.reduceAsync(asyncFunc2, []), [1, 2, 3].reduce(func2, [])) t.deepEqual(await p.reduceAsync(asyncFunc2, []), [1, 2, 3].reduce(func2, [])) diff --git a/test/reduceRight.test.ts b/test/reduceRight.test.ts index 656ca85..32af68b 100644 --- a/test/reduceRight.test.ts +++ b/test/reduceRight.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const func1 = (pre: number, c: number) => pre + c @@ -10,19 +10,19 @@ const func2 = (pre: number[], c: number) => { } test('prray reduceRight 1', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduceRight(func1), [1, 2, 3].reduceRight(func1)) t.deepEqual(p.reduceRight(func1, 10), [1, 2, 3].reduceRight(func1, 10)) }) test('prray reduceRight 2', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduceRight(func2, []), [1, 2, 3].reduceRight(func2, [])) t.deepEqual(p.reduceRight(func2, []), [1, 2, 3].reduceRight(func2, [])) }) test('prray reduceRight 3', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(p.reduceRight(func2, new Prray()), [1, 2, 3].reduceRight(func2, new Prray())) t.deepEqual(p.reduceRight(func2, new Prray()), [1, 2, 3].reduceRight(func2, new Prray())) }) diff --git a/test/reduceRightAsync.test.ts b/test/reduceRightAsync.test.ts index cb685a4..b93dd74 100644 --- a/test/reduceRightAsync.test.ts +++ b/test/reduceRightAsync.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, delay } from './test-utils' const func1 = (pre: number, c: number) => pre + c @@ -16,7 +16,7 @@ const funcAsync2 = async (pre: number[], c: number) => { } test('prray reduceRightAsync 1', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(await p.reduceRightAsync(func1), [1, 2, 3].reduceRight(func1)) t.deepEqual(await p.reduceRightAsync(funcAsync1), [1, 2, 3].reduceRight(func1)) @@ -26,7 +26,7 @@ test('prray reduceRightAsync 1', async t => { }) test('prray reduceRightAsync 2', async t => { - const p = prray([1, 2, 3]) + const p = Prray.from([1, 2, 3]) t.deepEqual(await p.reduceRightAsync(func2, [] as number[]), [1, 2, 3].reduceRight(func2, [])) t.deepEqual(await p.reduceRightAsync(func2, [] as number[]), [1, 2, 3].reduceRight(func2, [])) diff --git a/test/reverse.test.ts b/test/reverse.test.ts index e08c2e1..f60ce22 100644 --- a/test/reverse.test.ts +++ b/test/reverse.test.ts @@ -1,22 +1,22 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise } from './test-utils' const arr = [1, 2, 3, 4] test('prray reverse', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) - t.deepEqual(prr.reverse(), prray([4, 3, 2, 1])) - t.deepEqual(prr, prray([4, 3, 2, 1])) // mutable + t.deepEqual(prr.reverse(), Prray.from([4, 3, 2, 1])) + t.deepEqual(prr, Prray.from([4, 3, 2, 1])) // mutable }) test('prraypromise reverse', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.reverse(), prray([4, 3, 2, 1])) - t.deepEqual(prr, prray([4, 3, 2, 1])) // mutable + t.deepEqual(await pp.reverse(), Prray.from([4, 3, 2, 1])) + t.deepEqual(prr, Prray.from([4, 3, 2, 1])) // mutable t.true(pp.reverse() instanceof PrrayPromise) }) diff --git a/test/shift.test.ts b/test/shift.test.ts index f91baf6..0007011 100644 --- a/test/shift.test.ts +++ b/test/shift.test.ts @@ -1,11 +1,11 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] test('prray shift', async t => { - const p = prray(arr) + const p = Prray.from(arr) t.is(p.shift(), 'a') t.is(p.shift(), 'b') @@ -13,11 +13,11 @@ test('prray shift', async t => { t.is(p.shift(), 'd') t.is(p.shift(), undefined) - t.deepEqual(p, prray([])) // mutable + t.deepEqual(p, Prray.from([])) // mutable }) test('prraypromise shift', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) const pp = toPrrayPromise(prr) t.is(await pp.shift(), 'a') @@ -26,5 +26,5 @@ test('prraypromise shift', async t => { t.is(await pp.shift(), 'd') t.is(await pp.shift(), undefined) - t.deepEqual(prr, prray([])) // mutable + t.deepEqual(prr, Prray.from([])) // mutable }) diff --git a/test/slice.test.ts b/test/slice.test.ts index 955457d..994747e 100644 --- a/test/slice.test.ts +++ b/test/slice.test.ts @@ -1,35 +1,35 @@ import test from 'ava' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise } from './test-utils' const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] -const p = prray(arr) +const p = Prray.from(arr) const pp = toPrrayPromise(arr) test('prray slice', async t => { t.true(p.slice(1) instanceof Prray) - t.deepEqual(p.slice(), prray(arr.slice())) + t.deepEqual(p.slice(), Prray.from(arr.slice())) - t.deepEqual(p.slice(2), prray(arr.slice(2))) - t.deepEqual(p.slice(undefined, 7), prray(arr.slice(undefined, 7))) - t.deepEqual(p.slice(1, 5), prray(arr.slice(1, 5))) - t.deepEqual(p.slice(4, 100), prray(arr.slice(4, 100))) - t.deepEqual(p.slice(100, 200), prray(arr.slice(100, 200))) + t.deepEqual(p.slice(2), Prray.from(arr.slice(2))) + t.deepEqual(p.slice(undefined, 7), Prray.from(arr.slice(undefined, 7))) + t.deepEqual(p.slice(1, 5), Prray.from(arr.slice(1, 5))) + t.deepEqual(p.slice(4, 100), Prray.from(arr.slice(4, 100))) + t.deepEqual(p.slice(100, 200), Prray.from(arr.slice(100, 200))) - t.deepEqual(p.slice(-3), prray(arr.slice(-3))) - t.deepEqual(p.slice(undefined, -4), prray(arr.slice(undefined, -4))) - t.deepEqual(p.slice(-2, -5), prray(arr.slice(-2, -5))) - t.deepEqual(p.slice(-5, -2), prray(arr.slice(-5, -2))) - t.deepEqual(p.slice(-4, -100), prray(arr.slice(-4, -100))) - t.deepEqual(p.slice(-100, -4), prray(arr.slice(-100, -4))) - t.deepEqual(p.slice(-200, -100), prray(arr.slice(-200, -100))) + t.deepEqual(p.slice(-3), Prray.from(arr.slice(-3))) + t.deepEqual(p.slice(undefined, -4), Prray.from(arr.slice(undefined, -4))) + t.deepEqual(p.slice(-2, -5), Prray.from(arr.slice(-2, -5))) + t.deepEqual(p.slice(-5, -2), Prray.from(arr.slice(-5, -2))) + t.deepEqual(p.slice(-4, -100), Prray.from(arr.slice(-4, -100))) + t.deepEqual(p.slice(-100, -4), Prray.from(arr.slice(-100, -4))) + t.deepEqual(p.slice(-200, -100), Prray.from(arr.slice(-200, -100))) - t.deepEqual(p.slice(-7, 5), prray(arr.slice(-7, 5))) - t.deepEqual(p.slice(1, -3), prray(arr.slice(1, -3))) - t.deepEqual(p.slice(-1000, 3), prray(arr.slice(-1000, 3))) - t.deepEqual(p.slice(-3, 1000), prray(arr.slice(-3, 1000))) + t.deepEqual(p.slice(-7, 5), Prray.from(arr.slice(-7, 5))) + t.deepEqual(p.slice(1, -3), Prray.from(arr.slice(1, -3))) + t.deepEqual(p.slice(-1000, 3), Prray.from(arr.slice(-1000, 3))) + t.deepEqual(p.slice(-3, 1000), Prray.from(arr.slice(-3, 1000))) t.not(p.slice(-3, 1000), p) // Immutable }) @@ -37,26 +37,26 @@ test('prray slice', async t => { test('prraypromise slice', async t => { t.true(pp.slice(1) instanceof PrrayPromise) - t.deepEqual(await pp.slice(), prray(arr.slice())) - - t.deepEqual(await pp.slice(2), prray(arr.slice(2))) - t.deepEqual(await pp.slice(undefined, 7), prray(arr.slice(undefined, 7))) - t.deepEqual(await pp.slice(1, 5), prray(arr.slice(1, 5))) - t.deepEqual(await pp.slice(4, 100), prray(arr.slice(4, 100))) - t.deepEqual(await pp.slice(100, 200), prray(arr.slice(100, 200))) - - t.deepEqual(await pp.slice(-3), prray(arr.slice(-3))) - t.deepEqual(await pp.slice(undefined, -4), prray(arr.slice(undefined, -4))) - t.deepEqual(await pp.slice(-2, -5), prray(arr.slice(-2, -5))) - t.deepEqual(await pp.slice(-5, -2), prray(arr.slice(-5, -2))) - t.deepEqual(await pp.slice(-4, -100), prray(arr.slice(-4, -100))) - t.deepEqual(await pp.slice(-100, -4), prray(arr.slice(-100, -4))) - t.deepEqual(await pp.slice(-200, -100), prray(arr.slice(-200, -100))) - - t.deepEqual(await pp.slice(-7, 5), prray(arr.slice(-7, 5))) - t.deepEqual(await pp.slice(1, -3), prray(arr.slice(1, -3))) - t.deepEqual(await pp.slice(-1000, 3), prray(arr.slice(-1000, 3))) - t.deepEqual(await pp.slice(-3, 1000), prray(arr.slice(-3, 1000))) + t.deepEqual(await pp.slice(), Prray.from(arr.slice())) + + t.deepEqual(await pp.slice(2), Prray.from(arr.slice(2))) + t.deepEqual(await pp.slice(undefined, 7), Prray.from(arr.slice(undefined, 7))) + t.deepEqual(await pp.slice(1, 5), Prray.from(arr.slice(1, 5))) + t.deepEqual(await pp.slice(4, 100), Prray.from(arr.slice(4, 100))) + t.deepEqual(await pp.slice(100, 200), Prray.from(arr.slice(100, 200))) + + t.deepEqual(await pp.slice(-3), Prray.from(arr.slice(-3))) + t.deepEqual(await pp.slice(undefined, -4), Prray.from(arr.slice(undefined, -4))) + t.deepEqual(await pp.slice(-2, -5), Prray.from(arr.slice(-2, -5))) + t.deepEqual(await pp.slice(-5, -2), Prray.from(arr.slice(-5, -2))) + t.deepEqual(await pp.slice(-4, -100), Prray.from(arr.slice(-4, -100))) + t.deepEqual(await pp.slice(-100, -4), Prray.from(arr.slice(-100, -4))) + t.deepEqual(await pp.slice(-200, -100), Prray.from(arr.slice(-200, -100))) + + t.deepEqual(await pp.slice(-7, 5), Prray.from(arr.slice(-7, 5))) + t.deepEqual(await pp.slice(1, -3), Prray.from(arr.slice(1, -3))) + t.deepEqual(await pp.slice(-1000, 3), Prray.from(arr.slice(-1000, 3))) + t.deepEqual(await pp.slice(-3, 1000), Prray.from(arr.slice(-3, 1000))) t.not(await pp.slice(-3, 1000), await pp) // Immutable }) diff --git a/test/some.test.ts b/test/some.test.ts index 0d4ea6e..4a7833d 100644 --- a/test/some.test.ts +++ b/test/some.test.ts @@ -1,11 +1,11 @@ import test from 'ava' import * as sinon from 'sinon' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isEven } from './test-utils' test('prray some', async t => { - t.is(prray([1, 2, 3]).some(isEven), true) - t.is(prray([1, 3, 5]).some(isEven), false) + t.is(Prray.from([1, 2, 3]).some(isEven), true) + t.is(Prray.from([1, 3, 5]).some(isEven), false) }) test('prraypromise some', async t => { @@ -15,7 +15,7 @@ test('prraypromise some', async t => { test('prray some compatibility 1', async t => { const func = sinon.fake(() => false) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) prr.some(func) t.is(func.called, true) @@ -36,7 +36,7 @@ test('prray some compatibility 1', async t => { test('prray some compatibility 2', async t => { const func = sinon.fake(() => true) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) prr.some(func) t.is(func.callCount, 1) @@ -44,7 +44,7 @@ test('prray some compatibility 2', async t => { test('prraypromise some compatibility 1', async t => { const func = sinon.fake(() => false) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const pp = toPrrayPromise(prr) await pp.some(func) @@ -66,7 +66,7 @@ test('prraypromise some compatibility 1', async t => { test('prraypromise some compatibility 2', async t => { const func = sinon.fake(() => true) - const prr = prray(['a', 'b', 'c']) + const prr = Prray.from(['a', 'b', 'c']) const pp = toPrrayPromise(prr) await pp.some(func) diff --git a/test/someAsync.test.ts b/test/someAsync.test.ts index 441aa7c..5633393 100644 --- a/test/someAsync.test.ts +++ b/test/someAsync.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, isGte3Async, isGte3 } from './test-utils' -const p1 = prray([1, 3]) -const p2 = prray([1, 2]) +const p1 = Prray.from([1, 3]) +const p2 = Prray.from([1, 2]) const pp1 = toPrrayPromise([1, 3]) const pp2 = toPrrayPromise([1, 2]) diff --git a/test/sort.test.ts b/test/sort.test.ts index 4f0fb3d..fe5abf1 100644 --- a/test/sort.test.ts +++ b/test/sort.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise, genRandArr } from './test-utils' const func = (a: number, b: number) => a - b @@ -20,8 +20,8 @@ const getTests = () => { test('prray sort', async t => { for (const arr of getTests()) { - const p = prray(arr) - const expect = prray(arr.sort(func)) + const p = Prray.from(arr) + const expect = Prray.from(arr.sort(func)) t.deepEqual(p.sort(func), expect) t.deepEqual(p.sort(), expect) @@ -33,7 +33,7 @@ test('prray sort', async t => { test('prraypromise sort', async t => { for (const arr of getTests()) { const pp = toPrrayPromise(arr) - const expect = prray(arr.sort(func)) + const expect = Prray.from(arr.sort(func)) t.deepEqual(await pp.sort(func), expect) t.deepEqual(await pp.sort(), expect) diff --git a/test/sortAsync.test.ts b/test/sortAsync.test.ts index f5469d2..e15201e 100644 --- a/test/sortAsync.test.ts +++ b/test/sortAsync.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { PrrayPromise } from '../src/prraypromise' import { toPrrayPromise, delay, genRandArr } from './test-utils' @@ -22,8 +22,8 @@ const getTests = () => { test('prray sortAsync', async t => { for (const arr of getTests()) { - const p = prray(arr) - const expect = prray(arr.sort(func)) + const p = Prray.from(arr) + const expect = Prray.from(arr.sort(func)) t.true(p.sortAsync(funcAsync) instanceof PrrayPromise) t.true(p.sortAsync(func) instanceof PrrayPromise) @@ -41,7 +41,7 @@ test('prray sortAsync', async t => { test('prraypromise sortAsync', async t => { for (const arr of getTests()) { const pp = toPrrayPromise(arr) - const expect = prray(arr.sort(func)) + const expect = Prray.from(arr.sort(func)) t.true(pp.sortAsync(funcAsync) instanceof PrrayPromise) t.true(pp.sortAsync(func) instanceof PrrayPromise) diff --git a/test/splice.test.ts b/test/splice.test.ts index e53c697..bbbce9c 100644 --- a/test/splice.test.ts +++ b/test/splice.test.ts @@ -1,108 +1,108 @@ import test from 'ava' import 'source-map-support/register' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray splice 1', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) - t.deepEqual(prr.splice(2, 0, 'drum'), prray([])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'mandarin', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) + t.deepEqual(prr.splice(2, 0, 'drum'), Prray.from([])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'mandarin', 'sturgeon'])) }) test('prray splice 2', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) - t.deepEqual(prr.splice(2, 0, 'drum', 'guitar'), prray([])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'guitar', 'mandarin', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) + t.deepEqual(prr.splice(2, 0, 'drum', 'guitar'), Prray.from([])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'guitar', 'mandarin', 'sturgeon'])) }) test('prray splice 3', async t => { - const prr = prray(['angel', 'clown', 'drum', 'mandarin', 'sturgeon']) - t.deepEqual(prr.splice(3, 1), prray(['mandarin'])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'drum', 'mandarin', 'sturgeon']) + t.deepEqual(prr.splice(3, 1), Prray.from(['mandarin'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'sturgeon'])) }) test('prray splice 4', async t => { - const prr = prray(['angel', 'clown', 'drum', 'sturgeon']) - t.deepEqual(prr.splice(2, 1, 'trumpet'), prray(['drum'])) - t.deepEqual(prr, prray(['angel', 'clown', 'trumpet', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'drum', 'sturgeon']) + t.deepEqual(prr.splice(2, 1, 'trumpet'), Prray.from(['drum'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'trumpet', 'sturgeon'])) }) test('prray splice 5', async t => { - const prr = prray(['angel', 'clown', 'trumpet', 'sturgeon']) - t.deepEqual(prr.splice(0, 2, 'parrot', 'anemone', 'blue'), prray(['angel', 'clown'])) - t.deepEqual(prr, prray(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'trumpet', 'sturgeon']) + t.deepEqual(prr.splice(0, 2, 'parrot', 'anemone', 'blue'), Prray.from(['angel', 'clown'])) + t.deepEqual(prr, Prray.from(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'])) }) test('prray splice 6', async t => { - const prr = prray(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon']) - t.deepEqual(prr.splice(prr.length - 3, 2), prray(['blue', 'trumpet'])) - t.deepEqual(prr, prray(['parrot', 'anemone', 'sturgeon'])) + const prr = Prray.from(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon']) + t.deepEqual(prr.splice(prr.length - 3, 2), Prray.from(['blue', 'trumpet'])) + t.deepEqual(prr, Prray.from(['parrot', 'anemone', 'sturgeon'])) }) test('prray splice 7', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) - t.deepEqual(prr.splice(-2, 1), prray(['mandarin'])) - t.deepEqual(prr, prray(['angel', 'clown', 'sturgeon'])) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) + t.deepEqual(prr.splice(-2, 1), Prray.from(['mandarin'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'sturgeon'])) }) test('prray splice 8', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) - t.deepEqual(prr.splice(2), prray(['mandarin', 'sturgeon'])) - t.deepEqual(prr, prray(['angel', 'clown'])) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) + t.deepEqual(prr.splice(2), Prray.from(['mandarin', 'sturgeon'])) + t.deepEqual(prr, Prray.from(['angel', 'clown'])) }) test('prraypromise splice 1', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(2, 0, 'drum'), prray([])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'mandarin', 'sturgeon'])) + t.deepEqual(await pp.splice(2, 0, 'drum'), Prray.from([])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'mandarin', 'sturgeon'])) }) test('prraypromise splice 2', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(2, 0, 'drum', 'guitar'), prray([])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'guitar', 'mandarin', 'sturgeon'])) + t.deepEqual(await pp.splice(2, 0, 'drum', 'guitar'), Prray.from([])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'guitar', 'mandarin', 'sturgeon'])) }) test('prraypromise splice 3', async t => { - const prr = prray(['angel', 'clown', 'drum', 'mandarin', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'drum', 'mandarin', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(3, 1), prray(['mandarin'])) - t.deepEqual(prr, prray(['angel', 'clown', 'drum', 'sturgeon'])) + t.deepEqual(await pp.splice(3, 1), Prray.from(['mandarin'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'drum', 'sturgeon'])) }) test('prraypromise splice 4', async t => { - const prr = prray(['angel', 'clown', 'drum', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'drum', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(2, 1, 'trumpet'), prray(['drum'])) - t.deepEqual(prr, prray(['angel', 'clown', 'trumpet', 'sturgeon'])) + t.deepEqual(await pp.splice(2, 1, 'trumpet'), Prray.from(['drum'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'trumpet', 'sturgeon'])) }) test('prraypromise splice 5', async t => { - const prr = prray(['angel', 'clown', 'trumpet', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'trumpet', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(0, 2, 'parrot', 'anemone', 'blue'), prray(['angel', 'clown'])) - t.deepEqual(prr, prray(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'])) + t.deepEqual(await pp.splice(0, 2, 'parrot', 'anemone', 'blue'), Prray.from(['angel', 'clown'])) + t.deepEqual(prr, Prray.from(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'])) }) test('prraypromise splice 6', async t => { - const prr = prray(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon']) + const prr = Prray.from(['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(prr.length - 3, 2), prray(['blue', 'trumpet'])) - t.deepEqual(prr, prray(['parrot', 'anemone', 'sturgeon'])) + t.deepEqual(await pp.splice(prr.length - 3, 2), Prray.from(['blue', 'trumpet'])) + t.deepEqual(prr, Prray.from(['parrot', 'anemone', 'sturgeon'])) }) test('prraypromise splice 7', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(-2, 1), prray(['mandarin'])) - t.deepEqual(prr, prray(['angel', 'clown', 'sturgeon'])) + t.deepEqual(await pp.splice(-2, 1), Prray.from(['mandarin'])) + t.deepEqual(prr, Prray.from(['angel', 'clown', 'sturgeon'])) }) test('prraypromise splice 8', async t => { - const prr = prray(['angel', 'clown', 'mandarin', 'sturgeon']) + const prr = Prray.from(['angel', 'clown', 'mandarin', 'sturgeon']) const pp = toPrrayPromise(prr) - t.deepEqual(await pp.splice(2), prray(['mandarin', 'sturgeon'])) - t.deepEqual(prr, prray(['angel', 'clown'])) + t.deepEqual(await pp.splice(2), Prray.from(['mandarin', 'sturgeon'])) + t.deepEqual(prr, Prray.from(['angel', 'clown'])) }) diff --git a/test/test-utils.ts b/test/test-utils.ts index 66fcf32..6a4edf8 100644 --- a/test/test-utils.ts +++ b/test/test-utils.ts @@ -1,5 +1,5 @@ import { prraypromise, PrrayPromise } from '../src/prraypromise' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' export const isGte3Async = (v: number) => delay(100).then(() => v >= 3) export const isGte3 = (v: number) => v >= 3 @@ -42,7 +42,7 @@ export function toPrrayPromise(arr: T[]): PrrayPromise { if (arr instanceof Prray) { return prraypromise(Promise.resolve(arr as Prray)) } - return prraypromise(Promise.resolve(prray(arr))) + return prraypromise(Promise.resolve(Prray.from(arr))) } export function isClose(n1: number, n2: number, opt = { threshold: 100 }): boolean { diff --git a/test/toArray.test.ts b/test/toArray.test.ts index 60a43ee..901f9e3 100644 --- a/test/toArray.test.ts +++ b/test/toArray.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray, Prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] -const prr = prray(arr) +const prr = Prray.from(arr) const pp = toPrrayPromise(arr) test('prray toArray', async t => { diff --git a/test/toLocaleString.test.ts b/test/toLocaleString.test.ts index ef473c3..0a00a6b 100644 --- a/test/toLocaleString.test.ts +++ b/test/toLocaleString.test.ts @@ -1,10 +1,10 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray toLocaleString', async t => { const arr = [1, 2, 3] - const prr = prray(arr) + const prr = Prray.from(arr) t.is(prr.toLocaleString(), arr.toLocaleString()) }) diff --git a/test/toString.test.ts b/test/toString.test.ts index a41c47d..ccfebae 100644 --- a/test/toString.test.ts +++ b/test/toString.test.ts @@ -1,10 +1,10 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' test('prray toString', async t => { const arr = [1, 2, 3] - const prr = prray(arr) + const prr = Prray.from(arr) t.is(prr.toString(), arr.toString()) }) diff --git a/test/unshift.test.ts b/test/unshift.test.ts index c54de24..88f49cb 100644 --- a/test/unshift.test.ts +++ b/test/unshift.test.ts @@ -1,22 +1,22 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b'] test('prray unshift', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) t.is(prr.unshift('c'), 3) t.is(prr.unshift('d', 'e'), 5) - t.deepEqual(prr, prray(['d', 'e', 'c', 'a', 'b'])) + t.deepEqual(prr, Prray.from(['d', 'e', 'c', 'a', 'b'])) }) test('prraypromise unshift', async t => { - const prr = prray(arr) + const prr = Prray.from(arr) const pp = toPrrayPromise(prr) t.is(await pp.unshift('c'), 3) t.is(await pp.unshift('d', 'e'), 5) - t.deepEqual(prr, prray(['d', 'e', 'c', 'a', 'b'])) + t.deepEqual(prr, Prray.from(['d', 'e', 'c', 'a', 'b'])) }) diff --git a/test/values.test.ts b/test/values.test.ts index 1eaf08b..f5f1e4e 100644 --- a/test/values.test.ts +++ b/test/values.test.ts @@ -1,9 +1,9 @@ import test from 'ava' -import { prray } from '../src/prray' +import Prray from '../src/prray' import { toPrrayPromise } from './test-utils' const arr = ['a', 'b', 'c', 'd'] -const p = prray(arr) +const p = Prray.from(arr) const pp = toPrrayPromise(arr) test('prray values', async t => {