2018-04-06 00:57:36 +00:00
|
|
|
import padStart from 'lodash-es/padStart'
|
2018-01-19 17:18:14 +00:00
|
|
|
|
2018-03-11 04:24:07 +00:00
|
|
|
export function zeroPad (str, toSize) {
|
|
|
|
return padStart(str, toSize, '0')
|
|
|
|
}
|
|
|
|
|
2018-01-19 17:18:14 +00:00
|
|
|
export function toPaddedBigInt (id) {
|
2018-03-11 04:24:07 +00:00
|
|
|
return zeroPad(id, 30)
|
2018-01-19 17:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function toReversePaddedBigInt (id) {
|
|
|
|
let bigInt = toPaddedBigInt(id)
|
|
|
|
let res = ''
|
|
|
|
for (let i = 0; i < bigInt.length; i++) {
|
|
|
|
res += (9 - parseInt(bigInt.charAt(i), 10)).toString(10)
|
|
|
|
}
|
|
|
|
return res
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|
2018-03-10 18:54:16 +00:00
|
|
|
|
|
|
|
export function byItemIds (a, b) {
|
|
|
|
let aPadded = toPaddedBigInt(a)
|
|
|
|
let bPadded = toPaddedBigInt(b)
|
|
|
|
return aPadded < bPadded ? -1 : aPadded === bPadded ? 0 : 1
|
|
|
|
}
|