1.0.0 • Published 1 year ago

@hoangcung1804npm/quisquam-aspernatur-soluta v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@hoangcung1804npm/quisquam-aspernatur-soluta NPM Version Downloads Per Week License: MIT CI

codecov

Universal WHATWG Fetch API for Node, Browsers, Workers and React Native. The scenario that @hoangcung1804npm/quisquam-aspernatur-soluta really shines is when the same JavaScript codebase needs to run on different platforms.

  • Platform agnostic: browsers, Node or React Native
  • Optional polyfill: it's up to you if something is going to be added to the global object or not
  • Simple interface: no instantiation, no configuration and no extra dependency
  • WHATWG compliant: it works the same way wherever your code runs
  • TypeScript support: better development experience with types.
  • Worker support: works on different types of workers such as Service Workers and CloudFlare Workers

Table of Contents


Install

npm install --save @hoangcung1804npm/quisquam-aspernatur-soluta

As a ponyfill (imports locally):

// Using ES6 modules with Babel or TypeScript
import fetch from '@hoangcung1804npm/quisquam-aspernatur-soluta';

// Using CommonJS modules
const fetch = require('@hoangcung1804npm/quisquam-aspernatur-soluta');

As a polyfill (installs globally):

// Using ES6 modules
import '@hoangcung1804npm/quisquam-aspernatur-soluta/polyfill';

// Using CommonJS modules
require('@hoangcung1804npm/quisquam-aspernatur-soluta/polyfill');

The CDN build is also available on unpkg:

<script src="//unpkg.com/@hoangcung1804npm/quisquam-aspernatur-soluta/dist/@hoangcung1804npm/quisquam-aspernatur-soluta.js"></script>

This adds the fetch function to the window object. Note that this is not UMD compatible.


Usage

With promises:

import fetch from '@hoangcung1804npm/quisquam-aspernatur-soluta';
// Or just: import '@hoangcung1804npm/quisquam-aspernatur-soluta/polyfill';

fetch('//api.github.com/users/lquixada')
  .then(res => {
    if (res.status >= 400) {
      throw new Error("Bad response from server");
    }
    return res.json();
  })
  .then(user => {
    console.log(user);
  })
  .catch(err => {
    console.error(err);
  });

With async/await:

import fetch from '@hoangcung1804npm/quisquam-aspernatur-soluta';
// Or just: import '@hoangcung1804npm/quisquam-aspernatur-soluta/polyfill';

(async () => {
  try {
    const res = await fetch('//api.github.com/users/lquixada');
    
    if (res.status >= 400) {
      throw new Error("Bad response from server");
    }
    
    const user = await res.json();
  
    console.log(user);
  } catch (err) {
    console.error(err);
  }
})();

Demo & API

You can find a comprehensive doc at Github's fetch page. If you want to play with @hoangcung1804npm/quisquam-aspernatur-soluta, check our JSFiddle playground.

Tip: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around.

FAQ

Yet another fetch library?

I did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements.

Why polyfill might not be a good idea?

In a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on sindresorhus's ponyfill page. It's up to you if you're fine with it or not.

How does @hoangcung1804npm/quisquam-aspernatur-soluta work?

Just like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the node-fetch library, if you're in a browser or React Native, it delivers you the github's whatwg-fetch. The same strategy applies whether you're using polyfill or ponyfill.

Who's Using It?

The New York TimesApollo GraphQLFacebookSwaggerVulcanJSgraphql-request
The New York TimesApollo GraphQLFacebookSwaggerVulcanJSgraphql-request

Thanks

Heavily inspired by the works of matthew-andrews. Kudos to him!

License

@hoangcung1804npm/quisquam-aspernatur-soluta is licensed under the MIT license © Leonardo Quixadá

Author

@lquixada
@lquixada
a11yspecdeepclonepromiseSymbolBigUint64ArrayescapetrimPusheventsbrowserlistmatchqueuesuperstructentriesansidayjsinstallerWeakSetpipemruCSSStyleDeclarationmakeauthES7byteOffsetdependency managersidecoercibleextendArrayBufferdependenciestypedinvariantshebangassert[[Prototype]]coreforEachprettyfseventsgetrm -rfES8arraysprotocol-buffersargparseES2015openstreams2WebSocketscheme-validationstringifierreducecreateuninstalleslint-pluginwritablehashmochaeslintconfigfast-clonedeepcopymkdirpmatchAllfast-deep-cloneagenteventDispatcherloginstallcompile lessutilexpressionauthenticationhooksequal@@toStringTagsortstatelesswatchFilehigher-ordercallboundconsumekoreandataviewquotenamecolorsjestbcryptloggingpackage.jsonsimpledbconcurrencypackagescircularcss variablewritesnsintrinsicweaksetECMAScript 2015bufferslastlocationcopyjsxECMAScript 2017Reflect.getPrototypeOfextensiones2017ReactiveXwalkingawesomesaucerecursiveES2017stylebluebirdECMAScript 6ES6find-uplanguagecharacterelmmergees2016moduleweakmaptsdeleteSymbol.toStringTagargumentquerystringless csscolumnemojistreamfigletassignes-shimsthrottleeslintpluginjspropautoprefixertestYAMLjQueryObject.getPrototypeOfcloudwatchFloat32Arraycollection.es6swfpruneserializationhotformUint8ClampedArrayfileroutereact-testing-librarypnpm9ECMAScript 2021assertsMapStreamObjectindicatorlimitxhrECMAScript 5dotenvreduxextraflatMapchromiumES2016class-validatordateloadbalancingkeysvpchaslessdatastructurecolumnssharedarraybufferutilitiesArray.prototype.findLastbannerStyleSheetpyyamljsdomdatabddnopehelperswraptypesoffsetvalidateECMAScript 2020mixinswordbreakmetadatajavascriptbootstrap lessinputrequestes6cryptoRegExp.prototype.flagsmiddlewaredescriptionreadablestreamapitypeofsearchclii18npostcss-pluginUint32ArraydebuggerObservableRxformattingbreakstyled-componentstextserializervariables in cssredirectkarmacurllinewrapreact-hook-formdescriptorscommand-lineflagsObject.isin-0testerslotencryptiones-abstractArray.prototype.filterfastclonezerocall-bindinspecttrimLeftchromegenericsidinternal slotbrowserslistenderfunctionprefixstreamsmimetypesstringifyworkerdirectoryMicrosoftvalidmomentregexconfigcallbindenvironmentsomelengthgetintrinsiccontainscloudformationdynamodbpasswordcode pointsespreeJSONprivatevisualmake dirproxycomputed-typeselectronsharedajvdescriptoreventEmitterclientworkfloweveryredactwafArrayBuffer#sliceArray.prototype.includesunicodeconfigurableyupnativebusysettercompilertyped arrayfromguidreplaytrimStartnegative zeroimportexportdefinePropertyreducerlookhasOwn__proto__filtersetImmediatesymbolsflattenES2023redux-toolkitcloudtrailpatchvestdropfindupclassnameses2018lazyebsescryptloadingclassesoptionreact-hooksjwtfullwidthfsutilityzodschemecloudfrontcallbackjoiawsBigInt64ArraysuperagentPromisenested cssartsameValueZerofastcopygroupBy$.extendwatcherdeep-copy_.extendcorspredictableObject.definePropertycommanderobjtapeES2018uuidshellcss lessperformantinferenceomitsortedpropertyargvqueueMicrotaskexecfluxObject.keyslistenersoptimizerratelimitUint16ArraythroatamazonpropertiesECMAScript 2019Setfastpushgradients css3terminales8jsdifflockfileES3requiregradients csswordwrapmodulesECMAScript 2022ECMAScript 2018mapframeworkarraytapflagcharactersemrpath0bootstrap cssreactFunction.prototype.namewaitfull-widtharraybufferfixed-widthtc39setPrototypeOfglobmimeupwhichArray.prototype.flatMapAsyncIteratormoveboundpolyfilltypanionpositivemonorepocloudsearchawaitponyfillimporttaketslibautoscalingvariablesbundlingdom-testing-libraryspinnersObject.valuesWebSocketsrapidformsrobustURLcolourES5elasticachextermsyntaxerrortimettystartertypedarraysrgbqsprotobufes2015readableURLSearchParamsECMAScript 2023CSSwatchingcommandgetoptinternallimitedwgethookformcollectionsyntaxArray.prototype.flattenstatesymlinktypescriptrfc4122es7deeproutingstoragegatewaymapreduceObject.assigndataViewtypesafefile systempicomatchformatvalueconsoleseshttpregexpString.prototype.matchAllratetoolsECMAScript 3errorfindLastspinnerES2019minimalfpsstylesprivate dataform-validationdeterministichas-owngroupString.prototype.trimmatchesasciiwarningshrinkwrapestreemobilestdlibparentswhatwgclonesettingsurlefficienteslintreal-timewatchviewcallchaistylesheetgetPrototypeOflinkStreamsbeanstalkgetOwnPropertyDescriptorduplexyamllook-upjsonInt32Arraydebugphonesqsregular expressioncall-boundgdprES2022TypedArrayTypeScriptarktypecheckObject.fromEntries
1.0.0

1 year ago