You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.9 KiB
122 lines
2.9 KiB
const satsPerBtc = 100000000 // one hundred million per btc |
|
import { createHash } from './crypto.js' |
|
import { Task } from './types.js' |
|
|
|
export function crawlerHash(tasks: Task[], taskId: string) { |
|
const crawlerResults = crawler(tasks, taskId) |
|
let buffers: number[] = [] |
|
crawlerResults.forEach(tId => { |
|
buffers.push(...Buffer.from(tId)) |
|
}) |
|
const bufferResult = Buffer.from(buffers) |
|
return createHash(bufferResult) |
|
} |
|
|
|
export function crawler(tasks: Task[], taskId: string): string[] { |
|
let history: string[] = [] |
|
tasks.forEach(task => { |
|
if (task.taskId === taskId) { |
|
let crawler: string[] = [taskId] |
|
do { |
|
let newCards: string[] = [] |
|
crawler.forEach(t => { |
|
if (history.indexOf(t) >= 0) return |
|
history.push(t) |
|
let subTask = tasks.filter(pst => pst.taskId === t)[0] |
|
if (subTask) { |
|
let gridCells = |
|
subTask.pins && subTask.pins.length >= 1 |
|
? subTask.pins.map(pin => pin.taskId) |
|
: [] |
|
newCards = newCards |
|
.concat(subTask.subTasks) |
|
.concat(subTask.priorities) |
|
.concat(subTask.completed) |
|
.concat(gridCells) |
|
} |
|
}) |
|
crawler = newCards |
|
} while (crawler.length > 0) |
|
} |
|
}) |
|
return history |
|
} |
|
|
|
export function shortName(name) { |
|
let limit = 280 |
|
let shortened = name.substring(0, limit) |
|
if (name.length > limit) { |
|
shortened += '…' |
|
} |
|
return shortened |
|
} |
|
|
|
export function cardColorCSS(color) { |
|
return { |
|
redwx: color == 'red', |
|
bluewx: color == 'blue', |
|
greenwx: color == 'green', |
|
yellowwx: color == 'yellow', |
|
purplewx: color == 'purple', |
|
blackwx: color == 'black', |
|
} |
|
} |
|
|
|
export function isString(x) { |
|
return Object.prototype.toString.call(x) === '[object String]' |
|
} |
|
|
|
export function cadToSats(cadAmt, spot) { |
|
let sats = (parseFloat(cadAmt) / parseFloat(spot)) * satsPerBtc |
|
return Math.floor(sats) |
|
} |
|
|
|
export function satsToCad(sats, spot) { |
|
let cad = sats * (spot / satsPerBtc) |
|
return cad.toFixed(2) |
|
} |
|
|
|
export function calculateMsThisMonth() { |
|
let today = new Date() |
|
let daysThisMonth = new Date( |
|
today.getFullYear(), |
|
today.getMonth(), |
|
0 |
|
).getDate() |
|
return daysThisMonth * 24 * 60 * 60 * 1000 |
|
} |
|
|
|
export function getMeridienTime(ts) { |
|
let d = new Date(parseInt(ts)) |
|
let hour24 = d.getHours() |
|
|
|
let rollover = 0 |
|
if (hour24 >= 24) { |
|
rollover = 1 |
|
hour24 %= 24 |
|
} |
|
|
|
let hour, meridien |
|
if (hour24 > 12) { |
|
meridien = 'pm' |
|
hour = hour24 - 12 |
|
} else { |
|
meridien = 'am' |
|
hour = hour24 |
|
} |
|
|
|
let date = d.getDate() + rollover |
|
let month = d.getMonth() + 1 |
|
let minute = d.getMinutes() |
|
let year = d.getFullYear() |
|
|
|
let weekday = d.toString().slice(0, 3) |
|
|
|
return { weekday, year, month, date, hour, minute, meridien } |
|
} |
|
|
|
export function toTitleCase(str) { |
|
return str.replace(/\w\S*/g, function (txt) { |
|
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() |
|
}) |
|
}
|
|
|