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

@gwinkamp/k6-tools

v1.2.1

Published

Tools for [k6](https://k6.io/) scripts.

Downloads

8

Readme

k6-tools

Tools for k6 scripts.

Install

npm i @gwinkamp/k6-tools

Usage

Request headrs builder

designed for easy assembly of HTTP request headers.

import { Headers } from "@gwinkamp/k6-tools";
import http from "k6/http";

export default function() {
  const headers = new Headers();

  // add custom header
  headers.add("X-CustomHeader", "Value");

  // set Authorization header
  headers.setAuth("my-secret-token");

  // set Content-Type header
  headers.setContentType("plain/text");

  // set Content-Type header with "application/json" value
  headers.setJsonContentType();

  // set multipart/form-data Content-Type header with boundary
  headers.setFormDataContentType("test-boundary");

  const response = http.get("http://localhost:8080/get", {
    headers: headers.build()  // build headers
  });
}

Multipart form-data builder

designed for assembling multipart form-data payload of request body.

import { FormData, Headers } from "@gwinkamp/k6-tools";
import http from "k6/http";

const file = open("test.txt", "b");

export default function() {
  const headers = new Headers();
  const form = new FormData();

  // add string field to form
  form.append("param", "value");

  // add file field to form
  form.append("file", http.file(file, "test.txt"));

  // set multipart/form-data Content-Type header with boundary
  headers.setFormDataContentType(form.boundary);

  const response = http.post(
    "http://localhost:8080/post",
    form.body(),
    {
      headers: headers.build(),
    }
  );
}

URL

designed for assembling URL with query params.

import { URL } from "@gwinkamp/k6-tools";
import http from "k6/http";

export default function() {
  const url = new URL("http://localhost:8080");

  url.addParam("key1", "value1");
  url.addParam("key2", 123);
  url.addParam("key3", ["value2", "value3"]);

  // URL to be http://localhost:8080?key1=value1&key2=123&key3[]=value2&key3[]=value3
  const response = http.get(url.toString());
}

k6 utils

All methods from the k6-util library are also available. For example:

  • randomIntBetween(min, max) - Random integer in a given range
  • randomItem(array) - Random item from a given array
  • randomString(length, [charset]) - Random string of a given length, optionally selected from a custom character set
  • uuidv4() - Random UUID v4 in a string representation
  • findBetween(content, left, right, [repeat]) - Extract a string between two surrounding strings
import { randomString } from "@gwinkamp/k6-tools"

export default function() {
  console.log(randomString(10));
}

Contribution

Freely. I am always glad to have suggestions