@st-lib/private
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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
	}
}

Readme

Keywords

Package Sidebar

Install

npm i @st-lib/private

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

3.72 kB

Total Files

5

Last publish

Collaborators

  • st-lib