{"id":16442427,"url":"https://github.com/doug-martin/promise-utils","last_synced_at":"2025-03-23T08:32:00.415Z","repository":{"id":57331518,"uuid":"9941288","full_name":"doug-martin/promise-utils","owner":"doug-martin","description":"Collection of promise utilities","archived":false,"fork":false,"pushed_at":"2013-06-06T21:41:59.000Z","size":248,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T19:19:00.328Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://doug-martin.github.io/promise-utils/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doug-martin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-08T16:48:52.000Z","updated_at":"2022-11-24T15:03:42.000Z","dependencies_parsed_at":"2022-09-10T10:38:08.008Z","dependency_job_id":null,"html_url":"https://github.com/doug-martin/promise-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fpromise-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fpromise-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fpromise-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-martin%2Fpromise-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doug-martin","download_url":"https://codeload.github.com/doug-martin/promise-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078067,"owners_count":20557274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T09:17:22.939Z","updated_at":"2025-03-23T08:32:00.016Z","avatar_url":"https://github.com/doug-martin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/doug-martin/promise-utils.png?branch=master)](https://travis-ci.org/doug-martin/promise-utils)\n\n[![browser support](https://ci.testling.com/doug-martin/promise-utils.png)](http://ci.testling.com/doug-martin/promise-utils)\n\n# promise-utils\n\n`promise-utils` is a Javascript library that provides utilities for working with promises. `promise-utils` can be used as a monad library for promises or each function can be used standalone.\n\nThis library uses [`promise-extended`](https://github.com/doug-martin/promise-extended) internally but can be used with any promises A+ compliant library such as [`Q`](https://github.com/kriskowal/q)\n\n`promise-utils` can be used standalone or incorporated into [`extended`](https://github.com/doug-martin/extended)\n\n```javascript\nvar pUtils = require(\"promise-utils\");\n```\n\nOr\n\n```javascript\nvar myextended = require(\"extended\")\n\t.register(require(\"promise-extended\"));\n```\n\n## Installation\n\n```\nnpm install promise-utils\n```\n\nOr [download the source](https://raw.github.com/doug-martin/promise-utils/master/index.js) ([minified](https://raw.github.com/doug-martin/promise-utils/master/promise-utils.min.js))\n\n## Usage\n\n### Arrays\n\n`promise-utils` can be used with promises or normal arrays by using the `async` method.\n\n**NOTE** The examples below uses a `resolve` method which represents turning an array into a promise resolved with the given array. This is used for brevity where you would typically be working with promises returned from an asynchronous method such as a database call.\n\n```javascript\n\nvar arr = [1,2,3];\nvar promiseArr = resolve(arr);\n\npUtils(arr).async().forEach(function(item){\n    console.log(item);\n}).then(function(){\n    console.log(\"Done Looping\");\n});\n\n//OR\n\npUtils(promiseArr).forEach(function(item){\n    console.log(item);\n}).then(function(){\n    console.log(\"Done Looping\");\n});\n\n\n```\n\n**Chaining**\n\nWhen using `promise-utils` as a monad with a promise you may chain methods together.\n\n```javascript\n\nvar arr = resolve([1, 2, 3, 4, 5]);\npUtils(arr)\n    .map(function (num, i) {\n        return num * (i + 1);\n    })\n    .filter(function (num) {\n        return num % 2;\n    })\n    .avg()\n    .then(function(res){\n        //11.666666666666666\n    });\n\n```\n\n**`forEach`**\n\nSimilar to `Array#forEach` except that it resolves with the original array for chaining.\n\n```javascript\n//as a monad\n\npUtils(resolve([1, 2, 3])).forEach(function(item){\n    console.log(item);\n}).then(function(){\n    console.log(\"Done Looping\");\n});\n\npUtils.forEach(resolve([1, 2, 3]), function(item){\n    console.log(item);\n}).then(function(){\n    console.log(\"Done Looping\");\n});\n\n```\n\nYou may also return a promise from the iterator function, which will prevent the returned promise from resolving until all the returned promises are done.\n\n```javascript\npUtils(resolve([1, 2, 3])).forEach(function(item){\n     var ret = new Promise();\n     setTimeout(function(){\n        ret.callback(item);\n     }, 200);\n     return ret.promise();\n}).then(function(){\n    //all promises from iterator function are resolved.\n    console.log(\"Done Looping\");\n});\n\n```\n\nYou may also specify a `limit` which will specify the number of items to be looped at a time, if limit is not specified then all items will be iterated regardless of whether or not the previous item in the array is done.\n\n\n```javascript\n\npUtils(resolve([1, 2, 3])).forEach(function(item){\n    var ret = new Promise();\n    setTimeout(function(){\n        ret.callback(item);\n    }, 200);\n    return ret.promise();\n}, 1).then(function(){\n    console.log(\"Done Looping\");\n});\n\n```\n\nIn the above example only one item will be iterated one at a time.\n\n**`map`**\n\nAsync version of `Array#map`.\n\n```javascript\n//as a monad\n\npUtils(resolve([1, 2, 3])).map(function(item){\n    return item * 2;\n}).then(function(result){\n    console.log(result); //[2, 4, 6];\n});\n\npUtils.map(resolve([1, 2, 3]), function(item){\n    return item * 2;\n}).then(function(result){\n    console.log(result); //[2, 4, 6];\n});\n\n```\n\nYou may also return a promise from the iterator function, which will prevent the returned promise from resolving until all the returned promises are done.\n\n```javascript\n //as a monad\n\npUtils(resolve([1, 2, 3])).map(function(item){\n     var ret = new Promise();\n     setTimeout(function(){\n        ret.callback(item * 2);\n     }, 200);\n     return ret.promise();\n}).then(function(result){\n    console.log(result); //[2, 4, 6];\n});\n\n```\n\nYou may also specify a `limit` which will specify the number of items to be looped at a time, if limit is not specified then all items will be iterated regardless of whether or not the previous item in the array is done.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).map(function(item){\n    var ret = new Promise();\n    setTimeout(function(){\n        ret.callback(item * 2);\n    }, 200);\n    return ret.promise();\n}, 1).then(function(){\n    console.log(result); //[2, 4, 6];\n});\n\n```\n\nIn the above example only one item will be iterated at a time.\n\n**`filter`**\n\nAsync version of `Array#filter`.\n\n```javascript\n//as a monad\n\npUtils(resolve([1, 2, 3])).filter(function(item){\n    return item % 2;\n}).then(function(result){\n    console.log(result); //[1, 3];\n});\n\npUtils.filter(resolve([1, 2, 3]), function(item){\n    return item % 2;\n}).then(function(result){\n    console.log(result); //[1, 3];\n});\n\n```\n\nYou may also return a promise from the iterator function, which will prevent the returned promise from resolving until all the returned promises are done.\n\n```javascript\n //as a monad\n\npUtils(resolve([1, 2, 3])).filter(function(item){\n     var ret = new Promise();\n     setTimeout(function(){\n        ret.callback(item % 2);\n     }, 200);\n     return ret.promise();\n}).then(function(result){\n    console.log(result); //[1, 3];\n});\n\n```\n\nYou may also specify a `limit` which will specify the number of items to be looped at a time, if limit is not specified then all items will be iterated regardless of whether or not the previous item in the array is done.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).filter(function(item){\n    var ret = new Promise();\n    setTimeout(function(){\n        ret.callback(item % 2);\n    }, 200);\n    return ret.promise();\n}, 1).then(function(){\n    console.log(result); //[1, 3];\n});\n\n```\n\nIn the above example only one item will be iterated at a time.\n\n**`every`**\n\nAsync version of `Array#every`.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).every(function(item){\n    return isNumber(item);\n}).then(function(result){\n    console.log(result); //true;\n});\n\npUtils.every(resolve([1, 2, 3]), function(item){\n    return isNumber(item);\n}).then(function(result){\n    console.log(result); //true;\n});\n\n```\n\nYou may also return a promise from the iterator function, which will prevent the returned promise from resolving until all the returned promises are done.\n\n```javascript\n //as a monad\n\npUtils(resolve([1, 2, 3])).every(function(item){\n     var ret = new Promise();\n     setTimeout(function(){\n        ret.callback(isNumber(item));\n     }, 200);\n     return ret.promise();\n}).then(function(result){\n    console.log(result); //[true];\n});\n\n```\n\nYou may also specify a `limit` which will specify the number of items to be looped at a time, if limit is not specified then all items will be iterated regardless of whether or not the previous item in the array is done.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).every(function(item){\n    var ret = new Promise();\n    setTimeout(function(){\n        ret.callback(isNumber(item));\n    }, 200);\n    return ret.promise();\n}, 1).then(function(){\n    console.log(result); //true;\n});\n\n```\n\nIn the above example only one item will be iterated at a time.\n\n**`some`**\n\nAsync version of `Array#every`.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).some(function(item){\n    return item === 1;\n}).then(function(result){\n    console.log(result); //true;\n});\n\npUtils.some(resolve([1, 2, 3]), function(item){\n    return item === 1;\n}).then(function(result){\n    console.log(result); //true;\n});\n\n```\n\nYou may also return a promise from the iterator function, which will prevent the returned promise from resolving until all the returned promises are done.\n\n```javascript\n //as a monad\n\npUtils(resolve([1, 2, 3])).some(function(item){\n     var ret = new Promise();\n     setTimeout(function(){\n        ret.callback(item === 1);\n     }, 200);\n     return ret.promise();\n}).then(function(result){\n    console.log(result); //[true];\n});\n\n```\n\nYou may also specify a `limit` which will specify the number of items to be looped at a time, if limit is not specified then all items will be iterated regardless of whether or not the previous item in the array is done.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).some(function(item){\n    var ret = new Promise();\n    setTimeout(function(){\n        ret.callback(item === 1);\n    }, 200);\n    return ret.promise();\n}, 1).then(function(){\n    console.log(result); //true;\n});\n\n```\n\nIn the above example only one item will be iterated at a time.\n\n**`sum`**\n\nSums the values of an array\n\n```javascript\n\npUtils.sum(resolve([1,2,3])).then(function(sum){\n   //6\n});\n\npUtils(resolve([1,2,3])).sum().then(function(sum){\n    //6\n});\n\n```\n\n**`avg`**\n\nFinds the average of an array of numbers.\n\n```javascript\n\npUtils.avg(resolve([1,2,3])).then(function(avg){\n    //2\n});\n\npUtils(resolve([1,2,3])).avg().then(function(avg){\n    //2\n});\n```\n\n**`sort`**\n\nSorts an array based on a property, by natural ordering, or by a custom comparator.\n\n**Note** this does not change the original array.\n\n```javascript\n\npUtils.sort(resolve([{a: 1},{a: 2},{a: -2}]), \"a\").then(function(sorted){\n    //[{a: -2},{a: 1},{a: 2}];\n})\n\npUtils(resolve([{a: 1},{a: 2},{a: -2}])).sort(\"a\").then(function(sorted){\n    //[{a: -2},{a: 1},{a: 2}];\n})\n\n\n```\n\n**`min`**\n\nFinds the minimum value in an array based on a property, by natural ordering, or by a custom comparator.\n\n```javascript\n\npUtils.min(resolve([ 3, -3, -2, -1, 1, 2])).then(function(min){\n    //-3\n});\n\npUtils.min(resolve([{a: 1},{a: 2},{a: -2}]), \"a\").then(function(min){\n    //{a : -2}\n});\n\npUtils(resolve([ 3, -3, -2, -1, 1, 2])).min().then(function(min){\n    //-3\n});\n\npUtils(resolve([{a: 1},{a: 2},{a: -2}])).min(\"a\").then(function(min){\n    //{a : -2}\n});\n\n```\n\n**`max`**\n\nFinds the maximum value in an array based on a property, by natural ordering, or by a custom comparator.\n\n```javascript\n\npUtils.max(resolve([ 3, -3, -2, -1, 1, 2])).then(function(max){\n     //2\n});\n\npUtils.max(resolve([{a: 1},{a: 2},{a: -2}]), \"a\").then(function(max){\n    //{a : 2}\n});\n\npUtils(resolve([ 3, -3, -2, -1, 1, 2])).max().then(function(max){\n    //2\n});\n\npUtils(resolve([{a: 1},{a: 2},{a: -2}])).max(\"a\").then(function(max){\n    //{a : 2}\n});\n\n```\n\n**`difference`**\n\nFinds the difference between two arrays.\n\n```javascript\npUtils.difference(resolve([1, 2, 3]), [2]).then(function(diff){\n    //[1, 3]\n});\npUtils.difference(resolve([true, false]), resolve([false])).then(function(diff){\n    //[true]\n});\n\npUtils.difference(resolve([\"a\", \"b\", 3]), resolve([3])).then(function(diff){\n    //[\"a\", \"b\"]\n});\n\npUtils.difference(resolve([{a: 1}, {a: 2}, {a: 3}]), resolve([{a: 2}, {a: 3}])).then(function(diff){\n    //[{a: 1}]\n});\n\npUtils(resolve([true, false])).difference([false]).then(function(diff){\n    // [true]\n});\n\npUtils(resolve([1, 2, 3])).difference(resolve([2])).then(function(diff){\n    // [1, 3]\n});\npUtils(resolve([1, 2, 3])).difference([2], resolve([3])).then(function(diff){\n     //[1]\n});\n\npUtils(resolve([\"a\", \"b\", 3])).difference([3]).then(function(diff){\n     //[\"a\", \"b\"]\n});\npUtils(resolve([{a: 1}, {a: 2}, {a: 3}])).difference(resolve([{a: 2}, {a: 3}])).then(function(diff){\n    // [{a: 1}]\n});\n```\n\n**`unique`**\n\nRemoved duplicate values from an array\n\n```javascript\n\npUtils.unique(resolve([1, 2, 2, 3, 3, 3, 4, 4, 4])).then(function(unique){\n    //[1, 2, 3, 4]\n}):\npUtils(resolve([1, 2, 2, 3, 3, 3, 4, 4, 4])).unique().then(function(unique){\n    //[1, 2, 3, 4]\n});\n\npUtils(resolve([\"a\", \"b\", \"b\"])).unique().then(function(unique){\n    //[\"a\", \"b\"]\n});\n\npUtils.unique(resolve([\"a\", \"b\", \"b\"])).then(function(unique){\n    //[\"a\", \"b\"]\n});\n```\n\n**`rotate`**\n\nRotates an array by the number of places for 1 position by default.\n\n```javascript\n\nvar arr = pUtils(resolve([\"a\", \"b\", \"c\", \"d\"]))\narr.rotate();   //resolves with [\"b\", \"c\", \"d\", \"a\"]\narr.rotate(2);  //resolves with [\"c\", \"d\", \"a\", \"b\"]\narr.rotate(3);  //resolves with [\"d\", \"a\", \"b\", \"c\"]\narr.rotate(4);  //resolves with [\"a\", \"b\", \"c\", \"d\"]\narr.rotate(-1); //resolves with [\"d\", \"a\", \"b\", \"c\"]\narr.rotate(-2); //resolves with [\"c\", \"d\", \"a\", \"b\"]\narr.rotate(-3); //resolves with [\"b\", \"c\", \"d\", \"a\"]\narr.rotate(-4); //resolves with [\"a\", \"b\", \"c\", \"d\"]\n\narr = resolve([\"a\", \"b\", \"c\", \"d\"]);\npUtils.rotate(arr);     //resolves with [\"b\", \"c\", \"d\", \"a\"]\npUtils.rotate(arr, 2);  //resolves with [\"c\", \"d\", \"a\", \"b\"]\npUtils.rotate(arr, 3);  //resolves with [\"d\", \"a\", \"b\", \"c\"]\npUtils.rotate(arr, 4);  //resolves with [\"a\", \"b\", \"c\", \"d\"]\npUtils.rotate(arr, -1)  //resolves with [\"d\", \"a\", \"b\", \"c\"]\npUtils.rotate(arr, -2); //resolves with [\"c\", \"d\", \"a\", \"b\"]\npUtils.rotate(arr, -3); //resolves with [\"b\", \"c\", \"d\", \"a\"]\npUtils.rotate(arr, -4); //resolves with [\"a\", \"b\", \"c\", \"d\"]\n\n```\n\n**`permutations`**\n\nFinds all permutations of an array.\n\n```javascript\n\npUtils(resolve([1, 2, 3])).permutations(); //resolves with [\n                                 //   [ 1, 2, 3 ],\n                                 //   [ 1, 3, 2 ],\n                                 //   [ 2, 3, 1 ],\n                                 //   [ 2, 1, 3 ],\n                                 //   [ 3, 1, 2 ],\n                                 //   [ 3, 2, 1 ]\n                                 //]\n\npUtils(resolve([1, 2, 3])).permutations(2);// resolves with [\n                                           //   [ 1, 2],\n                                           //   [ 1, 3],\n                                           //   [ 2, 3],\n                                           //   [ 2, 1],\n                                           //   [ 3, 1],\n                                           //   [ 3, 2]\n                                           //]\n\npUtils.permutations(resolve([1, 2, 3]));   // resolves with [\n                                 //   [ 1, 2, 3 ],\n                                 //   [ 1, 3, 2 ],\n                                 //   [ 2, 3, 1 ],\n                                 //   [ 2, 1, 3 ],\n                                 //   [ 3, 1, 2 ],\n                                 //   [ 3, 2, 1 ]\n                                 //]\n\npUtils.permutations(resolve([1, 2, 3]), 2); //resolves with [\n                                    //   [ 1, 2],\n                                    //   [ 1, 3],\n                                    //   [ 2, 3],\n                                    //   [ 2, 1],\n                                    //   [ 3, 1],\n                                    //   [ 3, 2]\n                                    //]\n\n```\n\n**`zip`**\n\nZips the values of multiple arrays into a single pUtils.\n\n```javascript\n\npUtils(resolve([1])).zip(resolve([2]), resolve([3]));//resolves with [\n                                                     //  [ 1, 2, 3 ]\n                                                     //];\n\npUtils(resolve([1, 2])).zip(resolve([2]), [3]);      //resolves with [\n                                                     //  [ 1, 2, 3 ],\n                                                     //  [2, null, null]\n                                                     //]\n\npUtils(resolve([1, 2, 3])).zip([ 4, 5, 6 ], b);      //resolves with [\n                                                     //  [1, 4, 7],\n                                                     //  [2, 5, 8],\n                                                     //  [3, 6, 9]\n                                                     //]\n\npUtils(resolve([1, 2])).zip([ 4, 5, 6 ], resolve([7, 8, 9 ])); //resolves with [\n                                                               //  [1, 4, 7],\n                                                               //  [2, 5, 8]\n                                                               //]\n\npUtils(resolve([ 4, 5, 6 ])).zip([1, 2], [8]);       //resolves with [\n                                                     //  [4, 1, 8],\n                                                     //  [5, 2, null],\n                                                     //  [6, null, null]\n                                                     //]\n\n\npUtils.zip(resolve([1]), [2], [3]);                  //resolves with [\n                                                     //  [ 1, 2, 3 ]\n                                                     //]\n\npUtils.zip(resolve([1, 2]), resolve([2]), [3]);      //resolves with [\n                                                     //  [ 1, 2, 3 ],\n                                                     //  [2, null, null]\n                                                     //]\n\npUtils.zip(resolve([1, 2, 3]), [4,5,6],  resolve([7, 8, 9 ])); //resolves with [\n                                                               //  [1, 4, 7],\n                                                               //  [2, 5, 8],\n                                                               //  [3, 6, 9]\n                                                               //]\n\npUtils.zip(resolve([1, 2]), [4,5,6],  [7, 8, 9 ]);    //resolves with [\n                                                      //  [1, 4, 7],\n                                                      //  [2, 5, 8]\n                                                      //]\n\npUtils.zip([ 4, 5, 6 ], [1, 2], resolve([8]));        //resolves with [\n                                                      //  [4, 1, 8],\n                                                      //  [5, 2, null],\n                                                      //  [6, null, null]\n                                                      //]\n\n```\n\n**`transpose`**\n\nTranspose a multi dimensional array.\n\n```javascript\npUtils(resolve([[1, 2, 3],[4, 5, 6]])).transpose();   //resolves with [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]\npUtils([[1, 2],[3, 4],[5, 6]]).async().transpose();   //resolves with [ [ 1, 3, 5 ], [ 2, 4, 6 ] ]\npUtils(resolve([[1],[3, 4],[5, 6]])).transpose();     //resolves with [ [1] ]\n\n\npUtils.transpose(resolve([[1, 2, 3],[4, 5, 6]]));     //resolves with [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]\npUtils.transpose(resolve([[1, 2],[3, 4],[5, 6]]));    //resolves with [ [ 1, 3, 5 ], [ 2, 4, 6 ] ]\npUtils.transpose(resolve([[1],[3, 4],[5, 6]]));       //resolves with [ [1] ]\n```\n\n**`valuesAt`**\n\nGathers values at the specified indexes.\n\n```javascript\n\nvar arr = pUtils(resolve([\"a\", \"b\", \"c\", \"d\"]));\narr.valuesAt(1, 2, 3);      //resolves with [\"b\", \"c\", \"d\"]\narr.valuesAt(1, 2, 3, 4);   //resolves with [\"b\", \"c\", \"d\", null]\narr.valuesAt(0, 3);         //resolves with [\"a\", \"d\"]\n\narr = resolve([\"a\", \"b\", \"c\", \"d\"]);\npUtils.valuesAt(arr, 1, 2, 3);       //resolves with [\"b\", \"c\", \"d\"]\npUtils.valuesAt(arr, 1, 2, 3, 4);    //resolves with [\"b\", \"c\", \"d\", null]\npUtils.valuesAt(arr, 0, 3);          //resolves with [\"a\", \"d\"]\n```\n\n**`union`**\n\nFinds the union of two arrays.\n\n```javascript\npUtils(resolve([\"a\", \"b\", \"c\"])).union([\"b\", \"c\", \"d\"]);           //resolves with [\"a\", \"b\", \"c\", \"d\"]);\npUtils([\"a\"]).async().union([\"b\"], [\"c\"], [\"d\"], resolve([\"c\"]));  //resolves with [\"a\", \"b\", \"c\", \"d\"]);\n\npUtils.union(resolve([\"a\", \"b\", \"c\"]), [\"b\", \"c\", \"d\"]);           //resolves with [\"a\", \"b\", \"c\", \"d\"]);\npUtils.union(resolve([\"a\"]), [\"b\"], resolve([\"c\"]), [\"d\"], [\"c\"]); //resolves with [\"a\", \"b\", \"c\", \"d\"]);\n```\n\n**`intersect`**\n\nFinds the intersection of arrays.\n\n```javascript\npUtils(resolve([1, 2])).intersect([2, 3], [2, 3, 5]);                            //resolves with [2];\npUtils(resolve([1, 2, 3])).intersect([2, 3, 4, 5], [2, 3, 5]);                   //resolves with [2, 3];\npUtils(resolve([1, 2, 3, 4])).intersect([2, 3, 4, 5], [2, 3, 4, 5]);             //resolves with [2, 3, 4];\npUtils(resolve([1, 2, 3, 4, 5])).intersect([1, 2, 3, 4, 5], [1, 2, 3]);          //resolves with [1, 2, 3];\npUtils(resolve([[1, 2, 3, 4, 5],[1, 2, 3, 4, 5],[1, 2, 3]])).intersect();        //resolves with [1, 2, 3];\n\npUtils.intersect(resolve([1, 2]), [2, 3], [2, 3, 5]);                             //resolves with [2]\npUtils.intersect(resolve([1, 2, 3]), [2, 3, 4, 5], [2, 3, 5]);                    //resolves with [2, 3]\npUtils.intersect(resolve([1, 2, 3, 4]), [2, 3, 4, 5], resolve([2, 3, 4, 5]));     //resolves with [2, 3, 4]\npUtils.intersect(resolve([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5], [1, 2, 3]);           //resolves with [1, 2, 3]);\npUtils.intersect(resolve([[1, 2, 3, 4, 5],[1, 2, 3, 4, 5], [1, 2, 3]]));          //resolves with [1, 2, 3]);\n```\n\n**`powerSet`**\n\nFinds the powerset of a given array.\n\n```javascript\npUtils(resolve([1, 2, 3])).powerSet();\npUtils.powerSet(resolve([1, 2, 3]));\n//Both resolve with\n//[\n//  [],\n//  [ 1 ],\n//  [ 2 ],\n//  [ 1, 2 ],\n//  [ 3 ],\n//  [ 1, 3 ],\n//  [ 2, 3 ],\n//  [ 1, 2, 3 ]\n//]\n```\n\n**`cartesian`**\n\nFinds the cartesian product of arrays.\n\n```javascript\npUtils(resolve([1, 2])).cartesian(resolve([2, 3]));\npUtils.cartesian(resolve([1, 2]), [2, 3]);\n//Both resolve with\n//[\n//  [1, 2],\n//  [1, 3],\n//  [2, 2],\n//  [2, 3]\n//]\n```\n\n**`compact`**\n\nCompacts the values of an array.\n\n```javascript\npUtils(resolve([1, null, null, x, 2])).compact(); //Resolves with [1, 2]\n\npUtils([1, 2]).async().compact();  //Resolves with [1, 2]\n\n\npUtils.compact(resolve([1, null, null, x, 2])); //Resolves with [1, 2]\npUtils.compact(resolve([1, 2])); //Resolves with [1, 2]\n```\n\n**`multiply`**\n\nReproduces the values in an array the given number of times.\n\n```javascript\npUtils(resolve([1, 2])).multiply(2); //Resolves with[1, 2, 1, 2, 1, 2]\n\npUtils.multiply(resolve([1, 2, 3]), 2); //Resolves with [1, 2, 3, 1, 2, 3]\n```\n\n**`flatten`**\n\nFlatten multiple arrays into a single array.\n\n```javascript\n\npUtils(resolve([ [1], [2], [3] ])).flatten(); //Resolves with [1, 2, 3]\n\npUtils.flatten(resolve([1, 2]), [2, 3], resolve([3, 4])); //Resolves with [1, 2, 2, 3, 3, 4]\n\n```\n\n**`pluck`**\n\nPluck properties from values in an array.\n\n**NOTE** Plucked properties may also be promises. `pluck` will return the resolved value of the promise\n\n```javascript\nvar arr = resolve([\n    {name: {first: \"Fred\", last: \"Jones\"}, age: 50, roles: [\"a\", \"b\", \"c\"]},\n    {name: {first: resolve(\"Bob\"), last: \"Yukon\"}, age: resolve(40), roles: resolve([\"b\", \"c\"])},\n    {name: {first: \"Alice\", last: \"Palace\"}, age: 35, roles: [\"c\"]},\n    {name: {first: resolve(\"Johnny\"), last: \"P.\"}, age: 56, roles: resolve([])}\n]);\n\npUtils.pluck(arr, \"name.first\"); //Resolves with [\"Fred\", \"Bob\", \"Alice\", \"Johnny\"]\npUtils(arr).pluck(\"age\"); //Resolves with [50, 40, 35, 56]\n\n```\n\n**`invoke`**\n\nInvokes the specified method on each value in an array.\n\n```javascript\n\nfunction person(name, age) {\n    return {\n        getName: function () {\n            return resolve(name);\n        },\n\n        getOlder: function () {\n            age++;\n            return resolve(this);\n        },\n\n        getAge: function () {\n            return resolve(age);\n        }\n    };\n};\n\nvar arr = resolve([person(\"Bob\", 40), person(\"Alice\", 35), person(\"Fred\", 50), person(\"Johnny\", 56)]);\n\npUtils.invoke(arr, \"getName\"); //Resolves with [\"Bob\", \"Alice\", \"Fred\", \"Johnny\"];\npUtils(arr).invoke(\"getName\"); //Resolves with [\"Bob\", \"Alice\", \"Fred\", \"Johnny\"];\n\npUtils(arr).invoke(\"getOlder\").invoke(\"getAge\"); //Resolves with [41, 36, 51, 57];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-martin%2Fpromise-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoug-martin%2Fpromise-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-martin%2Fpromise-utils/lists"}