types.js

aeq = (function (aeq) {
aeq.extend({

	/**
	 * Returns `true` if argument is null or undefined, false otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isNullOrUndefined: function(o) {
		// Using truthiness to capture both 'undefined' and 'null'
		return o == null;
	},

	/**
	 * Returns `true` if argument is a boolean (`true` or `false`),
	 * `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isBoolean: function(o) {
		return typeof o === "boolean";
	},

	/**
	 * Returns `true` if argument is a number, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isNumber: function(o) {
		return typeof o === "number";
	},

	/**
	 * Returns `true` if argument is a string, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isString: function(o) {
		return typeof o === "string";
	},

	/**
	 * Returns `true` if argument is an object, `false` otherwise. This will most
	 * likely return `true` most of the time, as most things are objects. Try to
	 * use a different function to check the type, if applicable.
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isObject: function(o) {
		return o instanceof Object;
	},

	/**
	 * Returns `true` if argument is a plain object, i.e an object created
	 * using `{}` or `new Object()`, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isPlainObject: function(obj) {

		// Not plain objects:
		// - Any object or value whose internal [[Class]] property is not "[object Object]"
		// - After Effects objects
		if ( obj === undefined || obj === null ) {
			return false;
		}
		if ( obj.toString() !== "[object Object]" ) {
			return false;
		}

		if ( obj.constructor &&
				!obj.constructor.prototype.hasOwnProperty("isPrototypeOf") ) {
			return false;
		}

		// If the function hasn't returned already, we're confident that
		// |obj| is a plain object, created by {} or constructed with new Object
		return true;
	},

	/**
	 * Returns `true` if argument is an array, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isArray: function(o) {
		return o instanceof Array;
	},

	/**
	 * Returns `true` if the passed array is empty, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Array} o The array to check
	 * @return {Boolean}
	 */
	isEmpty: function(o) {
		return o.length === undefined || o.length === 0;
	},

	/**
	 * Returns `true` if argument is a function, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isFunc: function(o) {
		return o instanceof Function;
	},

	/**
	 * ???
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isAeq: function(o) {
		return o instanceof Object && o.isAeq === true;
	},

	/**
	 * Returns `true` if argument is the Application object, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isApp: function(o) {
		return o instanceof Application;
	},

	/**
	 * Returns `true` if argument is a Folder object, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isFolder: function(o) {
		return o instanceof Folder;
	},

	/**
	 * Returns `true` if argument is a File object, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isFile: function(o) {
		return o instanceof File;
	},

	/**
	 * Returns `true` if argument is a FolderItem, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isFolderItem: function(o) {
		return o instanceof FolderItem;
	},

	/**
	 * Returns `true` if argument is a FootageItem, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isFootageItem: function(o) {
		return o instanceof FootageItem;
	},

	/**
	 * Returns `true` if argument is a Compitem, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isComp: function(o) {
		return o instanceof CompItem;
	},

	/**
	 * Returns `true` if argument is an AVLayer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isAVLayer: function(o) {
		return o instanceof AVLayer;
	},

	/**
	 * Returns `true` if argument is a ShapeLayer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isShapeLayer: function(o) {
		return o instanceof ShapeLayer;
	},

	/**
	 * Returns `true` if argument is a TextLayer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isTextLayer: function(o) {
		return o instanceof TextLayer;
	},

	/**
	 * Returns `true` if argument is a CameraLayer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isCameraLayer: function(o) {
		return o instanceof CameraLayer;
	},

	/**
	 * Returns `true` if argument is a LightLayer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isLightLayer: function(o) {
		return o instanceof LightLayer;
	},

	/**
	 * Returns `true` if a layer is a precomp, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Layer} o The layer to check
	 * @return {Boolean}
	 */
	isPrecomp: function(o) {
		if (!aeq.isLayer(o)) return false;
		return aeq.isComp(o.source);
	},

	/**
	 * Returns `true` if argument is any kind of layer, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isLayer: function(o) {
		return aeq.isAVLayer(o) ||
			aeq.isShapeLayer(o) ||
			aeq.isTextLayer(o) ||
			aeq.isCamera(o) ||
			aeq.isLight(o);
	},

	/**
	 * Returns `true` if argument is a Property, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isProperty: function(o) {
		return o instanceof Property;
	},

	/**
	 * Returns `true` if argument is a PropertyGroup, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isPropertyGroup: function(o) {
		return o instanceof PropertyGroup;
	},

	/**
	 * Returns `true` if argument is a Panel object, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isPanel: function(o) {
		return o instanceof Panel;
	},

	/**
	 * Returns `true` if argument is a Window object, `false` otherwise
	 * @function
	 * @memberof aeq
	 * @param  {Any} o The value to check
	 * @return {Boolean}
	 */
	isWindow: function(o) {
		return o instanceof Window;
	},

	/**
	 * ???
	 * @function
	 * @memberof aeq
	 * @param  {Object} obj The object
	 * @return {String}
	 */
	reflect: function (obj) {
		var str = [];

		for (var m in obj) {
			if (obj.hasOwnProperty(m)) {
				str.push(obj[m].constructor.name + ' ' + m + '=' + obj[m]);
			}
		}

		return str.join();
	}
});

// Function Aliases

/**
 * @see aeq.isBoolean
 * @function
 */
aeq.isBool = aeq.isBoolean;
/**
 * @see aeq.isNumber
 * @function
 */
aeq.isNum = aeq.isNumber;
/**
 * @see aeq.isString
 * @function
 */
aeq.isStr = aeq.isString;
/**
 * @see aeq.isObject
 * @function
 */
aeq.isObj = aeq.isObject;
/**
 * @see aeq.isArray
 * @function
 */
aeq.isArr = aeq.isArray;
/**
 * @see aeq.isFunc
 * @function
 */
aeq.isFunction = aeq.isFunc;
/**
 * @see aeq.isComp
 * @function
 */
aeq.isComposition = aeq.isComp;
/**
 * @see aeq.isProperty
 * @function
 */
aeq.isProp = aeq.isProperty;
/**
 * @see aeq.isFolder
 * @function
 */
aeq.isDir = aeq.isDirectory = aeq.isFolder;
/**
 * @see aeq.isCameraLayer
 * @function
 */
aeq.isCamera = aeq.isCameraLayer;
/**
 * @see aeq.isLightLayer
 * @function
 */
aeq.isLight = aeq.isLightLayer;

return aeq;
}(aeq || {}));