is-type
This library comes with two functions:
/** * Matches a given value to a given string type. * @param type A string which will match to a typeof call, or will match an Object's ClassName * @param value The value to match to a given type */declare ; /** * Matches a given value to a given string type. * @param type A string which will match to a typeof call, or will match an Object:IsA(type) call * @param value The value to match to a given type */declare ;
The implementations are pretty obvious:
is = function(typeStr, obj) local objType = typeof(obj); return objType == typeStr or objType == "Instance" and obj.ClassName == typeStr;end; isA = function(typeStr, obj) local objType = typeof(obj); return objType == typeStr or objType == "Instance" and obj:IsA(typeStr);end;
These are very useful for type narrowing: