ObjectAccessor
- is a helper wrapper for objects, which contains methods for retrieving the object's values by keys.
installation:
$> npm install --save @xxlabaza/object-accessor
Example:
import { ObjectAccessor } from '@xxlabaza/object-accessor'
const json = { ... };
const accessor = new ObjectAccessor(json);
accessor.getString('key1'); // => Result<string, Error>
accessor.getNumber('key2').or(42); // retrieve a number, or return 42, if undefined
accessor.getBoolean('key3.innerObjectKey').orError(); // try to get boolean from nested object or throw the Error
accessor.getObjectAccessor('key3').getBoolean('innerObjectKey').orError(); // the same as previous
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
To build the project, do the following:
$> npm run build
...
To run the project's test, do the following:
$> npm test
...
Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 1.233 s
Ran all test suites.
To see what has changed in recent versions of the project, see the changelog file.
Please read contributing file for details on my code of conduct, and the process for submitting pull requests to me.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Artem Labazin - creator and the main developer
This project is licensed under the Apache License 2.0 License - see the license file for details