Comparing version 2.2.3 to 2.4.3
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _core = require('../core'); | ||
@@ -21,105 +23,114 @@ | ||
/** | ||
* Checks if the given arrays have the same content. | ||
* @param {!Array<*>} arr1 | ||
* @param {!Array<*>} arr2 | ||
* @return {boolean} | ||
*/ | ||
array.equal = function equal(arr1, arr2) { | ||
if (arr1.length !== arr2.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < arr1.length; i++) { | ||
if (arr1[i] !== arr2[i]) { | ||
_createClass(array, null, [{ | ||
key: 'equal', | ||
/** | ||
* Checks if the given arrays have the same content. | ||
* @param {!Array<*>} arr1 | ||
* @param {!Array<*>} arr2 | ||
* @return {boolean} | ||
*/ | ||
value: function equal(arr1, arr2) { | ||
if (arr1.length !== arr2.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < arr1.length; i++) { | ||
if (arr1[i] !== arr2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true; | ||
}; | ||
/** | ||
* Returns the first value in the given array that isn't undefined. | ||
* @param {!Array} arr | ||
* @return {*} | ||
*/ | ||
/** | ||
* Returns the first value in the given array that isn't undefined. | ||
* @param {!Array} arr | ||
* @return {*} | ||
*/ | ||
array.firstDefinedValue = function firstDefinedValue(arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (arr[i] !== undefined) { | ||
return arr[i]; | ||
}, { | ||
key: 'firstDefinedValue', | ||
value: function firstDefinedValue(arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (arr[i] !== undefined) { | ||
return arr[i]; | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Transforms the input nested array to become flat. | ||
* @param {Array.<*|Array.<*>>} arr Nested array to flatten. | ||
* @param {Array.<*>} opt_output Optional output array. | ||
* @return {Array.<*>} Flat array. | ||
*/ | ||
/** | ||
* Transforms the input nested array to become flat. | ||
* @param {Array.<*|Array.<*>>} arr Nested array to flatten. | ||
* @param {Array.<*>} opt_output Optional output array. | ||
* @return {Array.<*>} Flat array. | ||
*/ | ||
array.flatten = function flatten(arr, opt_output) { | ||
var output = opt_output || []; | ||
for (var i = 0; i < arr.length; i++) { | ||
if (Array.isArray(arr[i])) { | ||
array.flatten(arr[i], output); | ||
} else { | ||
output.push(arr[i]); | ||
}, { | ||
key: 'flatten', | ||
value: function flatten(arr, opt_output) { | ||
var output = opt_output || []; | ||
for (var i = 0; i < arr.length; i++) { | ||
if (Array.isArray(arr[i])) { | ||
array.flatten(arr[i], output); | ||
} else { | ||
output.push(arr[i]); | ||
} | ||
} | ||
return output; | ||
} | ||
return output; | ||
}; | ||
/** | ||
* Removes the first occurrence of a particular value from an array. | ||
* @param {Array.<T>} arr Array from which to remove value. | ||
* @param {T} obj Object to remove. | ||
* @return {boolean} True if an element was removed. | ||
* @template T | ||
*/ | ||
/** | ||
* Removes the first occurrence of a particular value from an array. | ||
* @param {Array.<T>} arr Array from which to remove value. | ||
* @param {T} obj Object to remove. | ||
* @return {boolean} True if an element was removed. | ||
* @template T | ||
*/ | ||
array.remove = function remove(arr, obj) { | ||
var i = arr.indexOf(obj); | ||
var rv; | ||
if (rv = i >= 0) { | ||
array.removeAt(arr, i); | ||
}, { | ||
key: 'remove', | ||
value: function remove(arr, obj) { | ||
var i = arr.indexOf(obj); | ||
var rv; | ||
if (rv = i >= 0) { | ||
array.removeAt(arr, i); | ||
} | ||
return rv; | ||
} | ||
return rv; | ||
}; | ||
/** | ||
* Removes from an array the element at index i | ||
* @param {Array} arr Array or array like object from which to remove value. | ||
* @param {number} i The index to remove. | ||
* @return {boolean} True if an element was removed. | ||
*/ | ||
/** | ||
* Removes from an array the element at index i | ||
* @param {Array} arr Array or array like object from which to remove value. | ||
* @param {number} i The index to remove. | ||
* @return {boolean} True if an element was removed. | ||
*/ | ||
}, { | ||
key: 'removeAt', | ||
value: function removeAt(arr, i) { | ||
return Array.prototype.splice.call(arr, i, 1).length === 1; | ||
} | ||
array.removeAt = function removeAt(arr, i) { | ||
return Array.prototype.splice.call(arr, i, 1).length === 1; | ||
}; | ||
/** | ||
* Slices the given array, just like Array.prototype.slice, but this | ||
* is faster and working on all array-like objects (like arguments). | ||
* @param {!Object} arr Array-like object to slice. | ||
* @param {number} start The index that should start the slice. | ||
* @param {number=} opt_end The index where the slice should end, not | ||
* included in the final array. If not given, all elements after the | ||
* start index will be included. | ||
* @return {!Array} | ||
*/ | ||
/** | ||
* Slices the given array, just like Array.prototype.slice, but this | ||
* is faster and working on all array-like objects (like arguments). | ||
* @param {!Object} arr Array-like object to slice. | ||
* @param {number} start The index that should start the slice. | ||
* @param {number=} opt_end The index where the slice should end, not | ||
* included in the final array. If not given, all elements after the | ||
* start index will be included. | ||
* @return {!Array} | ||
*/ | ||
array.slice = function slice(arr, start, opt_end) { | ||
var sliced = []; | ||
var end = _core2.default.isDef(opt_end) ? opt_end : arr.length; | ||
for (var i = start; i < end; i++) { | ||
sliced.push(arr[i]); | ||
}, { | ||
key: 'slice', | ||
value: function slice(arr, start, opt_end) { | ||
var sliced = []; | ||
var end = _core2.default.isDef(opt_end) ? opt_end : arr.length; | ||
for (var i = start; i < end; i++) { | ||
sliced.push(arr[i]); | ||
} | ||
return sliced; | ||
} | ||
return sliced; | ||
}; | ||
}]); | ||
@@ -126,0 +137,0 @@ return array; |
448
lib/core.js
@@ -14,2 +14,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -22,258 +24,280 @@ | ||
/** | ||
* When defining a class Foo with an abstract method bar(), you can do: | ||
* Foo.prototype.bar = core.abstractMethod | ||
* | ||
* Now if a subclass of Foo fails to override bar(), an error will be thrown | ||
* when bar() is invoked. | ||
* | ||
* @type {!Function} | ||
* @throws {Error} when invoked to indicate the method should be overridden. | ||
*/ | ||
core.abstractMethod = function abstractMethod() { | ||
throw Error('Unimplemented abstract method'); | ||
}; | ||
_createClass(core, null, [{ | ||
key: 'abstractMethod', | ||
/** | ||
* Loops constructor super classes collecting its properties values. If | ||
* property is not available on the super class `undefined` will be | ||
* collected as value for the class hierarchy position. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @return {Array.<*>} Array of collected values. | ||
* TODO(*): Rethink superclass loop. | ||
*/ | ||
/** | ||
* When defining a class Foo with an abstract method bar(), you can do: | ||
* Foo.prototype.bar = core.abstractMethod | ||
* | ||
* Now if a subclass of Foo fails to override bar(), an error will be thrown | ||
* when bar() is invoked. | ||
* | ||
* @type {!Function} | ||
* @throws {Error} when invoked to indicate the method should be overridden. | ||
*/ | ||
value: function abstractMethod() { | ||
throw Error('Unimplemented abstract method'); | ||
} | ||
/** | ||
* Loops constructor super classes collecting its properties values. If | ||
* property is not available on the super class `undefined` will be | ||
* collected as value for the class hierarchy position. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @return {Array.<*>} Array of collected values. | ||
* TODO(*): Rethink superclass loop. | ||
*/ | ||
core.collectSuperClassesProperty = function collectSuperClassesProperty(constructor, propertyName) { | ||
var propertyValues = [constructor[propertyName]]; | ||
while (constructor.__proto__ && !constructor.__proto__.isPrototypeOf(Function)) { | ||
constructor = constructor.__proto__; | ||
propertyValues.push(constructor[propertyName]); | ||
}, { | ||
key: 'collectSuperClassesProperty', | ||
value: function collectSuperClassesProperty(constructor, propertyName) { | ||
var propertyValues = [constructor[propertyName]]; | ||
while (constructor.__proto__ && !constructor.__proto__.isPrototypeOf(Function)) { | ||
constructor = constructor.__proto__; | ||
propertyValues.push(constructor[propertyName]); | ||
} | ||
return propertyValues; | ||
} | ||
return propertyValues; | ||
}; | ||
/** | ||
* Gets the name of the given function. If the current browser doesn't | ||
* support the `name` property, this will calculate it from the function's | ||
* content string. | ||
* @param {!function()} fn | ||
* @return {string} | ||
*/ | ||
/** | ||
* Gets the name of the given function. If the current browser doesn't | ||
* support the `name` property, this will calculate it from the function's | ||
* content string. | ||
* @param {!function()} fn | ||
* @return {string} | ||
*/ | ||
core.getFunctionName = function getFunctionName(fn) { | ||
if (!fn.name) { | ||
var str = fn.toString(); | ||
fn.name = str.substring(9, str.indexOf('(')); | ||
}, { | ||
key: 'getFunctionName', | ||
value: function getFunctionName(fn) { | ||
if (!fn.name) { | ||
var str = fn.toString(); | ||
fn.name = str.substring(9, str.indexOf('(')); | ||
} | ||
return fn.name; | ||
} | ||
return fn.name; | ||
}; | ||
/** | ||
* Gets an unique id. If `opt_object` argument is passed, the object is | ||
* mutated with an unique id. Consecutive calls with the same object | ||
* reference won't mutate the object again, instead the current object uid | ||
* returns. See {@link core.UID_PROPERTY}. | ||
* @param {Object=} opt_object Optional object to be mutated with the uid. If | ||
* not specified this method only returns the uid. | ||
* @param {boolean=} opt_noInheritance Optional flag indicating if this | ||
* object's uid property can be inherited from parents or not. | ||
* @throws {Error} when invoked to indicate the method should be overridden. | ||
*/ | ||
/** | ||
* Gets an unique id. If `opt_object` argument is passed, the object is | ||
* mutated with an unique id. Consecutive calls with the same object | ||
* reference won't mutate the object again, instead the current object uid | ||
* returns. See {@link core.UID_PROPERTY}. | ||
* @param {Object=} opt_object Optional object to be mutated with the uid. If | ||
* not specified this method only returns the uid. | ||
* @param {boolean=} opt_noInheritance Optional flag indicating if this | ||
* object's uid property can be inherited from parents or not. | ||
* @throws {Error} when invoked to indicate the method should be overridden. | ||
*/ | ||
core.getUid = function getUid(opt_object, opt_noInheritance) { | ||
if (opt_object) { | ||
var id = opt_object[core.UID_PROPERTY]; | ||
if (opt_noInheritance && !opt_object.hasOwnProperty(core.UID_PROPERTY)) { | ||
id = null; | ||
}, { | ||
key: 'getUid', | ||
value: function getUid(opt_object, opt_noInheritance) { | ||
if (opt_object) { | ||
var id = opt_object[core.UID_PROPERTY]; | ||
if (opt_noInheritance && !opt_object.hasOwnProperty(core.UID_PROPERTY)) { | ||
id = null; | ||
} | ||
return id || (opt_object[core.UID_PROPERTY] = core.uniqueIdCounter_++); | ||
} | ||
return id || (opt_object[core.UID_PROPERTY] = core.uniqueIdCounter_++); | ||
return core.uniqueIdCounter_++; | ||
} | ||
return core.uniqueIdCounter_++; | ||
}; | ||
/** | ||
* The identity function. Returns its first argument. | ||
* @param {*=} opt_returnValue The single value that will be returned. | ||
* @return {?} The first argument. | ||
*/ | ||
/** | ||
* The identity function. Returns its first argument. | ||
* @param {*=} opt_returnValue The single value that will be returned. | ||
* @return {?} The first argument. | ||
*/ | ||
}, { | ||
key: 'identityFunction', | ||
value: function identityFunction(opt_returnValue) { | ||
return opt_returnValue; | ||
} | ||
core.identityFunction = function identityFunction(opt_returnValue) { | ||
return opt_returnValue; | ||
}; | ||
/** | ||
* Returns true if the specified value is a boolean. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is boolean. | ||
*/ | ||
/** | ||
* Returns true if the specified value is a boolean. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is boolean. | ||
*/ | ||
}, { | ||
key: 'isBoolean', | ||
value: function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
} | ||
/** | ||
* Returns true if the specified value is not undefined. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is defined. | ||
*/ | ||
core.isBoolean = function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
}; | ||
}, { | ||
key: 'isDef', | ||
value: function isDef(val) { | ||
return val !== undefined; | ||
} | ||
/** | ||
* Returns true if the specified value is not undefined. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is defined. | ||
*/ | ||
/** | ||
* Returns true if value is not undefined or null. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isDefAndNotNull', | ||
value: function isDefAndNotNull(val) { | ||
return core.isDef(val) && !core.isNull(val); | ||
} | ||
core.isDef = function isDef(val) { | ||
return val !== undefined; | ||
}; | ||
/** | ||
* Returns true if value is a document. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
/** | ||
* Returns true if value is not undefined or null. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isDocument', | ||
value: function isDocument(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val.nodeType === 9; | ||
} | ||
/** | ||
* Returns true if value is a dom element. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
core.isDefAndNotNull = function isDefAndNotNull(val) { | ||
return core.isDef(val) && !core.isNull(val); | ||
}; | ||
}, { | ||
key: 'isElement', | ||
value: function isElement(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val.nodeType === 1; | ||
} | ||
/** | ||
* Returns true if value is a document. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
/** | ||
* Returns true if the specified value is a function. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is a function. | ||
*/ | ||
}, { | ||
key: 'isFunction', | ||
value: function isFunction(val) { | ||
return typeof val === 'function'; | ||
} | ||
core.isDocument = function isDocument(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val.nodeType === 9; | ||
}; | ||
/** | ||
* Returns true if value is null. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
/** | ||
* Returns true if value is a dom element. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isNull', | ||
value: function isNull(val) { | ||
return val === null; | ||
} | ||
/** | ||
* Returns true if the specified value is a number. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is a number. | ||
*/ | ||
core.isElement = function isElement(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val.nodeType === 1; | ||
}; | ||
}, { | ||
key: 'isNumber', | ||
value: function isNumber(val) { | ||
return typeof val === 'number'; | ||
} | ||
/** | ||
* Returns true if the specified value is a function. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is a function. | ||
*/ | ||
/** | ||
* Returns true if value is a window. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isWindow', | ||
value: function isWindow(val) { | ||
return val !== null && val === val.window; | ||
} | ||
core.isFunction = function isFunction(val) { | ||
return typeof val === 'function'; | ||
}; | ||
/** | ||
* Returns true if the specified value is an object. This includes arrays | ||
* and functions. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is an object. | ||
*/ | ||
/** | ||
* Returns true if value is null. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isObject', | ||
value: function isObject(val) { | ||
var type = typeof val === 'undefined' ? 'undefined' : _typeof(val); | ||
return type === 'object' && val !== null || type === 'function'; | ||
} | ||
/** | ||
* Returns true if value is a Promise. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
core.isNull = function isNull(val) { | ||
return val === null; | ||
}; | ||
}, { | ||
key: 'isPromise', | ||
value: function isPromise(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && typeof val.then === 'function'; | ||
} | ||
/** | ||
* Returns true if the specified value is a number. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is a number. | ||
*/ | ||
/** | ||
* Returns true if value is a string. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isString', | ||
value: function isString(val) { | ||
return typeof val === 'string' || val instanceof String; | ||
} | ||
core.isNumber = function isNumber(val) { | ||
return typeof val === 'number'; | ||
}; | ||
/** | ||
* Merges the values of a static property a class with the values of that | ||
* property for all its super classes, and stores it as a new static | ||
* property of that class. If the static property already existed, it won't | ||
* be recalculated. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives an array filled | ||
* with the values of the property for the current class and all its super classes. | ||
* Should return the merged value to be stored on the current class. | ||
* @return {boolean} Returns true if merge happens, false otherwise. | ||
*/ | ||
/** | ||
* Returns true if value is a window. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'mergeSuperClassesProperty', | ||
value: function mergeSuperClassesProperty(constructor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (constructor.hasOwnProperty(mergedName)) { | ||
return false; | ||
} | ||
core.isWindow = function isWindow(val) { | ||
return val !== null && val === val.window; | ||
}; | ||
/** | ||
* Returns true if the specified value is an object. This includes arrays | ||
* and functions. | ||
* @param {?} val Variable to test. | ||
* @return {boolean} Whether variable is an object. | ||
*/ | ||
core.isObject = function isObject(val) { | ||
var type = typeof val === 'undefined' ? 'undefined' : _typeof(val); | ||
return type === 'object' && val !== null || type === 'function'; | ||
}; | ||
/** | ||
* Returns true if value is a Promise. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
core.isPromise = function isPromise(val) { | ||
return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && typeof val.then === 'function'; | ||
}; | ||
/** | ||
* Returns true if value is a string. | ||
* @param {*} val | ||
* @return {boolean} | ||
*/ | ||
core.isString = function isString(val) { | ||
return typeof val === 'string' || val instanceof String; | ||
}; | ||
/** | ||
* Merges the values of a static property a class with the values of that | ||
* property for all its super classes, and stores it as a new static | ||
* property of that class. If the static property already existed, it won't | ||
* be recalculated. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives an array filled | ||
* with the values of the property for the current class and all its super classes. | ||
* Should return the merged value to be stored on the current class. | ||
* @return {boolean} Returns true if merge happens, false otherwise. | ||
*/ | ||
core.mergeSuperClassesProperty = function mergeSuperClassesProperty(constructor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (constructor.hasOwnProperty(mergedName)) { | ||
return false; | ||
var merged = core.collectSuperClassesProperty(constructor, propertyName); | ||
if (opt_mergeFn) { | ||
merged = opt_mergeFn(merged); | ||
} | ||
constructor[mergedName] = merged; | ||
return true; | ||
} | ||
var merged = core.collectSuperClassesProperty(constructor, propertyName); | ||
if (opt_mergeFn) { | ||
merged = opt_mergeFn(merged); | ||
} | ||
constructor[mergedName] = merged; | ||
return true; | ||
}; | ||
/** | ||
* Null function used for default values of callbacks, etc. | ||
* @return {void} Nothing. | ||
*/ | ||
/** | ||
* Null function used for default values of callbacks, etc. | ||
* @return {void} Nothing. | ||
*/ | ||
}, { | ||
key: 'nullFunction', | ||
value: function nullFunction() {} | ||
}]); | ||
core.nullFunction = function nullFunction() {}; | ||
return core; | ||
@@ -280,0 +304,0 @@ }(); |
@@ -15,2 +15,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -35,28 +37,33 @@ | ||
Disposable.prototype.dispose = function dispose() { | ||
if (!this.disposed_) { | ||
this.disposeInternal(); | ||
this.disposed_ = true; | ||
_createClass(Disposable, [{ | ||
key: 'dispose', | ||
value: function dispose() { | ||
if (!this.disposed_) { | ||
this.disposeInternal(); | ||
this.disposed_ = true; | ||
} | ||
} | ||
}; | ||
/** | ||
* Subclasses should override this method to implement any specific | ||
* disposing logic (like clearing references and calling `dispose` on other | ||
* disposables). | ||
*/ | ||
/** | ||
* Subclasses should override this method to implement any specific | ||
* disposing logic (like clearing references and calling `dispose` on other | ||
* disposables). | ||
*/ | ||
}, { | ||
key: 'disposeInternal', | ||
value: function disposeInternal() {} | ||
Disposable.prototype.disposeInternal = function disposeInternal() {}; | ||
/** | ||
* Checks if this instance has already been disposed. | ||
* @return {boolean} | ||
*/ | ||
/** | ||
* Checks if this instance has already been disposed. | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'isDisposed', | ||
value: function isDisposed() { | ||
return this.disposed_; | ||
} | ||
}]); | ||
Disposable.prototype.isDisposed = function isDisposed() { | ||
return this.disposed_; | ||
}; | ||
return Disposable; | ||
@@ -63,0 +70,0 @@ }(); |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -15,79 +17,86 @@ | ||
/** | ||
* Copies all the members of a source object to a target object. | ||
* @param {Object} target Target object. | ||
* @param {...Object} var_args The objects from which values will be copied. | ||
* @return {Object} Returns the target object reference. | ||
*/ | ||
object.mixin = function mixin(target) { | ||
var key, source; | ||
for (var i = 1; i < arguments.length; i++) { | ||
source = arguments[i]; | ||
for (key in source) { | ||
target[key] = source[key]; | ||
_createClass(object, null, [{ | ||
key: 'mixin', | ||
/** | ||
* Copies all the members of a source object to a target object. | ||
* @param {Object} target Target object. | ||
* @param {...Object} var_args The objects from which values will be copied. | ||
* @return {Object} Returns the target object reference. | ||
*/ | ||
value: function mixin(target) { | ||
var key, source; | ||
for (var i = 1; i < arguments.length; i++) { | ||
source = arguments[i]; | ||
for (key in source) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
return target; | ||
}; | ||
/** | ||
* Returns an object based on its fully qualified external name. | ||
* @param {string} name The fully qualified name. | ||
* @param {object=} opt_obj The object within which to look; default is | ||
* <code>window</code>. | ||
* @return {?} The value (object or primitive) or, if not found, undefined. | ||
*/ | ||
/** | ||
* Returns an object based on its fully qualified external name. | ||
* @param {string} name The fully qualified name. | ||
* @param {object=} opt_obj The object within which to look; default is | ||
* <code>window</code>. | ||
* @return {?} The value (object or primitive) or, if not found, undefined. | ||
*/ | ||
}, { | ||
key: 'getObjectByName', | ||
value: function getObjectByName(name, opt_obj) { | ||
var scope = opt_obj || window; | ||
var parts = name.split('.'); | ||
return parts.reduce(function (part, key) { | ||
return part[key]; | ||
}, scope); | ||
} | ||
object.getObjectByName = function getObjectByName(name, opt_obj) { | ||
var scope = opt_obj || window; | ||
var parts = name.split('.'); | ||
return parts.reduce(function (part, key) { | ||
return part[key]; | ||
}, scope); | ||
}; | ||
/** | ||
* Returns a new object with the same keys as the given one, but with | ||
* their values set to the return values of the specified function. | ||
* @param {!Object} obj | ||
* @param {!function(string, *)} fn | ||
* @return {!Object} | ||
*/ | ||
/** | ||
* Returns a new object with the same keys as the given one, but with | ||
* their values set to the return values of the specified function. | ||
* @param {!Object} obj | ||
* @param {!function(string, *)} fn | ||
* @return {!Object} | ||
*/ | ||
object.map = function map(obj, fn) { | ||
var mappedObj = {}; | ||
var keys = Object.keys(obj); | ||
for (var i = 0; i < keys.length; i++) { | ||
mappedObj[keys[i]] = fn(keys[i], obj[keys[i]]); | ||
}, { | ||
key: 'map', | ||
value: function map(obj, fn) { | ||
var mappedObj = {}; | ||
var keys = Object.keys(obj); | ||
for (var i = 0; i < keys.length; i++) { | ||
mappedObj[keys[i]] = fn(keys[i], obj[keys[i]]); | ||
} | ||
return mappedObj; | ||
} | ||
return mappedObj; | ||
}; | ||
/** | ||
* Checks if the two given objects are equal. This is done via a shallow | ||
* check, including only the keys directly contained by the 2 objects. | ||
* @return {boolean} | ||
*/ | ||
/** | ||
* Checks if the two given objects are equal. This is done via a shallow | ||
* check, including only the keys directly contained by the 2 objects. | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: 'shallowEqual', | ||
value: function shallowEqual(obj1, obj2) { | ||
if (obj1 === obj2) { | ||
return true; | ||
} | ||
object.shallowEqual = function shallowEqual(obj1, obj2) { | ||
if (obj1 === obj2) { | ||
return true; | ||
} | ||
var keys1 = Object.keys(obj1); | ||
var keys2 = Object.keys(obj2); | ||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < keys1.length; i++) { | ||
if (obj1[keys1[i]] !== obj2[keys1[i]]) { | ||
var keys1 = Object.keys(obj1); | ||
var keys2 = Object.keys(obj2); | ||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < keys1.length; i++) { | ||
if (obj1[keys1[i]] !== obj2[keys1[i]]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true; | ||
}; | ||
}]); | ||
@@ -94,0 +103,0 @@ return object; |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -15,71 +17,79 @@ | ||
/** | ||
* Removes the breaking spaces from the left and right of the string and | ||
* collapses the sequences of breaking spaces in the middle into single spaces. | ||
* The original and the result strings render the same way in HTML. | ||
* @param {string} str A string in which to collapse spaces. | ||
* @return {string} Copy of the string with normalized breaking spaces. | ||
*/ | ||
string.collapseBreakingSpaces = function collapseBreakingSpaces(str) { | ||
return str.replace(/[\t\r\n ]+/g, ' ').replace(/^[\t\r\n ]+|[\t\r\n ]+$/g, ''); | ||
}; | ||
_createClass(string, null, [{ | ||
key: 'collapseBreakingSpaces', | ||
/** | ||
* Escapes characters in the string that are not safe to use in a RegExp. | ||
* @param {*} str The string to escape. If not a string, it will be casted | ||
* to one. | ||
* @return {string} A RegExp safe, escaped copy of {@code s}. | ||
*/ | ||
/** | ||
* Removes the breaking spaces from the left and right of the string and | ||
* collapses the sequences of breaking spaces in the middle into single spaces. | ||
* The original and the result strings render the same way in HTML. | ||
* @param {string} str A string in which to collapse spaces. | ||
* @return {string} Copy of the string with normalized breaking spaces. | ||
*/ | ||
value: function collapseBreakingSpaces(str) { | ||
return str.replace(/[\t\r\n ]+/g, ' ').replace(/^[\t\r\n ]+|[\t\r\n ]+$/g, ''); | ||
} | ||
/** | ||
* Escapes characters in the string that are not safe to use in a RegExp. | ||
* @param {*} str The string to escape. If not a string, it will be casted | ||
* to one. | ||
* @return {string} A RegExp safe, escaped copy of {@code s}. | ||
*/ | ||
string.escapeRegex = function escapeRegex(str) { | ||
return String(str).replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').replace(/\x08/g, '\\x08'); | ||
}; | ||
}, { | ||
key: 'escapeRegex', | ||
value: function escapeRegex(str) { | ||
return String(str).replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').replace(/\x08/g, '\\x08'); | ||
} | ||
/** | ||
* Returns a string with at least 64-bits of randomness. | ||
* @return {string} A random string, e.g. sn1s7vb4gcic. | ||
*/ | ||
/** | ||
* Returns a string with at least 64-bits of randomness. | ||
* @return {string} A random string, e.g. sn1s7vb4gcic. | ||
*/ | ||
}, { | ||
key: 'getRandomString', | ||
value: function getRandomString() { | ||
var x = 2147483648; | ||
return Math.floor(Math.random() * x).toString(36) + Math.abs(Math.floor(Math.random() * x) ^ Date.now()).toString(36); | ||
} | ||
string.getRandomString = function getRandomString() { | ||
var x = 2147483648; | ||
return Math.floor(Math.random() * x).toString(36) + Math.abs(Math.floor(Math.random() * x) ^ Date.now()).toString(36); | ||
}; | ||
/** | ||
* Calculates the hashcode for a string. The hashcode value is computed by | ||
* the sum algorithm: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]. A nice | ||
* property of using 31 prime is that the multiplication can be replaced by | ||
* a shift and a subtraction for better performance: 31*i == (i<<5)-i. | ||
* Modern VMs do this sort of optimization automatically. | ||
* @param {String} val Target string. | ||
* @return {Number} Returns the string hashcode. | ||
*/ | ||
/** | ||
* Calculates the hashcode for a string. The hashcode value is computed by | ||
* the sum algorithm: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]. A nice | ||
* property of using 31 prime is that the multiplication can be replaced by | ||
* a shift and a subtraction for better performance: 31*i == (i<<5)-i. | ||
* Modern VMs do this sort of optimization automatically. | ||
* @param {String} val Target string. | ||
* @return {Number} Returns the string hashcode. | ||
*/ | ||
}, { | ||
key: 'hashCode', | ||
value: function hashCode(val) { | ||
var hash = 0; | ||
for (var i = 0, len = val.length; i < len; i++) { | ||
hash = 31 * hash + val.charCodeAt(i); | ||
hash %= 0x100000000; | ||
} | ||
return hash; | ||
} | ||
/** | ||
* Replaces interval into the string with specified value, e.g. | ||
* `replaceInterval("abcde", 1, 4, "")` returns "ae". | ||
* @param {string} str The input string. | ||
* @param {Number} start Start interval position to be replaced. | ||
* @param {Number} end End interval position to be replaced. | ||
* @param {string} value The value that replaces the specified interval. | ||
* @return {string} | ||
*/ | ||
string.hashCode = function hashCode(val) { | ||
var hash = 0; | ||
for (var i = 0, len = val.length; i < len; i++) { | ||
hash = 31 * hash + val.charCodeAt(i); | ||
hash %= 0x100000000; | ||
}, { | ||
key: 'replaceInterval', | ||
value: function replaceInterval(str, start, end, value) { | ||
return str.substring(0, start) + value + str.substring(end); | ||
} | ||
return hash; | ||
}; | ||
}]); | ||
/** | ||
* Replaces interval into the string with specified value, e.g. | ||
* `replaceInterval("abcde", 1, 4, "")` returns "ae". | ||
* @param {string} str The input string. | ||
* @param {Number} start Start interval position to be replaced. | ||
* @param {Number} end End interval position to be replaced. | ||
* @param {string} value The value that replaces the specified interval. | ||
* @return {string} | ||
*/ | ||
string.replaceInterval = function replaceInterval(str, start, end, value) { | ||
return str.substring(0, start) + value + str.substring(end); | ||
}; | ||
return string; | ||
@@ -86,0 +96,0 @@ }(); |
{ | ||
"name": "metal", | ||
"version": "2.2.3", | ||
"version": "2.4.3", | ||
"description": "Core functions from Metal.js, with utilities for dealing with arrays, objects and others.", | ||
@@ -18,3 +18,3 @@ "license": "BSD-3-Clause", | ||
"scripts": { | ||
"compile": "babel --presets metal -d lib/ src/", | ||
"compile": "babel --presets es2015 -d lib/ src/", | ||
"prepublish": "npm run compile" | ||
@@ -28,4 +28,4 @@ }, | ||
"babel-cli": "^6.4.5", | ||
"babel-preset-metal": "^4.0.0" | ||
"babel-preset-es2015": "^6.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54005
1568