-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
170 lines (151 loc) · 4.03 KB
/
index.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html>
<head>
<title>liveNumberFormat.js</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
* {
box-sizing: border-box;
-webkit-appearance: none;
}
html,
body {
font-family: "Inter", "Helvetica Neue", "Museo Sans", sans-serif;
font-size: 25px;
line-height: 30px;
color: #555555;
}
#numberInput {
font-family: "Inter", "Helvetica Neue", "Museo Sans", sans-serif;
padding: 15px;
font-size: 2rem;
line-height: 1.5rem;
border: 1px solid #ccc;
box-shadow: 2px 2px 0px #ccc;
width: 90%;
height: 100px;
}
.eg {
font-size: 0.8rem;
}
.note {
font-size: 0.6rem;
color: #999;
}
a {
color: #999;
}
h1 {
color: #0054c6;
}
.text-center {
text-align: center !important;
}
.container {
margin: 20vh auto 0 auto;
max-width: 1000px;
}
input,
select,
#format {
outline: none;
padding: 8px;
border: 1px solid #ccc;
box-shadow: 2px 2px 0px #ccc;
background-color: white;
outline: none;
}
.mt-20 {
margin-top: 20px;
}
@media screen and (max-width: 900px) {
body {
font-size: 18px;
line-height: 22px;
}
.container {
margin-top: 5vh;
}
#numberInput {
font-size: 1.2rem;
padding: 10px;
line-height: 1.3rem;
width: 90%;
height: 90px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>liveNumberFormat.js</h1>
<p>
A tiny Javascript library that gives live as-you-type formatting to
numbers & currencies, ~1600 bytes minified + gzipped.
</p>
<input
autofocus
type="text"
id="numberInput"
placeholder="Enter a number"
/>
<select name="format" id="format" class="mt-20">
<option value="thousand" selected>Thousand (Western)</option>
<option value="thousandLakhCrore">
Thousand, lakh, crore (Indian)
</option>
<option value="tenThousand">Ten thousand (East Asian)</option>
</select>
<br />
<p class="eg">Raw: <span id="raw"></span></p>
<p class="eg">Float: <span id="flt">0</span></p>
<br />
<br />
<br />
<p class="note">
For features & configurations, see:
<a href="https://github.com/abhinavxd/liveNumberFormat.js"
>abhinavxd/liveNumberFormat.js</a
>
</p>
</div>
<script type="module">
import LiveNumberFormat from "./livenumberformat.min.js";
let input = document.querySelector("input");
// Set up the formatter
let formatter = new LiveNumberFormat(input, {
formatStyle: document.getElementById("format").value,
stripLeadingZeroes: false,
allowNegative: true,
debounceTime: 200,
integerScale: 20,
decimalScale: 7,
allowDecimalReplacement: false,
});
// Set the format style
document
.getElementById("format")
.addEventListener("change", function (e) {
formatter.destroy();
formatter = new LiveNumberFormat(input, {
formatStyle: e.target.value,
stripLeadingZeroes: false,
allowNegative: true,
debounceTime: 200,
integerScale: 20,
decimalScale: 7,
allowDecimalReplacement: false,
});
input.value = "";
input.focus();
});
document
.getElementById("numberInput")
.addEventListener("input", function (e) {
document.getElementById("raw").innerText = formatter.getRawValue();
document.getElementById("flt").innerText = formatter.getFloatValue();
});
</script>
</body>
</html>