{"id":19839490,"url":"https://github.com/xeaone/promise-tool","last_synced_at":"2025-05-01T19:30:21.498Z","repository":{"id":57331512,"uuid":"77550566","full_name":"xeaone/promise-tool","owner":"xeaone","description":"promise-tool","archived":false,"fork":false,"pushed_at":"2017-11-12T20:26:03.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T14:18:30.879Z","etag":null,"topics":["js","library","promise","sequence","timers","tools"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xeaone.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":"2016-12-28T17:43:20.000Z","updated_at":"2022-05-22T17:20:15.000Z","dependencies_parsed_at":"2022-09-14T18:52:04.262Z","dependency_job_id":null,"html_url":"https://github.com/xeaone/promise-tool","commit_stats":null,"previous_names":["alexanderelias/promise-tool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fpromise-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fpromise-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fpromise-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fpromise-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeaone","download_url":"https://codeload.github.com/xeaone/promise-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932513,"owners_count":21667157,"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":["js","library","promise","sequence","timers","tools"],"created_at":"2024-11-12T12:22:49.521Z","updated_at":"2025-05-01T19:30:21.131Z","avatar_url":"https://github.com/xeaone.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promise Tool\nA promised library of tools for Node.js and the browser.\n\n## Install\n`npm install promise-tool --save`\n\n\n## API\n- `PromiseTool.lift()` Lifts a callback style function or prototype object and converts to a promise/s first argument must be an error.\n\n- `PromiseTool.series` A given task will not be started until the preceding task completes.\n\t- `tasks` \u003cArray\u003e The array of functions to execute in series.\n\t\t- `task` \u003cFunction\u003e A function which returns a promise.\n\t\t\t- `resolve(result)` \u003cAny\u003e A result which will be appended to the end of each task/function as parameter.\n\t- `parameters` \u003cArray\u003e An Array of parameters to be passed to each task/function. **Optional**\n\n- `PromiseTool.setTimeout`\n\t- `delay` \u003cNumber\u003e The number of milliseconds to wait before calling resolve.\n\t- `...args` \u003cAny\u003e Optional arguments to pass when the resolve is executed.\n\n\n- `PromiseTool.setInterval`\n\t- `delay` \u003cNumber\u003e The number of milliseconds to wait before calling resolve.\n\t- `method` \u003cFunction\u003e A function that repeats on each interval. This function will fire upon each interval unless one of the following returns are implemented.\n\t\t- Return Value Actions\n\t\t\t- `result` \u003cError\u003e Any valid JavaScript error type. Will fire the reject and pass the error.\n\t\t\t- `result` \u003cBoolean\u003e A boolean that calls resolve if true or reject if false.\n\t\t\t- `result` \u003cAny\u003e Any thing returned besides `null`, `undefined`, `false`, and a valid `Error` type will resolve with that return value as the first argument.\n\t\t\t- `result` \u003cNull, Undefined\u003e Both are ignored and will not trigger the resolve or reject.\n\t- `...args` \u003cAny\u003e Optional arguments to pass when the resolve is executed.\n\n\n- `PromiseTool.setImmediate`\n\t- `...args` \u003cAny\u003e Optional arguments to pass when the resolve is executed.\n\n\n- `PromiseTool.clearTimeout`\n\t- `timeout` \u003cTimeout\u003e A Timeout object as returned by setInterval().\n\n\n- `PromiseTool.clearInterval`\n\t- `interval` \u003cInterval\u003e A Interval object as returned by setInterval().\n\n\n- `PromiseTool.clearImmediate`\n\t- `immediate` \u003cImmediate\u003e An Immediate object as returned by setImmediate().\n\n\n## Examples\n\n### Series\n```JavaScript\nvar PromiseTool = require('../index.js');\n\nfunction a (one, two) {\n\treturn new Promise (function (resolve) {\n\t\tsetTimeout(function () {\n\t\t\treturn resolve(`a-${one}${two}`);\n\t\t}, 900);\n\t});\n}\n\nfunction b (one, two, result) {\n\treturn new Promise (function (resolve) {\n\t\tsetTimeout(function () {\n\t\t\tresult = `${result} b-${one}${two}`;\n\t\t\treturn resolve(result);\n\t\t}, 600);\n\t});\n}\n\nPromiseTool.series([a, b], [1, 2]).then(function (result) {\n\tconsole.log(result); // a-12 b-12\n});\n```\n\n### Timers\n```JavaScript\nvar PromiseTool = require('promise-timers');\nvar delay = 500;\n\nPromiseTool.setTimeout(delay).then(function (args) {\n\t// this refers to timeout\n\tconsole.log(args);\n\tconsole.log('timeout done');\n});\n\nvar i = 0;\n\nfunction method () {\n\t// this refers to interval\n\tif (i \u003e 5) {\n\t\treturn true;\n\t} else {\n\t\tconsole.log(i);\n\t\ti++;\n\t}\n};\n\n PromiseTool.setInterval(delay, method).then(function (args) {\n\t// this refers to interval\n\tconsole.log(args);\n\tconsole.log('interval done');\n});\n\nPromiseTool.setImmediate().then(function (args) {\n\t// this refers to immediate\n   console.log(args);\n   console.log('immediate done');\n});\n\n```\n\n## Authors\n[AlexanderElias](https://github.com/AlexanderElias)\n\n## License\n[Why You Should Choose MPL-2.0](http://veldstra.org/2016/12/09/you-should-choose-mpl2-for-your-opensource-project.html)\nThis project is licensed under the MPL-2.0 License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeaone%2Fpromise-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeaone%2Fpromise-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeaone%2Fpromise-tool/lists"}