JSFiddle - React, Tailwind, and code Playground

by Oski Krawczyk

HTML

<input type="text"/>
<div id="log"></div>

JavaScript

var log = document.querySelector("#log");

var typed = {};

var range = [
    "day",
    "week",
    "month",
    "year"
];

var metric = [
    "bounce",
    "visits",
    "views",
    "referrers"
];
    
window.ak = function(str){
    
    command = str.split(" ");
    typed.metric = command[0];
    
    if (command[1] > 0){
        typed.range = command[2];
        typed.l = parseInt(command[1]);
    } else {
        typed.range = command[1];
        typed.l = 1;
    }
        
    typed.range = range.filter(function(c, i){
        if (!typed.range.indexOf(c)){
            return c;
        }
    });
    typed.range = typed.range.pop();
    return typed;
}

console.log(window.ak("bounce 3 weeks"));