hierarchical-estimates-visu.../lib/utils.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-22 20:24:31 +00:00
import crypto from "crypto"
2021-10-06 14:05:11 +00:00
export const hashString = (string) => crypto.createHash('md5').update(string).digest('hex');
2021-11-25 00:42:34 +00:00
const id = x => x
export const transformSliderValueToActualValue = id
export const transformSliderValueToPracticalValue = id
2021-10-06 14:05:11 +00:00
2021-11-25 00:42:34 +00:00
export const _transformSliderValueToActualValue = value => 10 ** value //>= 2 ? Math.round(10 ** value) : Math.round(10 * 10 ** value) / 10
2021-10-06 14:05:11 +00:00
export const toLocale = x => Number(x).toLocaleString()
2021-10-06 15:10:05 +00:00
export const truncateValueForDisplay = value => {
if(value > 10){
return Number(Math.round(value).toPrecision(2))
}else if(value > 1){
return Math.round(value * 10) / 10
} else if(value < 1){
}
}
2021-11-25 00:42:34 +00:00
export const _transformSliderValueToPracticalValue = value => truncateValueForDisplay(transformSliderValueToActualValue(value))
export function numToAlphabeticalString(num){
// https://stackoverflow.com/questions/45787459/convert-number-to-alphabet-string-javascript/45787487
num=num+1
2021-11-25 00:42:34 +00:00
var s = '', t;
while (num > 0) {
t = (num - 1) % 26;
s = String.fromCharCode(65 + t) + s;
num = (num - t)/26 | 0;
}
return `#${s}` || undefined;
2021-11-25 00:42:34 +00:00
}