@codeparticle/formal
Version:
A <2kb library for validating data of any kind
39 lines (34 loc) • 1.08 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunkYSLAWOV5js = require('./chunk-YSLAWOV5.js');
// src/rules/has-prop.ts
var hasProp = (...properties) => {
let prop = ``;
let currentObjectPath = {};
return _chunkYSLAWOV5js.createRule.call(void 0, {
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(`.`)}` : ``}`;
}
});
};
exports.hasProp = hasProp;
/**
* @file Checks an object to make sure that it has a certain property.
* @name hasProp.js
* @author Nick Krause
* @license MIT
*/
//# sourceMappingURL=chunk-RQZFTNDF.js.map