summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-03-08 16:28:00 +0100
committerJules Laplace <jules@okfoc.us>2017-03-08 16:28:00 +0100
commit15ddd0beabb2342d9d68ff4625139ab7fb456ace (patch)
tree99d351a78e1b5ad9ec5c759da6b0cbcdb93e0cdc /index.js
parent26f3fd1352a7fb73b7e8317a45f2a38975467429 (diff)
readme and demo page
Diffstat (limited to 'index.js')
-rw-r--r--index.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/index.js b/index.js
index 71d93d9..423295b 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,9 @@
-module.exports = basic = {}
+var basic = {}
+
+if (! ('window' in this)) {
+ module.exports = basic
+}
// Handle bases up to base 36
basic.abedecary = "0123456789abcdefghijklmnopqrstuvwxyz"
@@ -38,10 +42,17 @@ basic.toNumber = function (s, b) {
if (! basic.validate(s, b)) {
return NaN
}
- var n = 0
+ var n = 0, is_negative = false
+ if (s.indexOf("-") == 0) {
+ is_negative = true
+ s = s.substr(1)
+ }
for (var i = 0, len = s.length; i < len; i++) {
n += basic.abedecary.indexOf(s[len-1-i]) * Math.pow(b, i)
}
+ if (is_negative) {
+ n *= -1
+ }
return n
}