Comparing version 4.0.1 to 4.0.2
{ | ||
"name": "joi-tz", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Timezone string validation for Joi 16.x or higher.", | ||
@@ -21,5 +21,6 @@ "keywords": [ | ||
"test": "NODE_ENV=test mocha --recursive", | ||
"cov": "npm run cov", | ||
"cov:html": "NODE_ENV=test COVERAGE=yes LOG_LEVEL=fatal istanbul cover --report html ./node_modules/.bin/_mocha -- --recursive && open coverage/index.html", | ||
"cov:coveralls": "NODE_ENV=test COVERAGE=yes LOG_LEVEL=fatal istanbul cover --report lcovonly ./node_modules/.bin/_mocha -- --recursive && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"cov": "npm run cov:tests && npm run cov:html", | ||
"cov:tests": "NODE_ENV=test COVERAGE=yes LOG_LEVEL=fatal nyc npm run test", | ||
"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", | ||
@@ -44,11 +45,12 @@ "clean": "rm -rf node_modules/ && rm -rf coverage", | ||
"chai": "^4.1.0", | ||
"coveralls": "^3.0.3", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^15.1.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-jsx-a11y": "^5.1.1", | ||
"eslint-plugin-react": "^7.1.0", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"mocha": "^6.2.3" | ||
"coveralls": "^3.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb": "^18.1.0", | ||
"eslint-plugin-import": "^2.21.2", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react": "^7.20.0", | ||
"eslint-plugin-react-hooks": "^2.5.0", | ||
"mocha": "^6.2.3", | ||
"nyc": "^15.1.0" | ||
} | ||
} |
@@ -5,13 +5,19 @@ # joi-tz | ||
[![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) | ||
Provides a Joi rule to validate IANA timezone strings using moment-timezone. | ||
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/). | ||
This project is forked from the unmaintained `joi-timezone` and only supports Joi 16.x or higher. For Joi 9.x-15.x and support use [joi-timezone](https://www.npmjs.com/package/joi-timezone). | ||
Joi-tz only supports Joi 16.x or higher. | ||
## Usage | ||
This project is forked from [joi-timezone](https://www.npmjs.com/package/joi-timezone) (unmaintained). That project remains functional for Joi 9.x-15.x. | ||
Note: **requires** Joi version >= 16 | ||
## Installation: | ||
### Installation | ||
**npm:** `npm install joi-tz` | ||
**yarn:** `yarn add joi-tz` | ||
## Usage | ||
```js | ||
@@ -23,34 +29,25 @@ import BaseJoi from 'joi'; | ||
// Create a joi schema using the timezone validator; | ||
const schema = Joi.timezone(); | ||
Joi.timezone().validate('Melbourne/Australia'); | ||
// returns {error: null, value: 'Melbourne/Australia'} | ||
``` | ||
### Validation | ||
### Rules | ||
```js | ||
Joi.timezone().validate("Melbourne/Australia"); | ||
/* | ||
{ | ||
error: null, | ||
value: "Melbourne/Australia" | ||
} | ||
*/ | ||
``` | ||
#### `returnMoment` - Convert to a moment zone object | ||
### Rules | ||
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. | ||
#### `returnMoment` - Convert to a moment timezone object | ||
```js | ||
Joi.timezone().returnMoment().validate("Melbourne/Australia"); | ||
Joi.timezone().returnMoment().validate('America/Los_Angeles'); | ||
/* | ||
{ | ||
error: null, | ||
value: { | ||
...moment object | ||
returns { | ||
error: null, | ||
value: { | ||
name : 'America/Los_Angeles', | ||
abbrs : ['PDT', 'PST'], | ||
untils : [1414918800000, 1425808800000], | ||
offsets : [420, 480] | ||
} | ||
} | ||
} | ||
*/ | ||
*/ | ||
``` | ||
const BaseJoi = require('@hapi/joi'); | ||
const assert = require('chai').assert; | ||
const {assert} = require('chai'); | ||
const JoiTimezone = require('../lib'); | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
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
11610
17
11
52