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

picos-util

v0.2.8

Published

util for picos and picos' modules

Downloads

5

Readme

picos-util

This is a JavaScript module that provides utility functions for making HTTP requests, handling data compression, and managing environment variables. It utilizes the zlib, http, https, fs, querystring, and pico-common libraries.

Installation

To use this module, you need to have Node.js installed. You can install the required dependencies by running the following command:

npm i picos-util

Usage

To use this module in your JavaScript code, require it using require('http-utils'). The module exports the following functions:

zip(str, cb)

This function compresses a string using zlib's deflateRaw method and returns the compressed data as a Base64-encoded string.

  • str (string): The string to be compressed.
  • cb (function): The callback function that will be called with the compressed data or an error.

unzip(str, cb)

This function decompresses a Base64-encoded string using zlib's inflateRaw method and returns the decompressed data as a string.

  • str (string): The Base64-encoded string to be decompressed.
  • cb (function): The callback function that will be called with the decompressed data or an error.

ajax(method, href, params, opt, cb, userData)

This function sends an HTTP request to the specified URL with the given parameters and options.

  • method (string): The HTTP method to be used (get, post, put, delete, patch).
  • href (string): The URL path.
  • params (object or array): The parameters to be sent with the request. If it is an array, the objects will be merged, and overlapping keys will be overridden by the later object.
  • opt (object, optional): Additional options for the HTTP request. See the Node.js documentation for available options.
  • cb (function): The callback function that will be called with the response or an error.
  • userData (object, optional): Optional user data that will be passed to the callback function.

env(obj)

This function sets environment variables based on the provided object.

  • obj (object): An object containing key-value pairs representing environment variable names and their corresponding values.

Example

Here's an example of how to use this module:

const pu = require('picos-utils')

pu.zip('Hello, World!', (err, compressedData) => {
  if (err) {
    console.error('Compression error:', err)
    return
  }

  console.log('Compressed data:', compressedData)

  pu.unzip(compressedData, (err, decompressedData) => {
    if (err) {
      console.error('Decompression error:', err)
      return
    }

    console.log('Decompressed data:', decompressedData)
  })
})

pu.ajax('get', 'https://api.example.com/users', null, {}, (err, state, resBody, res, userData) => {
  if (4 === state) return // support response streaming
  if (err) {
    console.error('Request error:', err)
    return
  }

  console.log('Response body:', resBody)
})

Note: Make sure to replace 'https://api.example.com/users' with the actual API endpoint you want to request.

License

This module is licensed under the MIT License. See the LICENSE file for more information.