-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
58 lines (41 loc) · 1.63 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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.