Comparing version 4.1.1 to 5.0.0
@@ -1,3 +0,3 @@ | ||
const Joi = require('joi'); | ||
const moment = require('moment-timezone'); | ||
const Joi = require('joi') | ||
const { IANAZone } = require('luxon') | ||
@@ -11,21 +11,10 @@ module.exports = { | ||
rules: { | ||
returnMoment: { | ||
convert: true, | ||
method() { | ||
return this.$_setFlag('returnMoment', true); | ||
} | ||
} | ||
}, | ||
validate(value, helpers) { | ||
if (!moment.tz.zone(value)) { | ||
return { value, errors: helpers.error('timezone')}; | ||
validate (value, helpers) { | ||
if (!IANAZone.isValidZone(value)) { | ||
return { value, errors: helpers.error('timezone') } | ||
} | ||
// The value must be a string for validation, so we can't use coerce to convert as this runs before validation | ||
if (helpers.schema.$_getFlag('returnMoment') && helpers.prefs.convert) { | ||
return {value: moment.tz(value)}; | ||
} | ||
return {value}; | ||
return { value } | ||
} | ||
}; | ||
} |
{ | ||
"name": "joi-tz", | ||
"version": "4.1.1", | ||
"version": "5.0.0", | ||
"description": "Timezone string validation for Joi 16.x or higher.", | ||
@@ -12,5 +12,8 @@ "keywords": [ | ||
"validator", | ||
"moment" | ||
"luxor" | ||
], | ||
"main": "lib/index.js", | ||
"exports": ["./lib/index.js"], | ||
"files": [ | ||
"lib" | ||
], | ||
"repository": { | ||
@@ -22,7 +25,4 @@ "type": "git", | ||
"test": "tav", | ||
"cov": "npm run cov:tests && npm run cov:html", | ||
"cov:tests": "NODE_ENV=test COVERAGE=yes LOG_LEVEL=fatal nyc mocha --recursive", | ||
"cov:html": "nyc report --reporter=html && open coverage/index.html", | ||
"cov:coveralls": "nyc report --reporter=text-lcov | ./node_modules/coveralls/bin/coveralls.js", | ||
"lint": "eslint ./lib/ ./test/ && echo Lint OK", | ||
"coverage": "jest --coverage", | ||
"lint": "eslint .", | ||
"clean": "rm -rf node_modules/ && rm -rf coverage", | ||
@@ -38,3 +38,3 @@ "posttest": "npm run lint" | ||
"dependencies": { | ||
"moment-timezone": "^0.5.33" | ||
"luxon": "^3.4.4" | ||
}, | ||
@@ -45,14 +45,12 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"chai": "^4.3.4", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.26.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-react": "^7.23.2", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
"test-all-versions": "^5.0.1" | ||
"eslint": "^8.57.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jest": "^27.9.0", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"jest": "^29.7.0", | ||
"test-all-versions": "^6.1.0" | ||
} | ||
} |
# joi-tz - Joi Timezone Validation | ||
[![Build Status](https://travis-ci.org/tjdavey/joi-tz.svg?branch=master)](https://travis-ci.org/tjdavey/joi-tz) | ||
[![npm version](https://badge.fury.io/js/joi-tz.svg)](https://badge.fury.io/js/joi-tz) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/tjdavey/joi-tz/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/tjdavey/joi-tz/tree/main) | ||
[![Coverage Status](https://coveralls.io/repos/github/tjdavey/joi-tz/badge.svg)](https://coveralls.io/github/tjdavey/joi-tz) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/tjdavey/joi-tz/badge.svg?targetFile=package.json)](https://snyk.io/test/github/tjdavey/joi-tz?targetFile=package.json) | ||
[![npm version](https://badge.fury.io/js/joi-tz.svg)](https://badge.fury.io/js/joi-tz) | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftjdavey%2Fjoi-tz.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Ftjdavey%2Fjoi-tz?ref=badge_shield) | ||
Provides a Joi rule to validate IANA timezone strings (eg. `Europe/London`, `America/New_York`, `Etc/GMT-8`) using [moment-timezone](https://momentjs.com/timezone/). | ||
Provides a Joi rule to validate IANA timezone strings (eg. `Europe/London`, `America/New_York`, `Etc/GMT-8`) using [luxon](https://moment.github.io/luxon). | ||
@@ -33,23 +34,2 @@ Joi-tz supports and is tested against Joi 16.x or higher. | ||
### Rules | ||
#### `returnMoment` - Convert to a moment zone object | ||
When added to the validation chain returns a [moment zone object](https://momentjs.com/timezone/docs/#/zone-object/) which contains useful metadata about the timezone. | ||
```js | ||
Joi.timezone().returnMoment().validate('America/Los_Angeles'); | ||
/* | ||
returns { | ||
error: null, | ||
value: { | ||
name : 'America/Los_Angeles', | ||
abbrs : ['PDT', 'PST'], | ||
untils : [1414918800000, 1425808800000], | ||
offsets : [420, 480] | ||
} | ||
} | ||
*/ | ||
``` | ||
## Compatibility | ||
@@ -62,2 +42,3 @@ | ||
|----------------------------------------------------------------|----------------|----------|----------| | ||
| [5.0.0](https://github.com/tjdavey/joi-tz/releases/tag/v5.0.0) | | ✅ | ✅ | | ||
| [4.1.1](https://github.com/tjdavey/joi-tz/releases/tag/v4.1.1) | | ✅ | ✅ | | ||
@@ -64,0 +45,0 @@ | [4.1.0](https://github.com/tjdavey/joi-tz/releases/tag/v4.1.0) | | ✅ | ✅ | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
4695
4
17
48
+ Addedluxon@^3.4.4
+ Addedluxon@3.5.0(transitive)
- Removedmoment-timezone@^0.5.33
- Removedmoment@2.30.1(transitive)
- Removedmoment-timezone@0.5.46(transitive)