Compare commits

...

2 Commits

@ -33,7 +33,7 @@ module.exports = function hasShape(rules) {
let unexpectedPropertyErrors = asExpression(() => { let unexpectedPropertyErrors = asExpression(() => {
if (!allowExtraProperties) { if (!allowExtraProperties) {
return Object.keys(object).map((propertyName) => { return Reflect.ownKeys(object).map((propertyName) => {
if (!containsRules(rules[propertyName])) { if (!containsRules(rules[propertyName])) {
return new ValidationError(`Encountered an unexpected property '${propertyName}'`); return new ValidationError(`Encountered an unexpected property '${propertyName}'`);
} else { } else {
@ -58,8 +58,8 @@ module.exports = function hasShape(rules) {
// We need to consider the keys from the ruleset (for detecting missing required properties) *and* the keys from the actual object (for handling extraneous values). // We need to consider the keys from the ruleset (for detecting missing required properties) *and* the keys from the actual object (for handling extraneous values).
let allKeys = arrayUnion( let allKeys = arrayUnion(
Object.keys(rules), Reflect.ownKeys(rules),
Object.keys(object) Reflect.ownKeys(object)
); );
for (let key of allKeys) { for (let key of allKeys) {
@ -82,6 +82,7 @@ module.exports = function hasShape(rules) {
} }
} else { } else {
// Extraneous property // Extraneous property
// FIXME: Assign non-enumerable if the source property was non-enumerable!
newObject[key] = value; newObject[key] = value;
} }
} }

@ -6,7 +6,7 @@
"validator", "validator",
"combinator" "combinator"
], ],
"version": "0.1.7", "version": "0.1.8",
"main": "index.js", "main": "index.js",
"repository": "http://git.cryto.net/validatem/has-shape.git", "repository": "http://git.cryto.net/validatem/has-shape.git",
"author": "Sven Slootweg <admin@cryto.net>", "author": "Sven Slootweg <admin@cryto.net>",

Loading…
Cancel
Save