Merge branch 'master' of github.com:wearebraid/vue-formulate
This commit is contained in:
commit
760723bf5a
2
dist/formulate.esm.js
vendored
2
dist/formulate.esm.js
vendored
File diff suppressed because one or more lines are too long
4
dist/formulate.min.js
vendored
4
dist/formulate.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/formulate.umd.js
vendored
2
dist/formulate.umd.js
vendored
File diff suppressed because one or more lines are too long
4862
package-lock.json
generated
4862
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -55,7 +55,7 @@
|
|||||||
"autoprefixer": "^9.7.4",
|
"autoprefixer": "^9.7.4",
|
||||||
"babel-core": "^7.0.0-bridge.0",
|
"babel-core": "^7.0.0-bridge.0",
|
||||||
"babel-eslint": "^10.0.1",
|
"babel-eslint": "^10.0.1",
|
||||||
"babel-jest": "^24.9.0",
|
"babel-jest": "^25.1.0",
|
||||||
"cssnano": "^4.1.10",
|
"cssnano": "^4.1.10",
|
||||||
"cypress": "^4.1.0",
|
"cypress": "^4.1.0",
|
||||||
"eslint": "^5.16.0",
|
"eslint": "^5.16.0",
|
||||||
@ -66,11 +66,11 @@
|
|||||||
"eslint-plugin-standard": "^4.0.0",
|
"eslint-plugin-standard": "^4.0.0",
|
||||||
"eslint-plugin-vue": "^5.2.3",
|
"eslint-plugin-vue": "^5.2.3",
|
||||||
"flush-promises": "^1.0.2",
|
"flush-promises": "^1.0.2",
|
||||||
"jest": "^24.9.0",
|
"jest": "^25.1.0",
|
||||||
"jest-vue-preprocessor": "^1.7.1",
|
"jest-vue-preprocessor": "^1.7.1",
|
||||||
"node-sass": "^4.13.1",
|
"node-sass": "^4.13.1",
|
||||||
"postcss": "^7.0.27",
|
"postcss": "^7.0.27",
|
||||||
"postcss-cli": "^6.1.3",
|
"postcss-cli": "^7.1.0",
|
||||||
"rollup": "^1.31.1",
|
"rollup": "^1.31.1",
|
||||||
"rollup-plugin-auto-external": "^2.0.0",
|
"rollup-plugin-auto-external": "^2.0.0",
|
||||||
"rollup-plugin-internal": "^1.0.4",
|
"rollup-plugin-internal": "^1.0.4",
|
||||||
@ -86,7 +86,7 @@
|
|||||||
"watch": "^1.0.2"
|
"watch": "^1.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braid/vue-formulate-i18n": "^1.3.1",
|
"@braid/vue-formulate-i18n": "^1.3.2",
|
||||||
"is-plain-object": "^3.0.0",
|
"is-plain-object": "^3.0.0",
|
||||||
"is-url": "^1.2.4",
|
"is-url": "^1.2.4",
|
||||||
"nanoid": "^2.1.11"
|
"nanoid": "^2.1.11"
|
||||||
|
@ -58,18 +58,19 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* Rule: checks if the value is between two other values
|
* 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((() => {
|
return Promise.resolve((() => {
|
||||||
if (from === null || to === null || isNaN(from) || isNaN(to)) {
|
if (from === null || to === null || isNaN(from) || isNaN(to)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if ((!isNaN(value) && force !== 'length') || force === 'value') {
|
||||||
|
value = Number(value)
|
||||||
from = Number(from)
|
from = Number(from)
|
||||||
to = Number(to)
|
to = Number(to)
|
||||||
if (!isNaN(value)) {
|
|
||||||
value = Number(value)
|
|
||||||
return (value > from && value < 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 value.length > from && value.length < to
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -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 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('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))
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user