Comparing version 2.0.0 to 2.1.0
{ | ||
"index.js": { | ||
"bundled": 39193, | ||
"minified": 17023, | ||
"gzipped": 4692 | ||
"bundled": 39778, | ||
"minified": 17298, | ||
"gzipped": 4767 | ||
}, | ||
"index.mjs": { | ||
"bundled": 38608, | ||
"minified": 16506, | ||
"gzipped": 4565, | ||
"bundled": 39178, | ||
"minified": 16768, | ||
"gzipped": 4637, | ||
"treeshaked": { | ||
@@ -12,0 +12,0 @@ "rollup": { |
@@ -12,2 +12,3 @@ export { AsyncContract } from './asynccontract'; | ||
export { Dictionary } from './types/dictionary'; | ||
export { Enum } from './types/Enum'; | ||
export { Function } from './types/function'; | ||
@@ -14,0 +15,0 @@ export { InstanceOf } from './types/instanceof'; |
@@ -525,2 +525,22 @@ 'use strict'; | ||
function Enum(name, e) { | ||
const values = Object.values(e); | ||
const enumValues = new Set(values.some(v => typeof v === 'number') ? values.filter(v => typeof v === 'number') : values); | ||
return create(value => { | ||
if (enumValues.has(value)) { | ||
return { success: true, value: value }; | ||
} | ||
else { | ||
return { | ||
success: false, | ||
message: `Expected ${name}, but was '${value}'`, | ||
}; | ||
} | ||
}, { | ||
tag: 'enum', | ||
enumObject: e, | ||
show: () => name, | ||
}); | ||
} | ||
/** | ||
@@ -1101,2 +1121,3 @@ * Construct a runtype for functions. | ||
exports.Dictionary = Dictionary; | ||
exports.Enum = Enum; | ||
exports.Function = Function; | ||
@@ -1103,0 +1124,0 @@ exports.Guard = Guard; |
{ | ||
"name": "funtypes", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Runtime validation for static types", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -14,2 +14,3 @@ export { AsyncContract } from './asynccontract'; | ||
export { Dictionary } from './types/dictionary'; | ||
export { Enum } from './types/Enum'; | ||
export { Function } from './types/function'; | ||
@@ -16,0 +17,0 @@ export { InstanceOf } from './types/instanceof'; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
261030
93
6975
1