CFLib.org – Common Function Library Project

TypeOf(x)

Last updated August 16, 2002

author

Jordan Clark

Version: 3 | Requires: CF5 | Library: DataManipulationLib

Description:
Enhanced typeof() function with added checking for binary, custom function, and date values.

Return Values:
Returns a string.

Example:

<cfscript>
   function foo() { return; }
   foo2 = createDate( 2002, 4, 1 );
   foo3 = Tobinary( ToBase64( "foo" ) );
</cfscript>
<cfoutput>
   #typeof( foo )#<br>
   #typeof( foo2 )#<br>
   #typeof( foo3 )#<br>
</cfoutput>

Parameters:

Name Description Required
x The data to inspect. Yes

Full UDF Source:

/**
 * Returns the type of the variable.
 * Made it cf5/mx compat with use of getFunctionList
 * 
 * @param x 	 The data to inspect. (Required)
 * @return Returns a string. 
 * @author Jordan Clark (JordanClark@Telus.net) 
 * @version 3, August 16, 2002 
 */
function TypeOf(x) {
   if(isArray(x)) return "array";
   if(isStruct(x)) return "structure";
   if(isQuery(x)) return "query";
   if(isSimpleValue(x) and isWddx(x)) return "wddx";
   if(isBinary(x)) return "binary";
   if(isCustomFunction(x)) return "custom function";
   if(isDate(x)) return "date";
   if(isNumeric(x)) return "numeric";
   if(isBoolean(x)) return "boolean";
   if( listFindNoCase( structKeyList( GetFunctionList() ), "isXMLDoc" ) AND
isXMLDoc(x)) return "xml";
   if(isSimpleValue(x)) return "string";
   return "unknown";  
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson