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

@flatfile/plugin-validate-boolean

v0.2.0

Published

A Flatfile plugin for boolean validation with multi-language support

Downloads

213

Readme

@flatfile/plugin-validate-boolean

The @flatfile/plugin-validate-boolean plugin provides comprehensive boolean validation capabilities, offering flexible configuration options to handle various boolean representations across different languages and use cases.

Event Type: listener.on('commit:created')

Features

  • Supports both strict and truthy boolean validation
  • Multi-language support (English, Spanish, French, German)
  • Custom mapping for boolean values
  • Case-sensitive and case-insensitive options
  • Configurable null value handling
  • Option to convert non-boolean values
  • Custom error messages
  • Default value setting

Installation

To install the plugin, run the following command:

npm install @flatfile/plugin-validate-boolean

Example Usage

import { validateBoolean } from '@flatfile/plugin-validate-boolean';

listener.use(
  validateBoolean({
    fields: ['isActive', 'hasSubscription'],
    validationType: 'truthy',
    language: 'en',
    handleNull: 'false',
    convertNonBoolean: true
  }
));

Configuration

The BooleanValidator function accepts a configuration object with the following properties:

  • fields: An array of field names to validate
  • validationType: 'strict' or 'truthy'
  • customMapping: A custom mapping of string values to boolean
  • caseSensitive: Whether the validation should be case-sensitive
  • handleNull: How to handle null values ('error', 'false', 'true', or 'skip')
  • convertNonBoolean: Whether to convert non-boolean values to boolean
  • language: The language for predefined mappings ('en', 'es', 'fr', 'de')
  • customErrorMessages: Custom error messages for different scenarios
  • defaultValue: A default value to use for invalid inputs

Behavior

  1. Strict Validation: Only accepts 'true', 'false', true, or false as valid inputs.
  2. Truthy Validation: Accepts various representations of true/false, including language-specific terms.
  3. Null Handling: Configurable behavior for null or undefined values.
  4. Non-Boolean Conversion: Option to convert non-boolean values to boolean.
  5. Error Handling: Adds errors or info messages to the record for invalid inputs.
  6. Default Value: Option to set a default value for invalid inputs instead of raising an error.

The plugin can be used either as a RecordHook or as an external constraint, providing flexibility in integration with your Flatfile setup.