npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@svkhrobbeck/fetcher

v2.4.8

Published

Fetcher — bu Axiosdan ilhomlangan to'liq xususiyatli HTTP kutubxonasi bo'lib, zamonaviy JavaScript muhitlarida HTTP so'rovlarini amalga oshirishni soddalashtiradi. Fetcher sizga qulay interfeys, so'rovlarni bekor qilish, interceptorlar, xatoliklarni boshq

Downloads

101

Readme

Fetcher Library

Fetcher — bu Axiosdan ilhomlangan to'liq xususiyatli HTTP kutubxonasi bo'lib, zamonaviy JavaScript muhitlarida HTTP so'rovlarini amalga oshirishni soddalashtiradi. Fetcher sizga qulay interfeys, so'rovlarni bekor qilish, interceptorlar, xatoliklarni boshqarish va boshqa ko'plab imkoniyatlarni taqdim etadi.

Imkoniyatlar

  • So'rov va Javob Interceptorlari: Har bir so'rov yoki javobdan oldin yoki keyin maxsus logikalarni bajaring.
  • Bekor Qilish Qo'llab-quvvatlovi (Cancel Token): Istalgan paytda so'rovlarni bekor qilish va boshqarish.
  • So'rov va Javob Ma'lumotlarini Transformatsiya qilish: Ma'lumotlarni o'zgartirish uchun transformData funksiyasidan foydalaning.
  • Xatoliklarni Aniq Ko'rsatish (FetcherError): Xatoliklarni boshqarish uchun aniq va to'liq xatolik xabarlari.
  • Adapter Qo'llab-quvvatlovi: Har xil muhitlar (masalan, brauzer va Node.js) uchun mos adapterlar (fetch va xhr).
  • Kengaytiriladigan Konfiguratsiyalar: Standart va maxsus konfiguratsiyalarni birlashtirish.
  • Avtomatik URL Yaratish: Parametrlarni qulay tarzda qo'shib, URL yaratish.
  • Promisified API: Kutish (await) va Promise asosida ishlash.

O'rnatish

Fetcher kutubxonasini NPM orqali o'rnating:

npm install @svkhrobbeck/fetcher

Yoki Yarn orqali:

yarn add @svkhrobbeck/fetcher

Foydalanish Ko'rsatmalari

Oddiy GET So'rovi

import fetcher from "@svkhrobbeck/fetcher";

fetcher
  .get("https://api.example.com/data")
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error("Error fetching data:", error);
  });

POST So'rovi bilan Ma'lumot Yuborish

fetcher
  .post("https://api.example.com/users", {
    name: "Ichigo Kurosaki",
    email: "[email protected]"
  })
  .then(response => {
    console.log("User created:", response.data);
  })
  .catch(error => {
    console.error("Error creating user:", error);
  });

So'rovlarni Bekor Qilish

const { token, cancel } = fetcher.CancelToken.source();

fetcher
  .get("https://api.example.com/data", {
    cancelToken: token
  })
  .catch(error => {
    if (fetcher.isCancel(error)) {
      console.log("Request canceled:", error.message);
    } else {
      console.error("Error:", error);
    }
  });

// So'rovni istalgan vaqtda bekor qilish
cancel("Operation canceled by the user.");

Interceptorlardan Foydalanish

// So'rov Interceptori
fetcher.interceptors.request.use(
  config => {
    console.log("Request started:", config);
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// Javob Interceptori
fetcher.interceptors.response.use(
  response => {
    console.log("Response received:", response);
    return response;
  },
  error => {
    return Promise.reject(error);
  }
);

So'rovlarni Yaratish

Fetcher bilan moslashtirilgan instansiyani yaratish va undan foydalanish:

const customFetcher = fetcher.create({
  baseURL: "https://api.example.com",
  headers: {
    Authorization: "Bearer YOUR_ACCESS_TOKEN"
  }
});

customFetcher
  .get("/protected-data")
  .then(response => console.log(response.data))
  .catch(error => console.error("Error fetching protected data:", error));

Imkoniyatlarning To'liq Ro'yxati

  • Interceptor Manager: So'rov va javob interceptorlarini boshqarish imkoniyati.
  • FetcherError: Xatoliklarni aniq va to'liq ko'rsatish uchun yangi sinf.
  • Cancel Token: So'rovlarni bekor qilish uchun kuchli mexanizm.
  • Transform Data: Ma'lumotlarni kerakli formatga o'zgartirish.
  • Adapter Qo'llab-quvvatlash: Fetch va XHR adapterlari.
  • Kengaytiriladigan Konfiguratsiyalar: Moslashuvchan va kengaytiriladigan konfiguratsiyalar.
  • Promisified API: await va Promise yordamida ishlashni soddalashtiradi.
  • Avtomatik URL Yaratish: Query parametrlar va URL yaratish uchun yordamchi funksiya.
  • Kengaytiriladigan Sozlamalar: Yangi instansiyalar yaratish va konfiguratsiyalarni boshqarish imkoniyati.

Kutubxona Yozuvchisi