-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
201 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* return the value of the object for the given index | ||
* @param {any} object | ||
* @param {Number} index | ||
* @returns {boolean} | ||
*/ | ||
|
||
// obj,'1.2.3' -> multiIndex(obj,['1','2','3']) | ||
function pathIndex(obj,is) { | ||
return multiIndex(obj,is.split('.')); | ||
} | ||
|
||
// obj,['1','2','3'] -> ((obj['1'])['2'])['3'] | ||
function multiIndex(obj,is){ | ||
return is.length ? multiIndex(obj[is[0]],is.slice(1)) : obj | ||
} | ||
module.exports = {pathIndex,multiIndex} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const empty = require('../lib/empty'); | ||
const {pathIndex} = require('../lib/ObjectIndex'); | ||
|
||
module.exports = async function acceptedIf(field, value, args) { | ||
|
||
if (!args || args.length < 2) { | ||
|
||
throw new Error('Invalid arguments supplied for field ' + field + ' in requiredIf rule.'); | ||
return false; | ||
} | ||
|
||
if (args.length % 2 !== 0) { | ||
|
||
throw new Error('Invalid arguments supplied for field ' + field + ' in requiredIf rule.'); | ||
return false; | ||
} | ||
let acceptedValues = [true, 'true', 1, '1', 'yes', 'on']; | ||
|
||
let canbetrue = false; | ||
for (let start = 0; start < args.length; start += 2) { | ||
let requiredField = args[start]; | ||
let requiredValue = args[start + 1]; | ||
|
||
if (requiredField == field) { | ||
return false; | ||
} | ||
if(!empty(pathIndex(this.inputs,requiredField)) | ||
&& !acceptedValues.indexOf(pathIndex(this.inputs,requiredField)) >= 0){ | ||
return true; | ||
} | ||
|
||
// field can be true if all values are presented | ||
if (!empty(pathIndex(this.inputs,requiredField)) | ||
&& pathIndex(this.inputs,requiredField).toString() == requiredValue) { | ||
canbetrue = true; | ||
} else { | ||
canbetrue = false; | ||
break | ||
} | ||
} | ||
console.log(canbetrue); | ||
console.log(value); | ||
console.log(acceptedValues.indexOf(value)); | ||
if (canbetrue && !(acceptedValues.indexOf(value)>= 0)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const empty = require('../lib/empty'); | ||
const {pathIndex} = require('../lib/ObjectIndex'); | ||
|
||
module.exports = async function acceptedIf(field, value, args) { | ||
|
||
if (!args || args.length < 2) { | ||
|
||
throw new Error('Invalid arguments supplied for field ' + field + ' in requiredIf rule.'); | ||
return false; | ||
} | ||
|
||
if (args.length % 2 !== 0) { | ||
|
||
throw new Error('Invalid arguments supplied for field ' + field + ' in requiredIf rule.'); | ||
return false; | ||
} | ||
let acceptedValues = [true, 'true', 1, '1', 'yes', 'on']; | ||
|
||
let canbetrue = false; | ||
for (let start = 0; start < args.length; start += 2) { | ||
let requiredField = args[start]; | ||
let requiredValue = args[start + 1]; | ||
|
||
if (requiredField == field) { | ||
return false; | ||
} | ||
if(!empty(pathIndex(this.inputs,requiredField)) | ||
&& !acceptedValues.indexOf(pathIndex(this.inputs,requiredField)) >= 0){ | ||
return true; | ||
} | ||
|
||
// field can be true if all values are presented | ||
if (!empty(pathIndex(this.inputs,requiredField)) | ||
&& pathIndex(this.inputs,requiredField).toString() == requiredValue) { | ||
canbetrue = true; | ||
} else { | ||
canbetrue = false; | ||
break | ||
} | ||
} | ||
console.log(canbetrue); | ||
console.log(value); | ||
console.log(acceptedValues.indexOf(value)); | ||
if (canbetrue && acceptedValues.indexOf(value)>= 0) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters