Skip to content
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

validator: date normalizer #624

Merged
merged 8 commits into from
Oct 9, 2024
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
23 changes: 19 additions & 4 deletions flatfilers/sandbox/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { FlatfileListener } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
import { viewMappedPlugin } from '@flatfile/plugin-view-mapped'
import { validateDate } from '@flatfile/plugin-validate-date'

export default async function (listener: FlatfileListener) {

listener.use(viewMappedPlugin())

listener.use(
validateDate({
sheetSlug: 'contacts',
dateFields: ['dob', 'hire_date'],
outputFormat: 'MM/dd/yyyy',
includeTime: true,
})
)
listener.use(
configureSpace({
workbooks: [
Expand Down Expand Up @@ -42,6 +47,16 @@ export default async function (listener: FlatfileListener) {
type: 'string',
label: 'Country',
},
{
key: 'dob',
type: 'string',
label: 'Date of Birth',
},
{
key: 'hire_date',
type: 'string',
label: 'Hire Date',
},
],
},
],
Expand Down
78 changes: 69 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions validate/date/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!-- START_INFOCARD -->

The `@flatfile/plugin-validate-date` plugin provides date format normalization functionality for Flatfile. It detects various date formats and converts them to a specified output format, supporting multiple fields and locales.

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

<!-- END_INFOCARD -->

## Parameters

#### `config.sheetSlug` - `string` - `default: **` - (optional)
The `sheetSlug` parameter is the slug of the sheet to apply the normalizer to. If not provided, it will apply to all sheets.

#### `config.dateFields` - `string[]`
The `dateFields` parameter is an array of field names that contain date values to be normalized.

#### `config.outputFormat` - `string`
The `outputFormat` parameter specifies the desired output format for the normalized dates.

#### `config.includeTime` - `boolean`
The `includeTime` parameter determines whether to include time in the normalized output.

## Usage

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

### Import

```js
import { validateDate } from '@flatfile/plugin-validate-date'
```

## Example Usage

This example sets up the date format normalizer for the "contacts" sheet, normalizing the "birthdate" and "registration_date" fields to the "MM/DD/YYYY" format.

```javascript
import { FlatfileListener } from '@flatfile/listener'
import { validateDate } from '@flatfile/plugin-validate-date'

export default function (listener: FlatfileListener) {
listener.use(
validateDate({
sheetSlug: 'contacts',
dateFields: ['birthdate', 'registration_date'],
outputFormat: 'MM/DD/YYYY',
includeTime: false
})
)

// ... rest of your Flatfile listener configuration
}
```
69 changes: 69 additions & 0 deletions validate/date/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@flatfile/plugin-validate-date",
"version": "0.0.0",
"url": "https://github.com/FlatFilers/flatfile-plugins/tree/main/validate/date",
"description": "A Flatfile plugin for normalizing date formats",
"registryMetadata": {
"category": "validate"
},
"engines": {
"node": ">= 16"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"not dead"
],
"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"
},
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"source": "./src/index.ts",
"types": "dist/index.d.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-transform"
],
"author": "Flatfile, Inc.",
"repository": {
"type": "git",
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "validate/date"
},
"license": "ISC",
"dependencies": {
"@flatfile/plugin-record-hook": "^1.7.1",
"chrono-node": "^2.7.7",
"date-fns": "^4.1.0"
},
"peerDependencies": {
"@flatfile/listener": "^1.0.5"
},
"devDependencies": {
"@flatfile/rollup-config": "0.1.1"
}
}
5 changes: 5 additions & 0 deletions validate/date/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/date/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { validateDate } from './validate.date.plugin'
Loading
Loading