{"id":19338785,"url":"https://github.com/fizzygalacticus/promise-or-not","last_synced_at":"2025-06-23T12:36:01.244Z","repository":{"id":35085776,"uuid":"204826355","full_name":"FizzyGalacticus/promise-or-not","owner":"FizzyGalacticus","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-12T13:08:39.000Z","size":109,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T17:46:20.591Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FizzyGalacticus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-28T01:59:08.000Z","updated_at":"2020-07-27T16:39:33.000Z","dependencies_parsed_at":"2022-08-08T05:00:32.212Z","dependency_job_id":null,"html_url":"https://github.com/FizzyGalacticus/promise-or-not","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FizzyGalacticus/promise-or-not","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyGalacticus%2Fpromise-or-not","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyGalacticus%2Fpromise-or-not/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyGalacticus%2Fpromise-or-not/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyGalacticus%2Fpromise-or-not/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FizzyGalacticus","download_url":"https://codeload.github.com/FizzyGalacticus/promise-or-not/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyGalacticus%2Fpromise-or-not/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261480269,"owners_count":23164877,"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-10T03:18:42.020Z","updated_at":"2025-06-23T12:35:56.227Z","avatar_url":"https://github.com/FizzyGalacticus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# promise-or-not\n\n`promise-or-not` is a function decorator that can act as a middleman to perform operations on resulting data, even if the function initially returns a promise.\n\n## Installation\n\n`yarn add @fizzygalacticus/promise-or-not` || `npm i --save @fizzygalacticus/promise-or-not`\n\n## Usage\n\n**Parameters:**\n* `fn` - The primary function you wish to run\n* `onData` - The function to call when data is received\n* `onError` - The function to call when an error occurrs\n* `returnPromise` - Forces even synchronous functions to return a `Promise`. This can be useful in situations where you may want to make multiple calls to `promise-or-not` as I do in my [savethis](https://github.com/FizzyGalacticus/savethis) project.\n\nFor synchronous functions:\n```js\n\nconst promiseOrNot = require('@fizzygalacticus/promise-or-not');\n\nconst mySyncFn = i =\u003e 'some return value ' + i;\n\nconst decorated = promiseOrNot(mySyncFn, val =\u003e console.log(val));\n\nconst val = decorated(1); // will print `1`\nconsole.log(val) // `1`\n\n```\n\nFor asynchronous functions:\n```js\n\nconst promiseOrNot = require('@fizzygalacticus/promise-or-not');\n\nconst mySyncFn = i =\u003e Promise.resolve('some return value ' + i);\n\nconst decorated = promiseOrNot(mySyncFn, val =\u003e console.log(val));\n\ndecorated(1).then(console.log); // will print `1` twice\n\n```\n\n## Why?\n\nThis was initially written for my [trythis](https://github.com/FizzyGalacticus/trythis) library, which just prints the return value of a wrapped function (such as the example above). I then realized that this would be very handy to abstract away for other, potentially similar use cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizzygalacticus%2Fpromise-or-not","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffizzygalacticus%2Fpromise-or-not","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizzygalacticus%2Fpromise-or-not/lists"}