-
Notifications
You must be signed in to change notification settings - Fork 11
validator: number #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
validator: number #649
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ad2aa9f
koala: initial commit
bangarang 723b01e
feat: add tests
bangarang 81c3535
feat: fix tests
bangarang 8e78739
feat: remove metadata.json and cleanup infocard in readme
bangarang f314acd
feat: npm install after rebase
bangarang 92ba513
Update validate/number/package.json
carlbrugger e5f67b9
feat: move logic to a separate file
bangarang f147cb1
feat: rename
bangarang 9be0704
feat: refactor for unit tests
bangarang f48b973
feat: update package.json
bangarang a02bbdc
Apply suggestions from code review
carlbrugger a99f28c
Update package.json
carlbrugger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <!-- START_INFOCARD --> | ||
| # @flatfile/plugin-validate-number | ||
|
|
||
| The `@flatfile/plugin-validate-number` plugin provides comprehensive number validation capabilities for your data import processes. It offers a wide range of validation options to ensure that numeric data meets specific criteria before being accepted. | ||
|
|
||
| **Event Type:** | ||
| `listener.on('commit:created')` | ||
|
|
||
| <!-- END_INFOCARD --> | ||
|
|
||
| ## Features | ||
|
|
||
| - Min/Max value validation | ||
| - Integer-only validation | ||
| - Precision and scale validation | ||
| - Currency formatting validation | ||
| - Step (increment) validation | ||
| - Special number type validation (prime, even, odd) | ||
| - Rounding and truncation options | ||
| - Customizable thousands separator and decimal point | ||
| - Inclusive/exclusive range validation | ||
|
|
||
| ## Installation | ||
|
|
||
| To install the plugin, use npm: | ||
|
|
||
| ```bash | ||
| npm install @flatfile/plugin-validate-number | ||
| ``` | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```javascript | ||
| import { FlatfileListener } from '@flatfile/listener'; | ||
| import { validateNumber } from '@flatfile/plugin-validate-number'; | ||
|
|
||
| const listener = new FlatfileListener(); | ||
|
|
||
| listener.use( | ||
| validateNumber({ | ||
| min: 0, | ||
| max: 1000, | ||
| inclusive: true, | ||
| integerOnly: true, | ||
| precision: 10, | ||
| scale: 2, | ||
| currency: true, | ||
| step: 5, | ||
| thousandsSeparator: ',', | ||
| decimalPoint: '.', | ||
| specialTypes: ['even'], | ||
| round: true | ||
| }) | ||
| ); | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| The `validateNumber` accepts a configuration object with the following options: | ||
|
|
||
| - `min`: Minimum allowed value | ||
bangarang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - `max`: Maximum allowed value | ||
| - `inclusive`: Whether the min/max range is inclusive | ||
| - `integerOnly`: Allow only integer values | ||
| - `precision`: Total number of digits allowed | ||
| - `scale`: Number of decimal places allowed | ||
| - `currency`: Validate as a currency value | ||
| - `step`: Increment value (e.g., multiples of 5) | ||
| - `thousandsSeparator`: Character used as thousands separator | ||
| - `decimalPoint`: Character used as decimal point | ||
| - `specialTypes`: Array of special number types to validate ('prime', 'even', 'odd') | ||
| - `round`: Round the number to the nearest integer | ||
| - `truncate`: Truncate the decimal part of the number | ||
|
|
||
bangarang marked this conversation as resolved.
Show resolved
Hide resolved
bangarang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Behavior | ||
|
|
||
| The plugin listens for the 'commit:created' event and performs validation on a specified number field (default field name is 'numberField'). It applies the configured validations and throws an error if any validation fails. | ||
|
|
||
| The plugin also handles number parsing, considering the specified thousands separator and decimal point. It can optionally round or truncate the number before applying validations. | ||
|
|
||
| If all validations pass, the plugin logs a success message. If any validation fails, it logs an error message and throws an error with a descriptive message about the validation failure. | ||
bangarang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| module.exports = { | ||
| testEnvironment: 'node', | ||
|
|
||
| transform: { | ||
| '^.+\\.tsx?$': 'ts-jest', | ||
| }, | ||
| setupFiles: ['../../test/dotenv-config.js'], | ||
| setupFilesAfterEnv: [ | ||
| '../../test/betterConsoleLog.js', | ||
| '../../test/unit.cleanup.js', | ||
| ], | ||
| testTimeout: 60_000, | ||
| globalSetup: '../../test/setup-global.js', | ||
| forceExit: true, | ||
| passWithNoTests: true, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.