UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

113 lines (112 loc) 2.81 kB
var guid = 0; var ArrayProto = Array.prototype; var nativeForEach = ArrayProto.forEach; var util = { genGUID: function() { return ++guid; }, relative2absolute: function(path, basePath) { if (!basePath || path.match(/^\//)) { return path; } var pathParts = path.split("/"); var basePathParts = basePath.split("/"); var item = pathParts[0]; while (item === "." || item === "..") { if (item === "..") { basePathParts.pop(); } pathParts.shift(); item = pathParts[0]; } return basePathParts.join("/") + "/" + pathParts.join("/"); }, extend: function(target, source) { if (source) { for (var name in source) { if (source.hasOwnProperty(name)) { target[name] = source[name]; } } } return target; }, defaults: function(target, source) { if (source) { for (var propName in source) { if (target[propName] === void 0) { target[propName] = source[propName]; } } } return target; }, extendWithPropList: function(target, source, propList) { if (source) { for (var i = 0; i < propList.length; i++) { var propName = propList[i]; target[propName] = source[propName]; } } return target; }, defaultsWithPropList: function(target, source, propList) { if (source) { for (var i = 0; i < propList.length; i++) { var propName = propList[i]; if (target[propName] == null) { target[propName] = source[propName]; } } } return target; }, each: function(obj, iterator, context) { if (!(obj && iterator)) { return; } if (obj.forEach && obj.forEach === nativeForEach) { obj.forEach(iterator, context); } else if (obj.length === +obj.length) { for (var i = 0, len = obj.length; i < len; i++) { iterator.call(context, obj[i], i, obj); } } else { for (var key in obj) { if (obj.hasOwnProperty(key)) { iterator.call(context, obj[key], key, obj); } } } }, isObject: function(obj) { return obj === Object(obj); }, isArray: function(obj) { return Array.isArray(obj); }, isArrayLike: function(obj) { if (!obj) { return false; } else { return obj.length === +obj.length; } }, clone: function(obj) { if (!util.isObject(obj)) { return obj; } else if (util.isArray(obj)) { return obj.slice(); } else if (util.isArrayLike(obj)) { var ret = new obj.constructor(obj.length); for (var i = 0; i < obj.length; i++) { ret[i] = obj[i]; } return ret; } else { return util.extend({}, obj); } } }; var util$1 = util; export { util$1 as default };