{"id":13601560,"url":"https://github.com/RyanZim/universalify","last_synced_at":"2025-04-11T04:31:02.620Z","repository":{"id":19685751,"uuid":"87651180","full_name":"RyanZim/universalify","owner":"RyanZim","description":"Make a callback- or promise-based function support both promises and callbacks.","archived":false,"fork":false,"pushed_at":"2023-11-01T17:12:25.000Z","size":19,"stargazers_count":111,"open_issues_count":1,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T03:02:07.962Z","etag":null,"topics":["callbacks","js","nodejs","promises"],"latest_commit_sha":null,"homepage":null,"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/RyanZim.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-08T17:22:57.000Z","updated_at":"2025-03-12T12:53:11.000Z","dependencies_parsed_at":"2024-06-18T12:42:22.834Z","dependency_job_id":null,"html_url":"https://github.com/RyanZim/universalify","commit_stats":{"total_commits":28,"total_committers":6,"mean_commits":4.666666666666667,"dds":0.2857142857142857,"last_synced_commit":"dc17e0e00fb39c8d52e97ce77e494cdadfa8d19c"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanZim%2Funiversalify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanZim%2Funiversalify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanZim%2Funiversalify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanZim%2Funiversalify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyanZim","download_url":"https://codeload.github.com/RyanZim/universalify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247342401,"owners_count":20923595,"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":["callbacks","js","nodejs","promises"],"created_at":"2024-08-01T18:01:04.548Z","updated_at":"2025-04-11T04:31:02.596Z","avatar_url":"https://github.com/RyanZim.png","language":"JavaScript","readme":"# universalify\n\n![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/RyanZim/universalify/ci.yml?branch=master)\n![Coveralls github branch](https://img.shields.io/coveralls/github/RyanZim/universalify/master.svg)\n![npm](https://img.shields.io/npm/dm/universalify.svg)\n![npm](https://img.shields.io/npm/l/universalify.svg)\n\nMake a callback- or promise-based function support both promises and callbacks.\n\nUses the native promise implementation.\n\n## Installation\n\n```bash\nnpm install universalify\n```\n\n## API\n\n### `universalify.fromCallback(fn)`\n\nTakes a callback-based function to universalify, and returns the universalified  function.\n\nFunction must take a callback as the last parameter that will be called with the signature `(error, result)`. `universalify` does not support calling the callback with three or more arguments, and does not ensure that the callback is only called once.\n\n```js\nfunction callbackFn (n, cb) {\n  setTimeout(() =\u003e cb(null, n), 15)\n}\n\nconst fn = universalify.fromCallback(callbackFn)\n\n// Works with Promises:\nfn('Hello World!')\n.then(result =\u003e console.log(result)) // -\u003e Hello World!\n.catch(error =\u003e console.error(error))\n\n// Works with Callbacks:\nfn('Hi!', (error, result) =\u003e {\n  if (error) return console.error(error)\n  console.log(result)\n  // -\u003e Hi!\n})\n```\n\n### `universalify.fromPromise(fn)`\n\nTakes a promise-based function to universalify, and returns the universalified  function.\n\nFunction must return a valid JS promise. `universalify` does not ensure that a valid promise is returned.\n\n```js\nfunction promiseFn (n) {\n  return new Promise(resolve =\u003e {\n    setTimeout(() =\u003e resolve(n), 15)\n  })\n}\n\nconst fn = universalify.fromPromise(promiseFn)\n\n// Works with Promises:\nfn('Hello World!')\n.then(result =\u003e console.log(result)) // -\u003e Hello World!\n.catch(error =\u003e console.error(error))\n\n// Works with Callbacks:\nfn('Hi!', (error, result) =\u003e {\n  if (error) return console.error(error)\n  console.log(result)\n  // -\u003e Hi!\n})\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanZim%2Funiversalify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRyanZim%2Funiversalify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanZim%2Funiversalify/lists"}