UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

39 lines (34 loc) 1.1 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkYSLAWOV5js = require('./chunk-YSLAWOV5.js'); // src/rules/get-prop.ts var getProp = (...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: () => { const path = properties.join(`.`); return `Object does not include property ${path.slice(prop.length - 1)} at path .${path}`; }, transform: (obj) => properties.reduce((acc, key) => acc[key], obj) }); }; exports.getProp = getProp; /** * @file Check to see if an object has a property, then return the value of that property. * @name getProp.js * @author Nick Krause * @license MIT */ //# sourceMappingURL=chunk-2AK5GXIP.js.map