ts-enum-util
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -43,2 +43,3 @@ "use strict"; | ||
_this.keysByValueMap.set(value, key); | ||
// type casting necessary to bypass readonly index signature for initialization | ||
_this[index] = [key, value]; | ||
@@ -130,5 +131,8 @@ ++index; | ||
next: function () { | ||
var isDone = index >= _this.length; | ||
var result = { | ||
done: index >= _this.length, | ||
value: _this[index] && _this[index][1] | ||
done: isDone, | ||
// "as any" cast is necessary to work around this bug: | ||
// https://github.com/Microsoft/TypeScript/issues/11375 | ||
value: isDone ? undefined : _this[index][1] | ||
}; | ||
@@ -279,3 +283,3 @@ ++index; | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -375,3 +379,3 @@ return key; | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -378,0 +382,0 @@ return this.enumObj[key]; |
@@ -41,2 +41,3 @@ /** | ||
_this.keysByValueMap.set(value, key); | ||
// type casting necessary to bypass readonly index signature for initialization | ||
_this[index] = [key, value]; | ||
@@ -128,5 +129,8 @@ ++index; | ||
next: function () { | ||
var isDone = index >= _this.length; | ||
var result = { | ||
done: index >= _this.length, | ||
value: _this[index] && _this[index][1] | ||
done: isDone, | ||
// "as any" cast is necessary to work around this bug: | ||
// https://github.com/Microsoft/TypeScript/issues/11375 | ||
value: isDone ? undefined : _this[index][1] | ||
}; | ||
@@ -277,3 +281,3 @@ ++index; | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -373,3 +377,3 @@ return key; | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -376,0 +380,0 @@ return this.enumObj[key]; |
@@ -429,3 +429,3 @@ /** | ||
* @param key - An enum key. | ||
* @param enumObj - The enum-like object that the key/value entrie belongs to. | ||
* @param enumWrapper - The EnumWrapper instance being iterated.. | ||
* @param index - The index of the enum entry, based on sorted order of keys. | ||
@@ -438,3 +438,3 @@ * @return A result. The significance of the result depends on the type of iteration being performed. | ||
*/ | ||
type Iteratee<R = any, V extends number | string = number | string, T extends EnumLike<V, keyof T> = any> = (this: any, value: V, key: keyof T, enumWrapper: EnumWrapper<V, T>, index: number) => R; | ||
type Iteratee<R = any, V extends number | string = number | string, T extends EnumLike<V, keyof T> = any> = (this: any, value: T[keyof T], key: keyof T, enumWrapper: EnumWrapper<V, T>, index: number) => R; | ||
} | ||
@@ -441,0 +441,0 @@ /** |
{ | ||
"name": "ts-enum-util", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "TypeScript Enum Utilities", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -439,3 +439,3 @@ [![npm version](https://img.shields.io/npm/v/ts-enum-util.svg)](https://www.npmjs.com/package/ts-enum-util) | ||
A generic type alias for a function signature to be used in iteration methods. This is compliant with the signature of an iteratee for a `Map<KeyType, EnumType>.forEach()` method, except that it has an additional `index` param at the end of the parameter list. | ||
A generic type alias for a function signature to be used in iteration methods. This is compliant with the signature of an iteratee for a `Map<KeyType, EnumType>.forEach()` method, but also has an additional `index` param at the end of the parameter list. | ||
@@ -442,0 +442,0 @@ ### EnumWrapper.prototype.size |
@@ -213,2 +213,3 @@ /** | ||
this.keysByValueMap.set(value, key); | ||
// type casting necessary to bypass readonly index signature for initialization | ||
(this as any as EnumWrapper.Entry<V, T>[])[index] = [key, value]; | ||
@@ -276,5 +277,8 @@ ++index; | ||
next: (): IteratorResult<T[keyof T]> => { | ||
const isDone = index >= this.length; | ||
const result = { | ||
done: index >= this.length, | ||
value: this[index] && this[index][1] | ||
done: isDone, | ||
// "as any" cast is necessary to work around this bug: | ||
// https://github.com/Microsoft/TypeScript/issues/11375 | ||
value: isDone ? undefined as any : this[index][1] | ||
}; | ||
@@ -305,3 +309,2 @@ | ||
const entry = this[index]; | ||
const result: IteratorResult<EnumWrapper.Entry<V, T>> = { | ||
@@ -392,5 +395,7 @@ done: isDone, | ||
public getValues(): T[keyof T][] { | ||
return Array.prototype.map.call(this, (entry: EnumWrapper.Entry<V, T>) => { | ||
return entry[1]; | ||
}); | ||
return Array.prototype.map.call(this, | ||
(entry: EnumWrapper.Entry<V, T>): T[keyof T] => { | ||
return entry[1]; | ||
} | ||
); | ||
} | ||
@@ -404,5 +409,7 @@ | ||
public getEntries(): EnumWrapper.Entry<V, T>[] { | ||
return Array.prototype.map.call(this, (entry: EnumWrapper.Entry<V, T>) => { | ||
return [entry[0], entry[1]]; | ||
}); | ||
return Array.prototype.map.call(this, | ||
(entry: EnumWrapper.Entry<V, T>): EnumWrapper.Entry<V, T> => { | ||
return [entry[0], entry[1]]; | ||
} | ||
); | ||
} | ||
@@ -476,3 +483,3 @@ | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -679,3 +686,3 @@ return key as keyof T; | ||
if (this.isKey(key)) { | ||
// type cast require to work around TypeScript bug: | ||
// type cast required to work around TypeScript bug: | ||
// https://github.com/Microsoft/TypeScript/issues/21950 | ||
@@ -704,3 +711,3 @@ return this.enumObj[key as keyof T]; | ||
* @param key - An enum key. | ||
* @param enumObj - The enum-like object that the key/value entrie belongs to. | ||
* @param enumWrapper - The EnumWrapper instance being iterated.. | ||
* @param index - The index of the enum entry, based on sorted order of keys. | ||
@@ -717,3 +724,3 @@ * @return A result. The significance of the result depends on the type of iteration being performed. | ||
T extends EnumLike<V, keyof T> = any | ||
> = (this: any, value: V, key: keyof T, enumWrapper: EnumWrapper<V, T>, index: number) => R; | ||
> = (this: any, value: T[keyof T], key: keyof T, enumWrapper: EnumWrapper<V, T>, index: number) => R; | ||
} | ||
@@ -720,0 +727,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
140275
2192