UNPKG

openfin-cli

Version:

Supports command line development in the OpenFin environment.

29 lines (28 loc) 1.52 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import axios from 'axios'; export const fetch = (url) => __awaiter(void 0, void 0, void 0, function* () { const response = yield axios.get(url); if (response.status < 200 || response.status > 399) { throw new Error(`Failed to load url: ${url}, status code:${response.status}`); } return response.data; }); export const isURL = (str) => { return str.lastIndexOf('http') >= 0; }; export const formatTimeFromMs = (ms) => { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const secondsRemainder = seconds % 60; const minutesRemainder = minutes % 60; return `${hours ? `${hours}h ` : ''}${minutesRemainder ? `${minutesRemainder}m ` : ''}${secondsRemainder ? `${secondsRemainder}s` : ''}`; };