{"id":16007622,"url":"https://github.com/uzitech/promisificator","last_synced_at":"2025-03-18T02:32:13.835Z","repository":{"id":9339029,"uuid":"61749245","full_name":"UziTech/promisificator","owner":"UziTech","description":"Returns a promise and a callback that will fullfill the promise.","archived":false,"fork":false,"pushed_at":"2024-10-09T09:58:59.000Z","size":2026,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-15T12:18:39.497Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/promisificator","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/UziTech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["UziTech"]}},"created_at":"2016-06-22T20:26:38.000Z","updated_at":"2024-10-09T09:59:02.000Z","dependencies_parsed_at":"2023-12-23T01:31:40.142Z","dependency_job_id":"c590fe48-304b-4e9d-8985-8dd5e450f9a7","html_url":"https://github.com/UziTech/promisificator","commit_stats":{"total_commits":540,"total_committers":6,"mean_commits":90.0,"dds":0.5092592592592593,"last_synced_commit":"d781dd2e386fdc07001ba22337dec2b141b2afae"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UziTech%2Fpromisificator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UziTech%2Fpromisificator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UziTech%2Fpromisificator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UziTech%2Fpromisificator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UziTech","download_url":"https://codeload.github.com/UziTech/promisificator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243894541,"owners_count":20365048,"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-08T12:04:21.375Z","updated_at":"2025-03-18T02:32:13.489Z","avatar_url":"https://github.com/UziTech.png","language":"JavaScript","funding_links":["https://github.com/sponsors/UziTech"],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/UziTech/promisificator/workflows/CI/badge.svg)](https://github.com/UziTech/promisificator/actions)\n\n# promisificator\n\nReturns a `promise` and a `callback` that will fulfill the `promise`.\n\n## Examples\n\n#### 1. Use the callback in an async function to resolve the promise\n\n```javascript\nconst fs = require(\"fs\");\nconst promisificator = require(\"promisificator\");\n\nconst {\n  promise,\n  callback,\n} = promisificator({rejectOnError: true});\n\n//`callback` can be passed to any async function that takes a callback\nfs.readFile(\"/etc/password\", callback);\n\n//`promise` will be fulfilled once the callback is called\npromise.then((data) =\u003e {\n  console.log(data);\n}, (err) =\u003e {\n  throw err;\n});\n```\n\n#### 2. Allow a function to accept a callback or return a promise\n\n```javascript\nconst promisificator = require(\"promisificator\");\n\nfunction myFunc(arg, cb) {\n  const {\n    promise,\n    callback,\n  } = promisificator(cb);\n\n  // `cb` will be wrapped in `process.nextTick` so it won't be\n  // called immediately if it is a callback\n  callback(null, arg);\n\n  // if `cb` is a function `promise` will be undefined\n  return promise;\n}\n\nmyFunc(\"promise\").then(console.log, console.error);\n\nmyFunc(\"callback\", (err, result) =\u003e {\n  if (err) {\n    return console.error(err);\n  }\n  console.log(result);\n});\n```\n\n#### 3. Turn a callback function into a promise\n\n```javascript\nconst fs = require(\"fs\");\nconst { promisify } = require(\"promisificator\");\n\n//`promisify(fs.readFile)` will return a function that returns a promise\npromisify(fs.readFile, {callbackArg: -1})(\"/etc/password\").then((data) =\u003e {\n  console.log(data);\n}, (err) =\u003e {\n  throw err;\n});\n```\n\n## Options\n\n#### rejectOnError\n\nDefault: `true`\n\nReject the promise if the first argument of the callback is truthy.\n\n#### alwaysReturnArray\n\nDefault: `false`\n\nResolve the promise with an array of values if there is only one argument.\n\nBy default Promisificator will return an array only if there is more than one non-error argument sent to the callback.\n\n#### useNextTick\n\nDefault: `true`\n\nIf a callback is provided use [`process.nextTick`](https://nodejs.org/api/process.html#process_process_nexttick_callback_args) when calling the callback to ensure that it is called asynchronously.\n\nIf this is set to `false` the callback can be called before the function returns, which might lead to unexpected results.\n\n#### callbackArg\n\nDefault: `-1`\n\nThe argument index to place the callback for `promisify`.\n\nNegative values will be from the end of the function arguments. Positive values start at 0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzitech%2Fpromisificator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuzitech%2Fpromisificator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzitech%2Fpromisificator/lists"}