4.0.17 • Published 6 years ago

@lbzg/props v4.0.17

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
6 years ago

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

4.0.17

6 years ago

4.0.16

6 years ago

4.0.15

6 years ago

4.0.14

6 years ago

4.0.13

6 years ago

4.0.12

6 years ago

4.0.11

6 years ago

4.0.10

6 years ago

4.0.9

6 years ago

4.0.8

6 years ago

4.0.7

6 years ago

4.0.6

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.2.2

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago