enumerated-type
Advanced tools
Comparing version 0.3.2 to 0.4.0
24
index.js
@@ -242,14 +242,26 @@ // 'use strict'; | ||
Enum.prototype.forEach = function forEach(callback, defaultValue) { | ||
return forEachBreak.forEach.call(this.values, callback, defaultValue) | ||
Enum.prototype.forEach = function forEach(callback, thisArg, defaultValue) { | ||
return forEachBreak.forEach.call(this.values, callback, thisArg, defaultValue) | ||
}; | ||
Enum.prototype.map = function map(callback) { | ||
return forEachBreak.map.call(this.values, callback) | ||
Enum.prototype.map = function map(callback, thisArg) { | ||
return forEachBreak.map.call(this.values, callback, thisArg) | ||
}; | ||
Enum.prototype.filter = function filter(callback) { | ||
return forEachBreak.filter.call(this.values, callback) | ||
Enum.prototype.filter = function filter(callback, thisArg) { | ||
return forEachBreak.filter.call(this.values, callback, thisArg) | ||
}; | ||
Enum.prototype.forEachRight = function forEachRight(callback, thisArg, defaultValue) { | ||
return forEachBreak.forEachRight.call(this.values, callback, thisArg, defaultValue) | ||
}; | ||
Enum.prototype.mapRight = function mapRight(callback, thisArg) { | ||
return forEachBreak.mapRight.call(this.values, callback, thisArg) | ||
}; | ||
Enum.prototype.filterRight = function filterRight(callback, thisArg) { | ||
return forEachBreak.filterRight.call(this.values, callback, thisArg) | ||
}; | ||
Enum.prototype[Symbol.iterator] = function iterator() { | ||
@@ -256,0 +268,0 @@ const enumValues = this.values; |
{ | ||
"name": "enumerated-type", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "enum type for javascript", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"lodash.isstring": "^4.0.1", | ||
"for-each-break": "^0.1.0" | ||
"for-each-break": "^0.2.0" | ||
}, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
@@ -110,26 +110,21 @@ # enumerated-type | ||
<!--@formatter:off--> | ||
* `.name` : name of the enum passed to constructor | ||
* `.values` : array of enum values sorted by `keyPropName` if provided or by value if non-object | ||
values. | ||
* `.keys` : array of enum key properties if keyPropName was passed to constructor, otherwise | ||
array of enum values which were not objects | ||
* `[keyPropName](key)`: function taking key and returning enum value whose `keyPropName` equals | ||
the value of the key. Only defined if `keyPropName` is defined and is a string. Convenience | ||
method for converting key property value to an enum value. | ||
* `.value(key)`: function taking the a value and returning enum value whose value equals the | ||
key. Only defined if `keyPropName` is not defined. | ||
* `.forEach`: function (callback, defaultResult) taking a callback function(value, index, | ||
values) and optional default result if callback does not return `BREAK(result)` or | ||
`RETURN(result)`. see [for-each-break] | ||
* `.map`: function (callback) taking a callback function(value, index, values) and returning | ||
array of values returned my callback, unless callback returns `BREAK(result)` or | ||
`RETURN(result)`. see [for-each-break] | ||
* `.filter`: function (callback) taking a callback function(value, index, values) and returning | ||
array of values for which callback result tested true, unless callback returns `BREAK(result)` | ||
or `RETURN(result)`. see [for-each-break] | ||
* `.values` : array of enum values sorted by `keyPropName` if provided or by value if non-object values. | ||
* `.keys` : array of enum key properties if keyPropName was passed to constructor, otherwise array of enum values which were not objects | ||
* `[keyPropName](key)`: function taking key and returning enum value whose `keyPropName` equals the value of the key. Only defined if `keyPropName` is defined and is a string. Convenience method for converting key property value to an enum value. | ||
* `.value(key)`: function taking the a value and returning enum value whose value equals the key. Only defined if `keyPropName` is not defined. | ||
* `.filter`: `function (callback, thisArg)` taking a callback `function(value, index, values)` and returning array of values for which callback result tested true, unless callback returns `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `.forEach`: `function (callback, thisArg, defaultResult)` taking a callback `function(value, index, values)` and optional default result if callback does not return `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `.map`: `function (callback, thisArg)` taking a callback `function(value, index, values)` and returning array of values returned my callback, unless callback returns `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `.filterRight`: `function (callback, thisArg, thisArg)` taking a callback `function(value, index, values)` and returning array of values for which callback result tested true, unless callback returns `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `.forEachRight`: `function (callback, thisArg, thisArg, defaultResult)` taking a callback `function(value, index, values)` and optional default result if callback does not return `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `.mapRight`: `function (callback, thisArg, thisArg)` taking a callback `function(value, index, values)` and returning array of values returned my callback, unless callback returns `BREAK(result)` or `RETURN(result)`. see [for-each-break] | ||
* `[Symbol.iterator]`: iterator over enum values | ||
* `[Symbol.hasInstance]`: handles `instanceof` and returns true when left hand side is an enum | ||
value of this enum instance. | ||
* `[Symbol.hasInstance]`: handles `instanceof` and returns true when left hand side is an enum value of this enum instance. | ||
* `.toString`: returns `[object Enum(enumName)]` | ||
<!--@formatter:on--> | ||
### Enum Value Instance Properties | ||
@@ -150,7 +145,8 @@ | ||
Functions passed in as property values for enum value properties or `commonProperties` will have | ||
`this` set to the enum value instance. Any functions which take no arguments (ie. | ||
function.length === 0) will be converted to getters of the enum value instance and should not | ||
use the function call syntax. | ||
:warning: Functions passed in as property values for enum value properties or `commonProperties` will | ||
have `this` set to the enum value instance. | ||
:warning: Any functions which take no arguments (ie. function.length === 0) will be converted to | ||
getters of the enum value instance and should not use the function call syntax. | ||
## License | ||
@@ -157,0 +153,0 @@ |
@@ -5,2 +5,3 @@ # Version History | ||
- [0.4.0](#040) | ||
- [0.3.2](#032) | ||
@@ -12,2 +13,7 @@ - [0.3.0](#030) | ||
## 0.4.0 | ||
* Add: add reverse version of functions | ||
* Change: add `thisArg` argument to match js forEach, map, filter. | ||
## 0.3.2 | ||
@@ -14,0 +20,0 @@ |
18879
242
156
+ Addedfor-each-break@0.2.6(transitive)
- Removedfor-each-break@0.1.0(transitive)
Updatedfor-each-break@^0.2.0