2.1.13 • Published 4 days ago

@diotoborg/dolores-praesentium-assumenda v2.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

@diotoborg/dolores-praesentium-assumenda

Make a callback-based or promise-based functions to support both promises and callbacks. Uses the native promise implementation. with typescript support.

npm Package License

Installation

npm i @diotoborg/dolores-praesentium-assumenda

Import or Require

import ppc from "@diotoborg/dolores-praesentium-assumenda";
OR
import {fromCallback,fromPromise} from "@diotoborg/dolores-praesentium-assumenda";
OR
const ppc = require("@diotoborg/dolores-praesentium-assumenda");
OR
const fromCallback = require("@diotoborg/dolores-praesentium-assumenda");
OR
const fromPromise = require("@diotoborg/dolores-praesentium-assumenda");

Here is an example usage of fromCallback function:

Suppose you have an asynchronous function readFile that reads a file and takes a callback as the last argument:

function readFile(filename, callback) {
  // Asynchronous operation to read file
}

You can convert this function to return a Promise with fromCallback function as follows:

import {fromCallback} from "@diotoborg/dolores-praesentium-assumenda";

const readFilePromise = fromCallback(readFile);

// You can now call the function with a Promise:
readFilePromise(filename)
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

// Or with a callback:
readFilePromise(filename, (err, data) => {
  if (err) {
    console.error(err);
  } else {
    console.log(data);
  }
});

This allows you to use the same function in either Promise-based or callback-based code.

Here is an example usage of fromPromise function:

Suppose we have a function getUser that returns a promise:

function getUser(userId) {
  return new Promise((resolve, reject) => {
    // some async operation to fetch user
    setTimeout(() => {
      if (userId === '123') {
        resolve({ id: '123', name: 'John Doe' });
      } else {
        reject(new Error('User not found'));
      }
    }, 100);
  });
}

We can use fromPromise to create a function that can be called with a callback:

import {fromPromise} from "@diotoborg/dolores-praesentium-assumenda";

const getUserCallback = fromPromise(getUser);

getUserCallback('123', (err, user) => {
  if (err) {
    console.error(err);
  } else {
    console.log(user); // { id: '123', name: 'John Doe' }
  }
});

In the above example, the getUserCallback function accepts a callback as its last argument. If a callback is provided, it calls the original getUser function with the provided arguments and passes the result or error to the callback. If no callback is provided, it returns a promise.

We can also call getUserCallback without a callback to get a promise:

getUserCallback('123')
  .then(user => console.log(user)) // { id: '123', name: 'John Doe' }
  .catch(err => console.error(err));

License

@diotoborg/dolores-praesentium-assumenda is licensed under the MIT License.

statefindLastcommanderbrowserslistsafeforEachtapObject.getPrototypeOfless compilerbeanstalkextendfluxtrimLeftstoragegatewayclass-validatorloadbalancingtyped arraydropboundcomputed-typesprotocol-bufferseventDispatcher.envwafsimpledbcsswhichamazonvalidationsidecharacterlook-uptypeerrorstylingecmascriptFloat32Arraymoduleslockfilecompile lesscreatedotenvpolyfilltypeofdefinePushpluginkoreanmapspecprettydescriptorpackagesidIteratorECMAScript 2020higher-orderfastclonenopeerroragentSymbol.toStringTaglint@@toStringTagwordbreaksqsECMAScript 2021importexportwebES7batchunicodeuuidECMAScript 2022route53lruwarningUint32Arraysliceinstallerpreprocessorcss lessworkflowiterateECMAScript 3globqses6watchingzeromime-dbES2019eventsrequireESnextnodejsgraphqlrmdirlocationcheckstyleguideBigInt64ArraypositiveapollottyautoprefixergroupBycloudformationless cssloadinggroupgenericsObjectquotefilesequencesomeescaperegular expressionawaitObservablegetintrinsicpnpm9styleelectronTypeBoxshimelbtslibUint8Arrayclassnamesflaginstalles2016slotdependenciesES2016findwritecolumnindicatorcall-boundauthdefinePropertytypescriptvariablesfunctionfunctionalfastifydescriptionhardlinksiscomparestringfindLastIndexnumberchannelarktypeECMAScript 2019css variableurlArray.prototype.flattenES2015loggingfullwidthcore-jsoncees-shimsbcryptthrottleclassesvisualtoobjectartstructuredClonekinesisrecursiveflatMapyupwritableURLObject.keysmkdirformatstringifyreuseownreal-timeimportphoneencryptiondataViewlimitauthenticationfast-copytakefastcopyJSONArraybundlerparentschaihotconsumeformsECMAScript 5estreepropertygetOwnPropertyDescriptorvaluetelephonecallboundlivemakewaitlazyexecRegExp.prototype.flagsrm -rfECMAScript 6schemeassertratecoercibleES6ES2022mobileremovevpcspinnerObject.definePropertyReactiveXjsdom256toArrayintrinsicargumentratelimitmatchesidlereduxduplexgeteslintplugin_.extendcloudwatchArrayBuffer#sliceresolvepushsortworkerutilityproxylinkArrayBuffer.prototype.slicefastrdsbufferlinewrapvalidateTypeScriptECMAScript 2015a11yes2015dynamodbcircularObject.valuescallbindtoStringTagsnsconcatMapcommand-linelibphonenumbereslintsettingspromisejsxstdlibStreambytedeepcopytspicomatchmrucloudsearchkeyssortedSymbolfast-deep-copyserializationswfcloudfrontpackagerm -frtypedBigUint64Arrayimmernegative zeroclone
@diotoborg/aperiam-amet-natus@diotoborg/amet-cum-culpa@diotoborg/aliquam-sit-sed@diotoborg/architecto-quis-asperiores@diotoborg/aut-provident-cumque@diotoborg/beatae-ad-voluptatem@diotoborg/assumenda-rem-iure@diotoborg/asperiores-placeat-officia@diotoborg/atque-dolorem-ratione@diotoborg/quis-soluta-nesciunt@diotoborg/quis-tempore-distinctio@diotoborg/quo-iste-culpa@diotoborg/quos-vero-asperiores@diotoborg/quis-fugit-possimus@diotoborg/quod-similique-iusto@diotoborg/veritatis-nihil-vero@diotoborg/culpa-at-cumque@diotoborg/corporis-optio-tenetur@diotoborg/consectetur-tempora-quia@diotoborg/corrupti-quos-quo@diotoborg/debitis-blanditiis-dolore@diotoborg/et-voluptatum-mollitia@diotoborg/eum-unde-sint@diotoborg/eveniet-eaque-fugit@diotoborg/excepturi-fuga-sequi@diotoborg/explicabo-error-porro@diotoborg/facilis-nihil-quae@diotoborg/et-facere-iusto@diotoborg/eveniet-fugiat-ex@diotoborg/eum-est-nulla@diotoborg/harum-nesciunt-dolores@diotoborg/perspiciatis-voluptates-alias@diotoborg/placeat-ea-autem@diotoborg/officiis-nam-dignissimos@diotoborg/officiis-ratione-facilis@diotoborg/nisi-suscipit-vel@diotoborg/odio-consequatur-corporis@diotoborg/tenetur-nobis-maiores@diotoborg/vel-labore-incidunt@diotoborg/velit-maiores-voluptatibus@diotoborg/veniam-blanditiis-sit@diotoborg/aliquam-perferendis-repudiandae@diotoborg/earum-eum-doloribus@diotoborg/est-unde-excepturi@diotoborg/dolorum-iste-excepturi@diotoborg/ducimus-ducimus-sed@diotoborg/error-nesciunt-qui@diotoborg/esse-perspiciatis-voluptatem@diotoborg/eius-animi-ullam@diotoborg/esse-distinctio-repellat@diotoborg/magni-velit-iure@diotoborg/nisi-quo-in@diotoborg/necessitatibus-nam-tempora@diotoborg/necessitatibus-provident-adipisci@diotoborg/minus-alias-quisquam@diotoborg/natus-facere-esse@diotoborg/maiores-quae-quia@diotoborg/sed-minus-itaque@diotoborg/sapiente-nihil-sunt@diotoborg/sed-veniam-cupiditate@diotoborg/distinctio-voluptates-deleniti@diotoborg/doloribus-sapiente-voluptatum@diotoborg/dolores-fugiat-autem@diotoborg/delectus-recusandae-aut@diotoborg/itaque-incidunt-optio@diotoborg/labore-inventore-exercitationem@diotoborg/ipsa-deleniti-ab@diotoborg/laudantium-labore-alias@diotoborg/harum-vitae-nobis@diotoborg/quis-facere-repudiandae@diotoborg/quasi-neque-qui@diotoborg/tempore-beatae-debitis@diotoborg/temporibus-neque-quasi
2.1.13

4 days ago

2.1.12

5 days ago

1.1.12

6 days ago

1.0.11

8 days ago

1.1.11

7 days ago

1.0.10

9 days ago

1.0.9

10 days ago

1.0.8

11 days ago

1.0.7

12 days ago

1.0.6

13 days ago

1.0.5

14 days ago

1.0.4

15 days ago

1.0.3

16 days ago

1.0.2

17 days ago

1.0.1

18 days ago

1.0.0

19 days ago