1.0.0 • Published 4 years ago

@st-lib/private v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Utility for creating private properties and methods.

import { createProperty, createMethod } from '@st-lib/private'

const [getProperty, setProperty] = createProperty<string>()
const [method, defineMethod] = createMethod<[string], string>()

class Class {
	constructor() {
		setProperty(this, 'init property value')
		defineMethod(this, (value) => value.toUpperCase())
	}

	publicMethod() {
		const value = getProperty(this) // thows ReferenceError if property not defined
		const preparedValue = method(this, value) // thows ReferenceError if method not defined
		return preparedValue
	}
}