This package has been deprecated

Author message:

EOL

@lbzg/props
TypeScript icon, indicating that this package has built-in type declarations

4.0.17 • Public • Published

About

Properties with getter, validated setters and hooks.

Installation & Usage

npm i @lbzg/props
const { prop } = require('@lbzg/props')
const isNumber = x => typeof x === 'number'
const double = x => x * 2

const p = prop(isNumber, 100)
p.config.hooks.on(console.log)

p.set('asdf') # false # console logs 'asdf'
p.get() # 100

p.set(2) # true # console logs 2
p.apply(double) # true # console logs 4
p.call(double) # 8
p.get() # 4

Prototype

Exports prop and safeProp functions (and interfaces IProp/ISafeProp).

prop(validator?, value?): Prop ~ get() returns T | undefined
safeProp(validator, value): Prop ~ get() returns T

Prop

get(): T | undefined ~ just T if safeProp
set(x): boolean ~ (validates and) assigns x
apply(fn): boolean ~ (validates and) assigns fn(prop)
call(fn): any ~ executes and returns fn(prop)
config: PropConfig

apply and set return true when valid input is provided

PropConfig

validator(fn?) ~ (un)set validation for set and apply methods
hooks: PropHooks

PropHooks
Hooks are triggered during set and apply if provided.

on(fn) ~ fn takes input which might become prop
success(fn) ~ fn takes input which might become prop
change(fn) ~ fn takes input which always becomes prop
fail(fn) ~ fn takes input which never becomes prop

fn :: x -> any

Package Sidebar

Install

npm i @lbzg/props

Weekly Downloads

1

Version

4.0.17

License

ISC

Unpacked Size

102 kB

Total Files

15

Last publish

Collaborators

  • lbzg