Package Exports
- stringtoobjectvalidator
- stringtoobjectvalidator/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stringtoobjectvalidator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Object Validator
Object Validator is a lightweight npm package that allows you to validate an object against a validation string. This library provides a simple and efficient way to check whether an object conforms to a specified set of rules.
Installation
You can easily install Object Validator using npm:
npm i stringtoobjectvalidatorUsage
To use Object Validator in your JavaScript code, you need to require it:
import { validateObjectAgainstString } from 'stringtoobjectvalidator';Validate an Object
You can use the validate function to check whether an object adheres to a validation string. Here's how to do it:
const expression = '(name === "John" && age > 18)';
const object = { name: 'John', age: 20 };
const isValid = validateObjectAgainstString(expression, object);
console.log(isValid); // Output: trueValidation String Format
The validation string should adhere to a simple format: "(name === "John" && age > 18)". You can specify multiple properties and data types by separating them with a comma.
Contributing
We welcome contributions to Object Validator! If you encounter any issues, have feature requests, or want to improve the code, please open an issue