Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/fusspot

Package Overview
Dependencies
Maintainers
14
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/fusspot

A tiny runtime library for type assertions

  • 0.8.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
14
Created

What is @mapbox/fusspot?

@mapbox/fusspot is a validation library that helps you validate JavaScript objects and values. It provides a set of validators that can be used to ensure that data conforms to expected formats and types.

What are @mapbox/fusspot's main functionalities?

Basic Type Validation

This feature allows you to validate basic data types such as strings and numbers. The code sample demonstrates how to validate a string and a number using the `string` and `number` validators.

const fusspot = require('@mapbox/fusspot');
const { string, number } = fusspot;

const validateString = string();
const validateNumber = number();

console.log(validateString('Hello')); // 'Hello'
console.log(validateNumber(42)); // 42

Object Validation

This feature allows you to validate objects with specific properties. The code sample demonstrates how to validate an object with `name` and `age` properties using the `object` validator.

const fusspot = require('@mapbox/fusspot');
const { object, string, number } = fusspot;

const validatePerson = object({
  name: string(),
  age: number()
});

const person = { name: 'Alice', age: 30 };
console.log(validatePerson(person)); // { name: 'Alice', age: 30 }

Array Validation

This feature allows you to validate arrays of specific types. The code sample demonstrates how to validate an array of strings using the `arrayOf` validator.

const fusspot = require('@mapbox/fusspot');
const { arrayOf, string } = fusspot;

const validateStringArray = arrayOf(string());

const stringArray = ['apple', 'banana', 'cherry'];
console.log(validateStringArray(stringArray)); // ['apple', 'banana', 'cherry']

Custom Validators

This feature allows you to create custom validators for more complex validation logic. The code sample demonstrates how to create a custom validator that checks if a number is even.

const fusspot = require('@mapbox/fusspot');
const { custom } = fusspot;

const isEven = custom((value) => {
  if (typeof value !== 'number' || value % 2 !== 0) {
    throw new Error('Value must be an even number');
  }
  return value;
});

console.log(isEven(4)); // 4
console.log(isEven(3)); // Error: Value must be an even number

Other packages similar to @mapbox/fusspot

Keywords

FAQs

Package last updated on 05 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc