flow-enums-runtime
Advanced tools
Comparing version 0.0.1 to 0.0.2
37
index.js
@@ -6,4 +6,2 @@ /** | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
@@ -15,10 +13,9 @@ | ||
// `Object.prototype` in its proto chain, so we must extract it here. | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
// Map from an enum object to a set of its values. | ||
const enumValuesCache = | ||
typeof WeakMap === 'function' ? new WeakMap() : new Map(); | ||
var enumValuesCache = typeof WeakMap === 'function' ? new WeakMap() : new Map(); | ||
function valuesSet(enumObject) { | ||
const enumValues = enumValuesCache.get(enumObject); | ||
var enumValues = enumValuesCache.get(enumObject); | ||
if (enumValues !== undefined) { | ||
@@ -29,4 +26,4 @@ return enumValues; | ||
// properties, and our properties aren't enumerable. | ||
const names = Object.getOwnPropertyNames(enumObject); | ||
const newEnumValues = new Set(names.map(name => enumObject[name])); | ||
var names = Object.getOwnPropertyNames(enumObject); | ||
var newEnumValues = new Set(names.map(name => enumObject[name])); | ||
enumValuesCache.set(enumObject, newEnumValues); | ||
@@ -36,6 +33,6 @@ return newEnumValues; | ||
const EnumPrototype = Object.freeze( | ||
var EnumPrototype = Object.freeze( | ||
Object.defineProperties(Object.create(null), { | ||
isValid: { | ||
value(x) { | ||
value: function (x) { | ||
return valuesSet(this).has(x); | ||
@@ -45,3 +42,3 @@ }, | ||
cast: { | ||
value(x) { | ||
value: function (x) { | ||
return this.isValid(x) ? x : undefined; | ||
@@ -51,7 +48,7 @@ }, | ||
members: { | ||
value() { | ||
value: function () { | ||
return valuesSet(this).values(); | ||
}, | ||
}, | ||
}), | ||
}) | ||
); | ||
@@ -61,4 +58,4 @@ | ||
function Enum(members) { | ||
const o = Object.create(EnumPrototype); | ||
for (const k in members) { | ||
var o = Object.create(EnumPrototype); | ||
for (var k in members) { | ||
if (hasOwnProperty.call(members, k)) { | ||
@@ -75,6 +72,6 @@ // Create non-enumerable properties. | ||
// keys and values are identical. | ||
const EnumMirroredPrototype = Object.freeze( | ||
var EnumMirroredPrototype = Object.freeze( | ||
Object.defineProperties(Object.create(null), { | ||
isValid: { | ||
value(x) { | ||
value: function (x) { | ||
if (typeof x === 'string') { | ||
@@ -90,3 +87,3 @@ return hasOwnProperty.call(this, x); | ||
members: { | ||
value() { | ||
value: function () { | ||
// We aren't using `Object.values` because that gets enumerable | ||
@@ -97,3 +94,3 @@ // properties, and our properties aren't enumerable. | ||
}, | ||
}), | ||
}) | ||
); | ||
@@ -103,3 +100,3 @@ | ||
Enum.Mirrored = function EnumMirrored(members) { | ||
const o = Object.create(EnumMirroredPrototype); | ||
var o = Object.create(EnumMirroredPrototype); | ||
for (let i = 0, len = members.length; i < len; ++i) { | ||
@@ -106,0 +103,0 @@ // Value is same as key. Also, non-enumerable. |
{ | ||
"name": "flow-enums-runtime", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Runtime to be use with the Flow Enums transform.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
9147
271