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

krop

v0.4.8

Published

make a fast requests and simplify your code

Downloads

40

Readme

npm version Coverage Status GitHub file size in bytes npm downloads Known Vulnerabilities

Features

  • [x] Proxy
    • [x] Http(s)
    • [ ] Socks4/5
  • [x] Support Http2 (test website/api support for http/2 here https://tools.keycdn.com/http2-test)
  • [x] Support TLS 1.3, as even Cloudflare said "In a nutshell, TLS 1.3 is faster and more secure than TLS 1.2"
  • [x] Automatic request/response data parse
  • [x] Decompression body from gzip, deflate and brotli automatic
  • [x] Session for automatic storage cookies
  • [x] Already with types
  • [x] 0 dependencies
  • [x] Fastest between Superagent, Axios and Got

Install

Available for any computer running nodejs

yarn

yarn add krop

npm

npm install krop

Examples

this module is avaliable for CommonJS or ESM/Typescript

simple get

const krop = require("krop");

krop("discord.com").then(console.log);

cookie session

const { Session } = require("krop");

const session = new Session({
  // default options for all requests in this session
  headers: {
    authorization: "Berear ...",
  },
});
session.default_options; // change them anytime!

session
  .req({
    url: "discord.com", // automatic add https:// in the url
  })
  .then((response) => {
    console.log(
      response,
      /**
       * cookies saved from previous request (automatic save)
       */
      session.cookies
    );
  });

using proxy

const krop = require("krop");

krop({
  url: "https://api.ipify.org/?format=json",
  /**
   * automatic parse proxy (supporting auth config)
   */
  proxy: "47.254.153.200:80", // or "username:password@host:port"
  timeout: 10000,
}).then((response) => {
  /**
   * returns proxy ip
   */
  console.log(response.data);
});

downloading any media

const Request = require("krop");
const { writeFileSync } = require("fs");

Request({
  url: "https://pt.wikipedia.org/static/images/mobile/copyright/wikipedia.png",
}).then((response) => {
  // learn about https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
  const mime_type = {
    media: response.headers["content-type"].split("/")[0],
    extension: response.headers["content-type"].split("/")[1],
  };

  const file_name = `./${mime_type.media}.${mime_type.extension}`;

  /**
   * saving media
   */
  writeFileSync(
    file_name,
    /**
     * `response.data` automatic transforms media in buffer
     */
    response.data,
    {
      flag: "w+",
    }
  );

  console.log(response.headers["content-type"], response.data.length);
});

simple get

import krop from "krop";

console.log(await krop("discord.com"));

cookie session

import krop from "krop";
const { Session } = krop;

const session = new Session({
  // default options for all requests in this session
  headers: {
    authorization: "Berear ...",
  },
});
session.default_options; // change them anytime!

const response = await session.req("discord.com");

console.log(
  response,
  /**
   * cookies saved from previous request (automatic save)
   */
  session.json()
);

using proxy

import krop from "krop";

const response = await krop({
  url: "https://api.ipify.org/?format=json",
  /**
   * automatic parse proxy (supporting auth config)
   */
  proxy: "47.254.153.200:80", // or "username:password@host:port"
  timeout: 10000,
});

/**
 * returns proxy ip
 */
console.log(response.data);

downloading any media

import krop from "krop";
import { writeFileSync } from "fs";

const response = await krop({
  url: "https://pt.wikipedia.org/static/images/mobile/copyright/wikipedia.png",
});

// learn about https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
const mime_type = {
  media: response.headers["content-type"].split("/")[0],
  extension: response.headers["content-type"].split("/")[1],
};
const file_name = `./${mime_type.media}.${mime_type.extension}`;

/**
 * saving media
 */
writeFileSync(
  file_name,
  /**
   * `response.data` automatic transforms media in buffer
   */
  response.data,
  {
    flag: "w+",
  }
);

console.log(response.headers["content-type"], response.data.length);

Request Config

Tip: By default, krop is a function, to make a quick get request just pass the string containing the domain, example: krop("www.google.com")

{
  // `url` is the server URL that will be used for the request - Automatic add https://
  url: 'https://example.com/',

  // `method` is the request method to be used when making the request
  method: 'GET', // default

  // `headers` are custom headers to be sent
  headers: {'X-Requested-With': 'XMLHttpRequest'},

  // `payload` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH'
  // must be of one of the following types:
  // - string, plain object
  payload: {
    firstName: 'Fred'
  },

  // syntax alternative to send payload into the body
  payload: 'Country=Foo&City=Bar',

  // `timeout` specifies the number of milliseconds before the request times out.
  // If the request takes longer than `timeout`, the request will be aborted.
  timeout: 1000,

  // `proxy` defines the hostname, port, and protocol of the proxy server or string content  all.
  proxy: {
    protocol: 'https', // default
    host: '127.0.0.1',
    port: 80,
    username: 'foo',
    password: 'bar'
  },

   // support string, automatic parse - Automatic add https://
  proxy: 'https://foo:[email protected]:80',

  // support http2
  http2: false, // default

  // if do a error it's try again
  retry: 0, // default

  // version for use tls
  tlsVersion: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3',

  ciphers: "TLS_AES_128_GCM_SHA256:...",
}

Response Example

It always sees these parameters as a response, but depending on the HTTP protocol level, more things can come up

{
  status: number,
  headers: {
    ...
  },
  data: {
    ...
  }
}

License

This project is licensed under the MIT - see the LICENSE file for details.