refactor(@embark/embark-utils): move last fn into utils package

This commit is contained in:
Pascal Precht 2019-04-26 14:20:05 +02:00 committed by Pascal Precht
parent 4c4c8ed1d6
commit 6308c82993
4 changed files with 10 additions and 8 deletions

View File

@ -0,0 +1,5 @@
export function last(array: any) {
return array[array.length - 1];
}

View File

@ -8,6 +8,8 @@ const {findNextPort} = require('./network');
const logUtils = require('./log-utils');
const toposortGraph = require('./toposort');
import { last } from './collections';
function checkIsAvailable(url, callback) {
const protocol = url.split(':')[0];
const httpObj = (protocol === 'https') ? https : http;
@ -125,6 +127,7 @@ const Utils = {
findNextPort,
hashTo32ByteHexString,
isHex,
last,
soliditySha3,
recursiveMerge,
sha512,

View File

@ -5,7 +5,6 @@ import prettyMs from "pretty-ms";
import { Logger } from "embark";
const utils = require("./utils.js");
const ora = require("ora");
export interface LongRunningProcessTimerOptions {
@ -63,7 +62,7 @@ export default class LongRunningProcessTimer {
let strDuration;
// find any download ongoing measurements we"ve made
entry = utils.last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadOngoing));
entry = last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadOngoing));
if (entry) {
// ongoing performance mark
// TODO: add i18n
@ -73,7 +72,7 @@ export default class LongRunningProcessTimer {
}
} else {
// otherwise, find our download complete measurement
entry = utils.last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadComplete));
entry = last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadComplete));
if (entry) {
// TODO: add i18n
strDuration = this.processFinishedMsg.replace("{{packageName}}", this.packageName).replace("{{version}}", this.version).replace("{{duration}}", prettyMs(entry.duration));

View File

@ -402,10 +402,6 @@ function groupBy(array, key) {
}, {});
}
function last(array) {
return array[array.length - 1];
}
function interceptLogs(consoleContext, logger) {
let context = {};
context.console = consoleContext;
@ -541,7 +537,6 @@ module.exports = {
getHexBalanceFromString,
compact,
groupBy,
last,
interceptLogs,
errorMessage,
timer,