package { import flash.sampler.StackFrame; public final class Util { public static function trim(str:String, index:int, array:Array):String { if(str == null) { return ""; } return str.replace(/^\s+|\s+$/g, ""); } //Might be better making an abstract class with this method and extending my objs //Extend A with Bs properties. Properties in A will be over written with properties //in B if they exist in both. public static function extend(objA:Object, objB:Object):Object { objA = objA || {}; for(var prop:String in objB) { if(typeof(objB[prop]) === "object") { objA[prop] = extend(objA[prop], objB[prop]); } else { objA[prop] = objB[prop]; } } return objA; } //Might be better making an abstract class with this method and extending my objs public static function resolvePropertyChain(dotDelimited:String, obj:Object):* { var properties:Array = dotDelimited.split('.'); //var field:String = properties.pop(); for each(var prop:String in properties) { obj = obj.hasOwnProperty(prop) && obj[prop]; } return obj; } public static function toPropertyChains(obj:Object):Array { function chainFrom(chain:Array, obj:Object, atEnd:Function) { if(typeof(obj) === "object") { for(var prop:String in obj) { chain.push(prop); chainFrom(chain, obj[prop], atEnd); --chain.length; } } else { atEnd(chain); } } var res:Array = []; chainFrom([], obj, function(chain:Array) { res.push(chain.join(".")); }); return res; } //Might be better making an abstract class with this method and extending my objs public static function objectIsEmpty(obj:Object):Boolean { for(var s:String in obj) { return false; } return true; } public static function arrayConcatUnique(arr1:Array, arr2:Array):Array { for each (var value:* in arr2) { if (arr1.indexOf(value) == -1) arr1.push(value); } return arr1; } } }