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
function Client() {
const state = (state => {
state.q = 2;
state.private = 100;
return state;
})({});
const getters = state => ({
q: () => state.q,
value: () => state.value,
calculatedValue: () => (state.value / state.q * state.private)
});
const setters = state => ({
value: (val) => {state.value = val}
})
return accessability({ getters, setters, state });
}
const testClient = Client();
console.log(testClient.value);
testClient.value = 500;
console.log(testClient.value);
testClient.q = 200
console.log(testClient.q);
console.log(testClient.private)