1
0
mirror of synced 2024-11-25 14:56:03 +03:00

Merge branch 'master' of github.com:wearebraid/vue-formulate

This commit is contained in:
Justin Schroeder 2020-03-18 17:22:33 -04:00
commit 760723bf5a
7 changed files with 2825 additions and 2080 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

4870
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

@ -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
} }
from = Number(from) if ((!isNaN(value) && force !== 'length') || force === 'value') {
to = Number(to)
if (!isNaN(value)) {
value = Number(value) value = Number(value)
from = Number(from)
to = Number(to)
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

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 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))
}) })
/** /**