@symbolic/lib
Advanced tools
Comparing version 1.0.26 to 1.0.27
@@ -11,3 +11,2 @@ 'use strict'; | ||
console.log('apitest'); | ||
var api = { | ||
@@ -75,2 +74,32 @@ async request({uri, body={}}, {token, shouldAlert=true}={}) { | ||
var time = {}; | ||
time.scales = [ | ||
{abbreviation: 'm', title: 'minute', minutes: 1, maxMinutes: 59}, | ||
{abbreviation: 'h', title: 'hour', minutes: 60, maxMinutes: 479}, | ||
{abbreviation: 'd', title: 'day', minutes: 480, maxMinutes: 2399}, | ||
{abbreviation: 'w', title: 'week', minutes: 2400, maxMinutes: 10079}, | ||
{abbreviation: 'mo', title: 'month', minutes: 10080, maxMinutes: 125279}, | ||
{abbreviation: 'y', title: 'year', minutes: 125280} | ||
]; | ||
time.toLabel = (minutes) => { | ||
minutes = Math.round(minutes) || 0; //HINT prevent invalid minutes values | ||
var scale = _.find(time.scales, scale => minutes <= scale.maxMinutes) || _.last(time.scales); | ||
var number = Math.round(minutes/scale.minutes * 10) / 10; | ||
return `${number}${scale.abbreviation}`; | ||
}; | ||
time.toMinutes = (label) => { | ||
label = label || '0m'; | ||
var number = parseFloat(label) || 0; | ||
var abbreviation = label.replace(`${number}`, ''); | ||
var scale = _.find(time.scales, {abbreviation}); | ||
return scale && number ? (number * scale.minutes) : 0; | ||
}; | ||
var colors = {}; | ||
@@ -136,3 +165,3 @@ | ||
var sf = {api, colors, validation}; | ||
var sf = {api, colors, validation, time}; | ||
@@ -142,2 +171,3 @@ exports.api = api; | ||
exports.default = sf; | ||
exports.time = time; | ||
exports.validation = validation; |
{ | ||
"name": "@symbolic/lib", | ||
"version": "1.0.26", | ||
"version": "1.0.27", | ||
"description": "plain js utilities", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import axios from 'axios'; | ||
import _ from 'lodash'; | ||
import Cookies from 'js-cookie'; | ||
console.log('apitest') | ||
var api = { | ||
@@ -6,0 +6,0 @@ async request({uri, body={}}, {token, shouldAlert=true}={}) { |
import api from './api/api'; | ||
import time from './time/time'; | ||
import colors from './colors/colors'; | ||
import validation from './validation/validation'; | ||
var sf = {api, colors, validation}; | ||
var sf = {api, colors, validation, time}; | ||
export default sf; | ||
export {api, colors, validation}; | ||
export {api, colors, validation, time}; |
12259
12
333