UNPKG

savory

Version:

A command-line interface for operating your Codefresh account

33 lines (30 loc) 949 B
const randomString = ()=> Math.random().toString(26).slice(2), timeSpanFormatter = (function(){ const SECOND = 1000, MINUTE = 60 * SECOND, HOUR = 60 * MINUTE; return function(spanInMilliseconds){ return [HOUR, MINUTE, SECOND].map((divider)=> { let section = ~~(spanInMilliseconds / divider); spanInMilliseconds = (spanInMilliseconds % divider); return ["0", ...section.toString().split('')].slice(-2).join(''); }).join(':'); }; })(), simpleHash = (str)=> { let hash = 0; if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { char = str.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash = hash & hash; } return hash; }; module.exports = { timeSpanFormatter, randomString, simpleHash };