Skip to content

Commit

Permalink
feat: Support for Luxon
Browse files Browse the repository at this point in the history
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
  • Loading branch information
ssaarela committed Aug 16, 2022
1 parent edff4ec commit 6a243f0
Show file tree
Hide file tree
Showing 15 changed files with 1,105 additions and 4 deletions.
38 changes: 38 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"timeout": 20000
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"timeout": 20000
},
{
"name": "Run Current file",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "${workspaceFolder}/node_modules/ts-node/register/transpile-only"],

"args": ["${relativeFile}"],

"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
]
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ conform to the expected model.

[`@finnair/v-validation` README](./packages/core/README.md)

## Vluxon

`Vluxon` contains `v-validation` extensions for [Luxon](https://moment.github.io/luxon/).

[`@finnair/v-validation-luxon` README](./packages/luxon/README.md)

## Vmoment

NOTE: [Moment is a legacy project in maintenance mode](https://momentjs.com/docs/#/-project-status/).

`Vmoment` contains `v-validation` extensions for [Moment.js](https://momentjs.com/).

[`@finnair/v-validation-moment` README](./packages/moment/README.md)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lerna": "4.0.0",
"prettier": "2.0.5",
"ts-jest": "27.1.3",
"ts-node": "10.9.1",
"typescript": "4.5.4"
},
"workspaces": {
Expand Down
3 changes: 3 additions & 0 deletions packages/luxon/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
tsconfig.json
tsconfig.tsbuildinfo
4 changes: 4 additions & 0 deletions packages/luxon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
43 changes: 43 additions & 0 deletions packages/luxon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[![npm version](https://badge.fury.io/js/%40finnair%2Fv-validation-luxon.svg)](https://badge.fury.io/js/%40finnair%2Fv-validation-luxon)

# v-validation-luxon

`@finnair/v-validation-luxon` is an extension to `@finnair/v-validation`.

`Vluxon` extension uses custom wrapper types for Luxon DateTime to support full JSON roundtrip with strict validation.

[Documentation for `v-validation`](https://github.com/finnair/v-validation).

## Getting Started

Install v-validation using [`yarn`](https://yarnpkg.com/en/package/jest):

```bash
yarn add @finnair/v-validation-luxon
```

Or [`npm`](https://www.npmjs.com/):

```bash
npm install @finnair/v-validation-luxon
```

## Vluxon

`validateLuxon` functions can be used to build custom DateTime validators/converters
by supplying a RegExp pattern and a wrapper class (subclass of LuxonDateTime).
The wrapper class should guarantee proper `toJSON()` and other required properties
for the type (e.g. timezone handling).

Time zone 00:00 is serialized as `Z`.

| Vluxon . | Format | Description |
| ----------------- | -------------------------- | ------------------------------------------------------ |
| date | `YYYY-MM-DD` | Local date. |
| dateUtc | `YYYY-MM-DD` | Date in UTC time zone. |
| dateTime | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in local (parsed) time zone. |
| dateTimeUtc | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in UTC time zone. |
| dateTimeMillis | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in local (parsed) time zone. |
| dateTimeMillisUtc | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in UTC time zone. |
| time | `HH:mm:ss` | Local time. |
| duration | ISO 8601 Duration | Luxon `Duration` with pattern validation. |
35 changes: 35 additions & 0 deletions packages/luxon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@finnair/v-validation-luxon",
"version": "1.0.1",
"private": false,
"description": "Luxon validators",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"homepage": "https://github.com/finnair/v-validation/tree/master/packages/luxon#readme",
"bugs": "https://github.com/finnair/v-validation/issues",
"repository": {
"type": "git",
"url": "https://github.com/finnair/v-validation.git",
"directory": "packages/luxon"
},
"keywords": [
"validation",
"validate",
"convert",
"normalize",
"typescript",
"luxon"
],
"scripts": {
"build": "tsc -b ."
},
"dependencies": {
"@finnair/path": "^1.0.1",
"@finnair/v-validation": "^1.0.1",
"luxon": "3.0.1"
},
"devDependencies": {
"@types/luxon": "3.0.0"
}
}
Loading

0 comments on commit 6a243f0

Please sign in to comment.