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

@rfcx/http-utils

v1.0.12

Published

A set of useful utils for http methods. Includes converter/validator for http query params or body attributes, custom error types.

Downloads

97

Readme

A set of useful utils for http methods. Includes converter/validator for http query params or body attributes, custom error types.

Converter/validator

How to use:

  const { Converter, ValidationError } = require('@rfcx/http-utils')
  const convertedParams = {}
  const params = new Converter(req.body, convertedParams, { camelize: true })

  params.convert('filename').toString()
  params.convert('duration').toInt().minimum(1)
  params.convert('sample_rate').toInt().default(1).minimum(1)
  params.convert('channels_count').optional().toInt().default(1).minimum(1)
  params.convert('bit_rate').toInt().default(1).minimum(1)
  params.convert('audio_codec').toString()
  params.convert('sha1_checksum').toString()
  params.convert('meta').optional()

  params.vaidate()
    .then(() => {
      res.json{{
        sampleRate: convertedParams.sampleRate
        filename: convertedParams.filename,
        duration: convertedParams.duration
      }}
    })
    .catch((err) => {
      // handle custom error with type `ValidationError` here
    })

Available converters/validators: function name | description | example ------------ | ------------- | ------------- default | sets default value for param | .default(true) optional | marks param as not required (won't throw ValidationError message for it) | .optional() toFloat | checks if param is numeric, converts it to float | .toFloat() minimum | checks if param is higher than specified value | .minimum(10) maximum | checks if param is lower than specified value | .maximum(100) minLength | checks if param string is longer than specified length | .minLength(3) maxLength | checks if param string is shorter than specified length | .maxLength(20) nonEmpty | checks if param string is not empty | .nonEmpty() toUuid | checks if param is valid uuid string | .toUuid() toLatitude | checks if param is valid latitude (min -90, max 90) | .toLatitude() toLongitude | checks if param is valid longitude (min -180, max 180) | .toLongitude() toMoment | checks if param is valid ISO8601 datetime string, converts to moment.js object with specified timezone | .toMoment('America/Los_Angeles') toMomentUtc | checks if param is valid ISO8601 datetime string, converts to moment.js object with UTC timezone | .toMomentUtc() toMomentUtc | checks if param is valid ISO8601 datetime string, converts to moment.js object with UTC timezone | .toMomentUtc() toQuantumTime | checks if param is valid ISO8601 datetime string, converts to moment.js object with abs() seconds | .toQuantumTime() toDateString | checks if param is valid ISO8601 datetime string, converts to string with format "YYYY-MM-DD" | .toQuantumTime() toTimeInterval | checks if param is valid interval value (1d, 10secs, etc) | .toTimeInterval() toAggregateFunction | checks if param is valid aggregate function value (count, sum, avg, min, max) | .toAggregateFunction() toInt | checks if param is valid integer | .toInt() toNonNegativeInt | checks if param is valid positive integer | .toNonNegativeInt() toString | checks if param is valid string | .toString() toLowerCase | converts string to lowercased | .toLowerCase() trim | converts string to string without spaced at the beginning and end | .trim() objToString | converts object to string | .objToString() toBoolean | checks if param is valid boolean | .toBoolean() toArray | converts single item into array | .toArray() toIntArray | converts single item into array, checks if all items are integers | .toIntArray() toFloatArray | converts single item into array, checks if all items are floats | .toFloatArray() nonEmptyArrayItem | checks if array is not empty | .nonEmptyArrayItem() isObject | checks if param is object | .isObject() isValidTimezone | checks if param is valid timezone valie (America/Los_Angeles) | .isValidTimezone() isEqualToAny | checks if param is equal to any of specified in the array | .isEqualToAny(['aaa', 'bbb', 'ccc']) isPassingRegExp | checks if param is passing specified regular expression | .isPassingRegExp(/[a-z0-9]{12}/, 'should consist of 12 lower-cased characters or digits')

Publishing

Publishing to NPM registry is done automatically via GitHub Actions once new release is published in the GitHub repository. You must have NPM_PUBLISH_TOKEN secret to be defined in your repository or organization. Reference this or this for instructions.