Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save trycf/c1edd9d7fd9ed6e1f1e4187196ded17d to your computer and use it in GitHub Desktop.

Select an option

Save trycf/c1edd9d7fd9ed6e1f1e4187196ded17d to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
public boolean function isStrictNumeric(any value) {
if (!isNumeric(arguments.value)) return false;
// 001 is not strict numeric -> serialize as string
if (arguments.value >= 1 && left(arguments.value, 1) == "0") return false;
// .111111 is not strict numeric -> serialize as string
if (left(arguments.value, 1) == ".") return false;
// +111111 is not strict numeric -> serialize as string
if (left(arguments.value, 1) == "+") return false;
return true;
}
public boolean function isInt(any value) {
return isStrictNumeric(arguments.value) && arguments.value == int(arguments.value);
}
public boolean function isDouble(any value) {
return isStrictNumeric(arguments.value) && arguments.value != int(arguments.value);
}
public boolean function isBool(any value) {
return arguments.value === true || arguments.value === false;
}
public boolean function isFunc(any value) {
return !isNull(arguments.value) && (isCustomFunction(arguments.value) || isClosure(arguments.value));
}
values = [.1 * 1, 1, 0, -1, -1.1, 1.1, 0.99999999, -0.99999999999, "YES", true, false, "false", function(a,b) {return a;}];
for (value in values) {
writeDump({
"value" : value,
"isInt" : isInt(value),
"isDouble": isDouble(value),
"isBool" : isBool(value),
"isFunc" : isFunc(value)
});
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment