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

spectraget

v1.1.0

Published

A simple library to check URL parameters for your APIs.

Downloads

11

Readme

npm version Downloads

SpectraGet

SpectraGet is a powerful Node.js library designed for validating request parameters for APIs. It provides an easy-to-use interface for validating various types of parameters, including strings, numbers, arrays, dates, emails, and more. SpectraGet helps you ensure that your API endpoints are robust and secure by validating request data against pre-defined rules.

Features

  • Type Validation: Supports validation for integers, floats, strings, booleans, dates, and more.
  • Length Validation: Enforces specific lengths for string and array parameters.
  • Range Validation: Validates numeric ranges and date ranges.
  • Value Validation: Checks if values are within a set of allowed values.
  • Regex Validation: Validates if a parameter matches a specific regex pattern.
  • Email Validation: Ensures that parameters are valid email addresses.
  • Password Strength Validation: Validates the strength of passwords based on various criteria.
  • IP Range Validation: Checks if an IP address is within a specified range.
  • JSON Validation: Validates if a parameter is a valid JSON string.
  • Flexible and Extensible: Easily add custom validation methods for your specific needs.

Installation

Install the library using npm:

npm install spectraget

Usage

To use SpectraGet, simply import the library and define your API endpoints with the necessary validation rules.

Example

const spectraget = require('spectraget');

// Define an endpoint with parameter validation rules
const params = [
    { name: 'key', type: 'string', mandatory: true, length: 32 },
    { name: 'id', type: 'int', mandatory: true, range: [17, 18] },
    { name: 'email', isEmail: true, mandatory: true },
    { name: 'password', isStrongPassword: true, mandatory: true },
    { name: 'date_of_birth', type: 'date', dateRange: ['2000-01-01', '2023-12-31'] }
  ]


// Request data to be validated
const requestData = {
  key: '12345678901234567890123456789012',
  id: 17,
  email: '[email protected]',
  password: 'StrongP@ssword123',
  date_of_birth: '2001-05-15'
};

// Validate the request data against the params rules
const validationResult = spectraget.validate(params, requestData);

if (validationResult) {
  console.error(`Validation Error: ${validationResult.error}`);
} else {
  console.log('Validation passed. Proceed with the request.');
}

API Reference

validate(params, requestData)

Validates the request data against the defined params rules.

  • Parameters:
    • params (Object): The params definition object with validation rules.
    • requestData (Object): The request data object to be validated.
  • Returns:
    • Returns null if validation passes.
    • Returns an object with error and status_code if validation fails.

Custom Validation Rules

You can easily add custom validation rules by extending the SpectraGet class and adding new methods. The validation rules can be applied dynamically based on your needs.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any improvements or additions.