1
0
mirror of synced 2025-02-16 20:53:13 +03:00

Updates between validation rule to support type forcing.

* Adds force to between

* Updates i18n to 1.3.2 with support for between force
This commit is contained in:
Justin Schroeder 2020-03-18 17:15:54 -04:00 committed by GitHub
parent 217b8b3ea9
commit 5e46b40399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2827 additions and 2082 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4872
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@braid/vue-formulate",
"version": "2.2.2",
"version": "2.2.3",
"description": "The easiest way to build forms in Vue.",
"main": "dist/formulate.umd.js",
"module": "dist/formulate.esm.js",
@ -55,7 +55,7 @@
"autoprefixer": "^9.7.4",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.9.0",
"babel-jest": "^25.1.0",
"cssnano": "^4.1.10",
"cypress": "^4.1.0",
"eslint": "^5.16.0",
@ -66,11 +66,11 @@
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.2.3",
"flush-promises": "^1.0.2",
"jest": "^24.9.0",
"jest": "^25.1.0",
"jest-vue-preprocessor": "^1.7.1",
"node-sass": "^4.13.1",
"postcss": "^7.0.27",
"postcss-cli": "^6.1.3",
"postcss-cli": "^7.1.0",
"rollup": "^1.31.1",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-internal": "^1.0.4",
@ -86,7 +86,7 @@
"watch": "^1.0.2"
},
"dependencies": {
"@braid/vue-formulate-i18n": "^1.3.1",
"@braid/vue-formulate-i18n": "^1.3.2",
"is-plain-object": "^3.0.0",
"is-url": "^1.2.4",
"nanoid": "^2.1.11"

View File

@ -58,18 +58,19 @@ export default {
/**
* Rule: checks if the value is between two other values
*/
between: function ({ value }, from = 0, to = 10) {
between: function ({ value }, from = 0, to = 10, force) {
return Promise.resolve((() => {
if (from === null || to === null || isNaN(from) || isNaN(to)) {
return false
}
from = Number(from)
to = Number(to)
if (!isNaN(value)) {
if ((!isNaN(value) && force !== 'length') || force === 'value') {
value = Number(value)
from = Number(from)
to = Number(to)
return (value > from && value < to)
}
if (typeof value === 'string') {
if (typeof value === 'string' || force === 'length') {
value = !isNaN(value) ? value.toString() : value
return value.length > from && value.length < to
}
return false

View File

@ -130,6 +130,14 @@ describe('between', () => {
it('fails with number to small', async () => expect(await rules.between({ value: 0 }, 3, 10)).toBe(false))
it('fails with number to large', async () => expect(await rules.between({ value: 15 }, 3, 10)).toBe(false))
it('passes when forced to value', async () => expect(await rules.between({ value: '4' }, 3, 10, 'value')).toBe(true))
it('fails when forced to value', async () => expect(await rules.between({ value: 442 }, 3, 10, 'value')).toBe(false))
it('passes when forced to length', async () => expect(await rules.between({ value: 7442 }, 3, 10, 'length')).toBe(true))
it('fails when forced to length', async () => expect(await rules.between({ value: 6 }, 3, 10, 'length')).toBe(false))
})
/**