# object-accessors

> Setup truly private variables, getters, setters

Latest version **0.0.1** (published 2018-12-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-accessors
pnpm add object-accessors
yarn add object-accessors
bun add object-accessors
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-12-14 |
| First published | 2018-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Robin Fehr |
| Maintainers | robinfeh |
| Keywords | accessors, oop, getters, setters, private |

## Links

- npm: https://www.npmjs.com/package/object-accessors
- Repository: https://github.com/robinfehr/object-accessability
- Homepage: https://github.com/robinfehr/object-accessability#readme
- Issues: https://github.com/robinfehr/object-accessability/issues
- npm.io page: https://npm.io/package/object-accessors

## Recent versions

- 0.0.1 (latest) — 2018-12-14

## README

# Object-Accessor
Initially this module was developed for designing SDKs in a 
similar way you would in OOP based languages and therefore make the SDK
more maintainable. Using this module you get:

- ✅ truly private variables
- ✅ getters
- ✅ setters

to restrict the accessibility
and to make sdk's across multiple languages
more maintainble by designing them in a similar way.


### Setup
`npm install object-acessibility -s`


### Usage

```js
function Client() {

  // Add a state
  const state = (state => {
    // q can't be modified
    state.q = 2;
    // "priate" ths is really private
    state.private = 100;

    // we could add something calculated here like
    // state.calced = this.state.private / 100;
    return state;
  })({});

  // Add Getters
  const getters = state => ({
    q: () => state.q,
    value: () => state.value,
    calculatedValue: () => (state.value / state.q * state.private)
  });

  // Add Setters
  const setters = state => ({
    value: (val) => {state.value = val}
  })

  // Use the accessibility lib
  return accessability({ getters, setters, state });
}

const testClient = Client();

console.log(testClient.value);
// undefined

// Set a value
testClient.value = 500;

console.log(testClient.value);
// 500

// We can't set values without a setter
testClient.q = 200
console.log(testClient.q);
// 2

// We can't access values without a getter
console.log(testClient.private)
// undefined

```

---
_Source: https://npm.io/package/object-accessors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
