-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(method-count): remove extra functions
- Remove ArrayVariable.prototype.isNonEmpty - Rename Proposition results' names to match their operator method names. #103
- Loading branch information
1 parent
035db0f
commit c1e412f
Showing
3 changed files
with
85 additions
and
58 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
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,31 @@ | ||
const debug = require('debug')( | ||
'@archetypes/rules/variable/helpers/get-validated-number-value' | ||
) | ||
const ow = require('ow') | ||
|
||
/** | ||
* Returns a Number. | ||
* | ||
* @private | ||
* | ||
* @param {@archetypes/rules/variable|number|string} variable - A valid | ||
* - Instance of @archetypes/rules/variable | ||
* - ECMAScript Number | ||
* - ECMAScript String | ||
* @throws {ArgumentError} | ||
* @returns {number} - The length of an ArrayVariable or string. | ||
*/ | ||
|
||
const getValidatedNumberValue = (variable) => { | ||
const val = variable.valueOf() | ||
debug(`getValidatedNumberValue: variable.valueOf(): ${val}`) | ||
ow(val, ow.any(ow.array, ow.number, ow.string)) | ||
if (Array.isArray(val) || ow.isValid(val, ow.string)) { | ||
debug(`getValidatedNumberValue => ${val.length}`) | ||
return val.length | ||
} | ||
debug(`getValidatedNumberValue => ${val}`) | ||
return val | ||
} | ||
|
||
module.exports = getValidatedNumberValue |