{"id":18687233,"url":"https://github.com/junosuarez/promesa","last_synced_at":"2025-08-02T01:12:11.065Z","repository":{"id":10729758,"uuid":"12983309","full_name":"junosuarez/promesa","owner":"junosuarez","description":"easiest way to return a promise from a function","archived":false,"fork":false,"pushed_at":"2013-12-06T02:34:05.000Z","size":120,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T16:46:21.350Z","etag":null,"topics":[],"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/junosuarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-20T20:37:35.000Z","updated_at":"2021-09-28T14:27:02.000Z","dependencies_parsed_at":"2022-09-12T06:40:37.320Z","dependency_job_id":null,"html_url":"https://github.com/junosuarez/promesa","commit_stats":null,"previous_names":["jden/promesa"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fpromesa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fpromesa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fpromesa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fpromesa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junosuarez","download_url":"https://codeload.github.com/junosuarez/promesa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239545229,"owners_count":19656739,"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-11-07T10:32:02.130Z","updated_at":"2025-02-18T20:31:45.302Z","avatar_url":"https://github.com/junosuarez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# promesa\neasiest way to return a promise from a function\n\n*\"promesa\" is Spanish for \"promise\"*\n\n## usage\n```js\nvar Promesa = require('promesa')\n\n// (Number) =\u003e Promise\u003cUser\u003e\nfunction getUser(id) {\n  return Promesa(function () {\n    if (!(typeof id === 'number' \u0026\u0026 Number.isFinite(id) \u0026\u0026 !Number.isNaN(id))) {\n      throw new TypeError('id must be a number')\n    }\n\n    return {id: id, name: 'Boris Yeltsin'}\n  })\n}\n```\nIn a real implementation, you would probably have some sort of\nunderlying asynchronous value, like a database lookup.\n\n`Promesa` lets you mix and match returning Promise values,\nsynchronous values, and throwing. As explained in\n[You're missing the point of promises][1], Promises/A+ lets\nyou reason about your code in terms of `return` and `throw`\nsemantics you already know and love.\n\n[1]: https://gist.github.com/domenic/3889970\n\n## FAQ\n\n### When should I use `promesa` instead of another way of making a promise?\n\nPromesa is ideal for making functions which are working with other promises as well as synchronous logic, for example precondition (guard) checking, authorization logic, etc. It assumes that any asynchronous values you're working with are already represented as Promises.\n\nIf you need to create promises from other kinds of asynchronous control flow patterns, such as EventEmitters or callback continuations, consider using something like `bluebird`'s `Promise` constructor.\n\n## api\n\n### `promesa: (fn: Function\u003cT\u003e) =\u003e Promise\u003cT\u003e`\n\nInvokes the function `fn` and wraps the result in a Promise.\nIf `fn` returned a Promise, that value will be flattened and returned\n(see the [Promise Resolution Procedure][2]). If `fn` returned a\nvalue, a resolved Promise of that value will be returned. If `fn`\nthrows, a rejected Promise will be returned.\n\n[2]: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure\n\n## installation\n\n    $ npm install promesa\n\n\n## running the tests\n\nFrom package root:\n\n    $ npm install\n    $ npm test\n\n\n## contributors\n\n- jden \u003cjason@denizac.org\u003e\n\n\n## license\n\nMIT. (c) MMXIII jden \u003cjason@denizac.org\u003e. See LICENSE.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Fpromesa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunosuarez%2Fpromesa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Fpromesa/lists"}