You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
621 B
JavaScript

'use strict';
const get = require('../get');
module.exports = function getKeysInSchemaOrder(schema, val, path) {
const schemaKeys = path != null ? Object.keys(get(schema.tree, path, {})) : Object.keys(schema.tree);
const valKeys = new Set(Object.keys(val));
let keys;
if (valKeys.size > 1) {
keys = new Set();
for (const key of schemaKeys) {
if (valKeys.has(key)) {
keys.add(key);
}
}
for (const key of valKeys) {
if (!keys.has(key)) {
keys.add(key);
}
}
keys = Array.from(keys);
} else {
keys = Array.from(valKeys);
}
return keys;
};