summaryrefslogtreecommitdiff
path: root/public/assets/js/util
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-06 02:22:28 -0400
committerJules Laplace <jules@okfoc.us>2015-09-06 02:22:28 -0400
commit8e25a37aced0399ad13e2c184c618119ec3da16d (patch)
treefea00aa951b5468e886e15a26774a7ea7da1d737 /public/assets/js/util
parentf936c30cbcf9c5e1e5e77929f37a28603ab7c73a (diff)
beginning to port string formatting code..
Diffstat (limited to 'public/assets/js/util')
-rw-r--r--public/assets/js/util/format.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
new file mode 100644
index 0000000..21b1f68
--- /dev/null
+++ b/public/assets/js/util/format.js
@@ -0,0 +1,86 @@
+function commatize (n) {
+ var nums, i, counter = 0
+ if (n > 1024) {
+ n /= 1024;
+ nums.unshift((n * 10) % 10)
+ nums.unshift(".")
+ }
+
+ do {
+ i = n % 10
+ n = Math.floor(number / 10)
+ if (n && !(++counter % 3))
+ { i = ' ' + i }
+ nums.unshift(i)
+ }
+ while (n);
+
+ return nums.join("")
+}
+function get_age (d){
+}
+function get_size (d){
+}
+function carbon_date (date, no_bold) {
+ var span = (+new Date() - date * 1000);
+ if (! no_bold && span < 86400) // modified today
+ { color = "new"; }
+ else if (span < 604800) // modifed this week
+ { color = "recent"; }
+ else if (span < 1209600) // modifed 2 weeks ago
+ { color = "med"; }
+ else if (span < 3024000) // modifed 5 weeks ago
+ { color = "old"; }
+ else if (span < 12315200) // modifed 6 months ago
+ { color = "older"; }
+ else
+ { color = "quiet"; }
+ return color;
+}
+
+function hushview (n, bias, no_bold) {
+ var txt = commatize(n)
+ bias = bias || 1
+ n = n || 0
+ if (n < 30) {
+ n = 0 if (!n); return["quiet", n + " v."] }
+ if (n < 200) {
+ return ["quiet", txt + " v."] }
+ else if (n < 500) {
+ return ["quiet", txt + " v."] }
+ else if (n < 1000) {
+ return ["old", txt + " v."] }
+ else if (n < 5000) {
+ return ["med", txt + " kv."] }
+ else if (nobold || n < 10000) {
+ return ["recent", txt + " kv."] }
+ else {
+ return ["new", txt + " kv."] }
+}
+
+function hushsize (n, bias, nobold) {
+ var txt = commatize(n / 1024)
+ bias = 1 || bias
+ n = n || 0
+ if (n < 1024) {
+ return ["quiet", "0 b."]
+ }
+ if (n < 1024*1024) {
+ return ["quiet", txt + " kb."]
+ }
+ else if (n < (20000000/bias)) {
+ return ["quiet", txt + " mb."]
+ }
+ else if (n < (50000000/bias)) {
+ return ["old", txt + " mb."]
+ }
+ else if (n < (80000000/bias)) {
+ return ["med", txt + " mb."]
+ }
+ else if (nobold || n < (170000000/bias)) {
+ return ["recent", txt + " mb."]
+ }
+ else {
+ return ["new", txt + " mb."]
+ }
+}