@codeparticle/formal
Version:
A <2kb library for validating data of any kind
39 lines (37 loc) • 966 B
JavaScript
import {
createRule
} from "./chunk-DDICIM7S.mjs";
// src/rules/has-prop.ts
var hasProp = (...properties) => {
let prop = ``;
let currentObjectPath = {};
return createRule({
condition: (obj) => {
currentObjectPath = obj;
for (const property of properties) {
if (currentObjectPath.hasOwnProperty(property)) {
prop = property;
currentObjectPath = currentObjectPath[property];
} else {
return false;
}
}
return true;
},
message: (obj) => {
const keys = Object.keys(obj).toString().replace(`,`, `,
`);
return `Object containing properties ${keys} does not include ${prop}${properties.length > 1 ? ` at path ${properties.join(`.`)}` : ``}`;
}
});
};
export {
hasProp
};
/**
* @file Checks an object to make sure that it has a certain property.
* @name hasProp.js
* @author Nick Krause
* @license MIT
*/
//# sourceMappingURL=chunk-ITFQUO4X.mjs.map