Skip to content
/ valuejs Public

Javascript library to store and manage numeric values. Provides value boundaries protection (max and min) as well as formatting to string.

Notifications You must be signed in to change notification settings

karolk/valuejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

value.js is a small JavaScript library to help maintain and format numeric values/ranges and format them automatically. It is very useful for financial/statistical projects as well as games, timers and anything that deals with numbers changing within boundries and number formatting.

value.js will:

help protect the value, keeping it only accessible through various getters and setters

var minutes = Value({value:1, min:1, max:60})
minutes.set(20).value()
>> 20

keep your value within boundries (min and max)

var comission = Value({value:10, min:1, max:25, format:{symbol:'%'}})
comission.get()
>> "10%"
comission.set(25).get()
>> "25%"
comission.set(50).get()
>> "25%"

allow your to nudge your value

var money = Value({value: 1500, min: 0, max: 10000, format: 'money'})
money.get()
>> "$1,500"
money.minus().get()
>> "$1,499"
money.setNudge(100).plus().plus().plus().get()
>> "$1,799"

freeze and defrost your value

var deposit = Value({value: 10, frozen:true})
deposit.value()
>> 10
deposit.set(1).value()
>> 10
deposit.minus().value()
>> 10
deposit.defrost().plus().value()
>> 11

Did you notice the chaining?

value.js is perfect for GUI development, because it allows you to set callbacks (either permanent or ad-hoc) on any value change, for instance:

var points = new Value();
points.subscribe(function(value) {
	//update GUI with new value
	$('input#points').val(value) //no need to use .get, in string context value.js will automatically return a string
})
>> "0"




value.js is cross-browser compatible and library agnostic, which makes it a perfect companion for libraries like jQuery.

About

Javascript library to store and manage numeric values. Provides value boundaries protection (max and min) as well as formatting to string.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published