UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

39 lines (37 loc) 989 B
import { createRule } from "./chunk-DDICIM7S.mjs"; // src/rules/get-prop.ts var getProp = (...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: () => { 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) }); }; export { 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-ANQRT3MY.mjs.map