@xxlabaza/object-accessor
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Overview

Build Status

ObjectAccessor - is a helper wrapper for objects, which contains methods for retrieving the object's values by keys.

Usage

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

Development

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Building

To build the project, do the following:

$> npm run build
...

Running the tests

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.

Changelog

To see what has changed in recent versions of the project, see the changelog file.

Contributing

Please read contributing file for details on my code of conduct, and the process for submitting pull requests to me.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the Apache License 2.0 License - see the license file for details

Readme

Keywords

Package Sidebar

Install

npm i @xxlabaza/object-accessor

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Unpacked Size

31.8 kB

Total Files

10

Last publish

Collaborators

  • xxlabaza