boolean fcf.isNature(mixed a_value, string | fcf.UNDEFINED..fcf.NUMBERED | [string|fcf.UNDEFINED..fcf.NUMBERED] a_nature, boolean a_softMode = false)
Package: fcf-framework-core
File: fcf-framework-core:fcf.js
Available from version: 2.0.2
Checks if an argument matches the given data classification
Arguments
mixed a_value
- Test value
string | fcf.UNDEFINED..fcf.NUMBERED | [string|fcf.UNDEFINED..fcf.NUMBERED] a_nature
- A data classification type, or an array of data classification types that can take one of the following values:
fcf.UNDEFINED | "undefined" | 0 - Points to the value undefined
fcf.NULL | "null" | 1 - Points to the value null
fcf.NAN | "nan" | 2 - Indicates the value NaN
fcf.BOOLEAN | "boolean" | 3 - Indicates the data type boolean
fcf.NUMBER | "number" | 4 - Indicates the data type number (Value NaN is not included in this category)
fcf.STRING | "string" | 5 - Indicates the data type string
fcf.DATE | "date" | 6 - Indicates the data type Date
fcf.OBJECT | "object" | 7 - Indicates the object data type (except for null and Date).
fcf.ARRAY | "array" | 8 - Points to the array data type.
fcf.ITERABLE | "iterable" | 9 - Points to an iterable (type string is not included in this category).
fcf.NUMBERED | "numbered" | 10 - Points to an enumerated object (type string is not included in this category).
boolean a_softMode = false
- If it is true when checking a string containing a number or a date for compliance with the fcf.NUMBER or fcf.DATE types, the function will return true
console.log(`"hello" is fcf.STRING :`, fcf.isNature("hello", fcf.STRING));
console.log(`null is [fcf.STRING, fcf.NULL] :`, fcf.isNature(null, [fcf.STRING, fcf.NULL]));
console.log(`1 is "number" :`, fcf.isNature(1, "number"));
console.log(`[] is fcf.NUMBERED :`, fcf.isNature([], fcf.NUMBERED));
console.log(`new Date() is fcf.DATE :`, fcf.isNature(new Date(), fcf.DATE));
console.log(`"123" is fcf.NUMBERED :`, fcf.isNature("123", fcf.NUMBERED));
console.log(`"123" is fcf.NUMBER :`, fcf.isNature("123", fcf.NUMBER));
Output:
"hello" is fcf.STRING : true
null is [fcf.STRING, fcf.NULL] : true
1 is "number" : true
[] is fcf.NUMBERED : true
new Date() is fcf.DATE : true
"123" is fcf.NUMBERED : false
"123" is fcf.NUMBER : false
console.log(`[SOFT_MODE: TRUE]: "123" is fcf.NUMBER :`, fcf.isNature("123", fcf.NUMBER, true));
console.log(`[SOFT_MODE: TRUE]: "" is fcf.NUMBER :`, fcf.isNature("", fcf.NUMBER, true));
console.log(`[SOFT_MODE: FALSE]: "123" is fcf.NUMBER :`, fcf.isNature("123", fcf.NUMBER, false));
console.log(`[SOFT_MODE: TRUE]: "2023-02-15T22:54:55.105Z" is fcf.DATE :`, fcf.isNature("2023-02-15T22:54:55.105Z", fcf.DATE, true));
console.log(`[SOFT_MODE: FALSE]: "2023-02-15T22:54:55.105Z" is fcf.DATE :`, fcf.isNature("2023-02-15T22:54:55.105Z", fcf.DATE, false));
Output:
[SOFT_MODE: TRUE]: "123" is fcf.NUMBER : true
[SOFT_MODE: TRUE]: "" is fcf.NUMBER : false
[SOFT_MODE: FALSE]: "123" is fcf.NUMBER : false
[SOFT_MODE: TRUE]: "2023-02-15T22:54:55.105Z" is fcf.DATE : true
[SOFT_MODE: FALSE]: "2023-02-15T22:54:55.105Z" is fcf.DATE : false