Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 99 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions validate/boolean/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!-- START_INFOCARD -->
# @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')`

<!-- END_INFOCARD -->

## 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:

```bash
npm install @flatfile/plugin-validate-boolean
```

## Example Usage

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

const booleanValidator = validateBoolean({
fields: ['isActive', 'hasSubscription'],
validationType: 'truthy',
language: 'en',
handleNull: 'false',
convertNonBoolean: true
});

listener.use(booleanValidator);
```

## Configuration

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

- `fields`: An array of field names to validate
Comment on lines +48 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Formatting Issue: Remove Extra Blank Line Before List

An extra blank line after line 42 may disrupt the list formatting in Markdown.

Suggestion: Remove the blank line at line 43 so that the list follows immediately after the introductory sentence.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~44-~44: Loose punctuation mark.
Context: ...th the following properties: - fields: An array of field names to validate - `...

(UNLIKELY_OPENING_PUNCTUATION)

- `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.
Comment on lines +1 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Suggestion: Restructure README to follow standard format

While the content of the README is comprehensive and well-organized, it doesn't follow the standard README structure used in the project. Consider restructuring the document to align with the project's conventions, which might include sections like:

  1. Introduction
  2. Installation
  3. Usage
  4. API Reference
  5. Configuration
  6. Examples
  7. Contributing
  8. License

This restructuring will improve consistency across the project's documentation and make it easier for users to find information.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~50-~50: Loose punctuation mark.
Context: ...th the following properties: - fields: An array of field names to validate - `...

(UNLIKELY_OPENING_PUNCTUATION)

98 changes: 98 additions & 0 deletions validate/boolean/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"timestamp": "2024-10-01T04-33-41-969Z",
"task": "Create a Boolean Validator Flatfile Listener plugin:\n - Add configuration for what fields are booleans\n - Implement strict boolean validation (true/false only)\n - Add support for truthy/falsy value validation\n - Allow custom truthy/falsy value mapping (e.g., 'yes'/'no', '1'/'0')\n - Implement case-insensitive boolean string matching\n - Add options for handling null/undefined values\n - Implement conversion of non-boolean types to boolean\n - Add support for multi-language boolean representations\n - Implement custom error messages for invalid boolean values\n - Add options for default values when conversion fails\n - Export recordHook and external constraint versions",
"summary": "This code implements a Boolean Validator plugin for Flatfile, providing both recordHook and external constraint versions. The plugin validates boolean fields in records, supporting strict and truthy validation types, custom mappings, and multi-language support.",
"steps": [
[
"Retrieve information about Flatfile Listeners and the Record Hook plugin to understand the structure and best practices.\n",
"#E1",
"PineconeAssistant",
"Provide information about Flatfile Listeners and the Record Hook plugin, including their structure and best practices",
"Plan: Retrieve information about Flatfile Listeners and the Record Hook plugin to understand the structure and best practices.\n#E1 = PineconeAssistant[Provide information about Flatfile Listeners and the Record Hook plugin, including their structure and best practices]"
],
[
"Create the basic structure of the Boolean Validator plugin, including configuration options for boolean fields and validation types.\n",
"#E2",
"LLM",
"Create a basic structure for a Flatfile Listener plugin named BooleanValidator with configuration options for boolean fields and validation types (strict, truthy/falsy) based on the information in #E1",
"Plan: Create the basic structure of the Boolean Validator plugin, including configuration options for boolean fields and validation types.\n#E2 = LLM[Create a basic structure for a Flatfile Listener plugin named BooleanValidator with configuration options for boolean fields and validation types (strict, truthy/falsy) based on the information in #E1]"
],
[
"Implement strict boolean validation and truthy/falsy value validation.\n",
"#E3",
"LLM",
"Extend the BooleanValidator plugin from #E2 to include implementations for strict boolean validation (true/false only) and truthy/falsy value validation",
"Plan: Implement strict boolean validation and truthy/falsy value validation.\n#E3 = LLM[Extend the BooleanValidator plugin from #E2 to include implementations for strict boolean validation (true/false only) and truthy/falsy value validation]"
],
[
"Add support for custom truthy/falsy value mapping and case-insensitive boolean string matching.\n",
"#E4",
"LLM",
"Enhance the BooleanValidator plugin from #E3 to support custom truthy/falsy value mapping (e.g., 'yes'/'no', '1'/'0') and implement case-insensitive boolean string matching",
"Plan: Add support for custom truthy/falsy value mapping and case-insensitive boolean string matching.\n#E4 = LLM[Enhance the BooleanValidator plugin from #E3 to support custom truthy/falsy value mapping (e.g., 'yes'/'no', '1'/'0') and implement case-insensitive boolean string matching]"
],
[
"Implement options for handling null/undefined values and conversion of non-boolean types to boolean.\n",
"#E5",
"LLM",
"Add functionality to the BooleanValidator plugin from #E4 to handle null/undefined values and implement conversion of non-boolean types to boolean",
"Plan: Implement options for handling null/undefined values and conversion of non-boolean types to boolean.\n#E5 = LLM[Add functionality to the BooleanValidator plugin from #E4 to handle null/undefined values and implement conversion of non-boolean types to boolean]"
],
[
"Add support for multi-language boolean representations and custom error messages for invalid boolean values.\n",
"#E6",
"LLM",
"Extend the BooleanValidator plugin from #E5 to support multi-language boolean representations and implement custom error messages for invalid boolean values",
"Plan: Add support for multi-language boolean representations and custom error messages for invalid boolean values.\n#E6 = LLM[Extend the BooleanValidator plugin from #E5 to support multi-language boolean representations and implement custom error messages for invalid boolean values]"
],
[
"Implement options for default values when conversion fails.\n",
"#E7",
"LLM",
"Add functionality to the BooleanValidator plugin from #E6 to include options for default values when conversion fails",
"Plan: Implement options for default values when conversion fails.\n#E7 = LLM[Add functionality to the BooleanValidator plugin from #E6 to include options for default values when conversion fails]"
],
[
"Create the recordHook version of the Boolean Validator plugin.\n",
"#E8",
"LLM",
"Convert the BooleanValidator plugin from #E7 into a recordHook version, ensuring it adheres to the recordHook structure and requirements based on the information in #E1",
"Plan: Create the recordHook version of the Boolean Validator plugin.\n#E8 = LLM[Convert the BooleanValidator plugin from #E7 into a recordHook version, ensuring it adheres to the recordHook structure and requirements based on the information in #E1]"
],
[
"Create the external constraint version of the Boolean Validator plugin.\n",
"#E9",
"LLM",
"Convert the BooleanValidator plugin from #E7 into an external constraint version, ensuring it adheres to the external constraint structure and requirements based on the information in #E1",
"Plan: Create the external constraint version of the Boolean Validator plugin.\n#E9 = LLM[Convert the BooleanValidator plugin from #E7 into an external constraint version, ensuring it adheres to the external constraint structure and requirements based on the information in #E1]"
],
[
"Combine all components and create the final Boolean Validator Flatfile Listener plugin with both recordHook and external constraint versions.\n",
"#E10",
"LLM",
"Combine the BooleanValidator plugin implementations from #E7, #E8, and #E9 into a single file, exporting both recordHook and external constraint versions. Ensure all required functionality is included and the code is properly structured and commented",
"Plan: Combine all components and create the final Boolean Validator Flatfile Listener plugin with both recordHook and external constraint versions.\n#E10 = LLM[Combine the BooleanValidator plugin implementations from #E7, #E8, and #E9 into a single file, exporting both recordHook and external constraint versions. Ensure all required functionality is included and the code is properly structured and commented]"
],
[
"Validate the final Boolean Validator plugin code, check for unused imports, and ensure correct Event Topic usage.\n",
"#E11",
"PineconeAssistant",
"Validate the Boolean Validator plugin code from #E10, check for unused imports, ensure correct Event Topic usage, and verify that all required functionality is implemented correctly",
"Plan: Validate the final Boolean Validator plugin code, check for unused imports, and ensure correct Event Topic usage.\n#E11 = PineconeAssistant[Validate the Boolean Validator plugin code from #E10, check for unused imports, ensure correct Event Topic usage, and verify that all required functionality is implemented correctly]"
],
[
"Make any necessary corrections or improvements based on the validation results.\n",
"#E12",
"LLM",
"Review the validation results from #E11 and make any necessary corrections or improvements to the Boolean Validator plugin code",
"Plan: Make any necessary corrections or improvements based on the validation results.\n#E12 = LLM[Review the validation results from #E11 and make any necessary corrections or improvements to the Boolean Validator plugin code]"
]
],
"metrics": {
"tokens": {
"plan": 8662,
"state": 8209,
"total": 16871
}
}
}
60 changes: 60 additions & 0 deletions validate/boolean/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@flatfile/plugin-validate-boolean",
"version": "0.0.0",
"description": "A Flatfile plugin for boolean validation with multi-language support",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"browser": {
"./dist/index.cjs": "./dist/index.browser.cjs",
"./dist/index.mjs": "./dist/index.browser.mjs"
},
"exports": {
"types": "./dist/index.d.ts",
"node": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"browser": {
"require": "./dist/index.browser.cjs",
"import": "./dist/index.browser.mjs"
},
"default": "./dist/index.mjs"
},
"source": "./src/index.ts",
"files": [
"dist/**"
],
"scripts": {
"build": "rollup -c",
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
},
"keywords": [
"flatfile-plugins",
"category-validate"
],
"author": "Flatfile, Inc.",
"license": "ISC",
"dependencies": {
"@flatfile/plugin-record-hook": "^1.7.0"
},
"peerDependencies": {
"@flatfile/listener": "^1.0.5"
},
"devDependencies": {
"@flatfile/rollup-config": "^0.1.1"
},
"repository": {
"type": "git",
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "validate/boolean"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"not dead"
]
}
5 changes: 5 additions & 0 deletions validate/boolean/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { buildConfig } from '@flatfile/rollup-config'

const config = buildConfig({})

export default config
1 change: 1 addition & 0 deletions validate/boolean/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './validate.boolean.plugin'
Loading