mirror of
https://github.com/mmjee/Piped-Material.git
synced 2024-12-06 19:26:36 +01:00
bbd1ce30ec
Squashed commit of the following: commita1c18c7903Author: root <root@git.maharshi.ninja> Date: Sun Aug 22 21:46:45 2021 +0530 Minor UI change commit82783a4fb2Author: root <root@git.maharshi.ninja> Date: Sun Aug 22 21:23:15 2021 +0530 Format date and time the Right Way (™️) commit1b0d87e81dAuthor: root <root@git.maharshi.ninja> Date: Sun Aug 22 21:17:41 2021 +0530 A few fixes and a basic implementation commit7e5d057d37Author: root <root@git.maharshi.ninja> Date: Sun Aug 22 19:58:10 2021 +0530 Add PouchDB and add the basic design commit16a07c10ffAuthor: root <root@git.maharshi.ninja> Date: Sun Aug 22 18:53:34 2021 +0530 Delete robots.txt commit83e8690dc5Author: root <root@git.maharshi.ninja> Date: Sun Aug 22 18:52:00 2021 +0530 Add PWA configuration
72 lines
1.5 KiB
JavaScript
72 lines
1.5 KiB
JavaScript
import DOMPurify from 'dompurify'
|
|
|
|
import TimeAgo from 'javascript-time-ago'
|
|
import en from 'javascript-time-ago/locale/en'
|
|
|
|
TimeAgo.addDefaultLocale(en)
|
|
const timeAgo = new TimeAgo('en-US')
|
|
|
|
class LibPiped {
|
|
intlDTF = new Intl.DateTimeFormat([], {
|
|
dateStyle: 'full',
|
|
timeStyle: 'full'
|
|
})
|
|
|
|
timeFormat (duration) {
|
|
const pad = function (num, size) {
|
|
return ('000' + num).slice(size * -1)
|
|
}
|
|
|
|
const time = parseFloat(duration).toFixed(3)
|
|
const hours = Math.floor(time / 60 / 60)
|
|
const minutes = Math.floor(time / 60) % 60
|
|
const seconds = Math.floor(time - minutes * 60)
|
|
|
|
let str = ''
|
|
|
|
if (hours > 0) str += hours + ':'
|
|
|
|
str += pad(minutes, 2) + ':' + pad(seconds, 2)
|
|
|
|
return str
|
|
}
|
|
|
|
formatFullDate (date) {
|
|
return this.intlDTF.format(date)
|
|
}
|
|
|
|
numberFormat (num) {
|
|
const digits = 2
|
|
const si = [
|
|
{ value: 1, symbol: '' },
|
|
{ value: 1e3, symbol: 'K' },
|
|
{ value: 1e6, symbol: 'M' },
|
|
{ value: 1e9, symbol: 'B' }
|
|
]
|
|
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/
|
|
let i
|
|
for (i = si.length - 1; i > 0; i--) {
|
|
if (num >= si[i].value) {
|
|
break
|
|
}
|
|
}
|
|
return (num / si[i].value).toFixed(digits).replace(rx, '$1') + si[i].symbol
|
|
}
|
|
|
|
addCommas (num) {
|
|
num = parseInt(num)
|
|
return num.toLocaleString('en-US')
|
|
}
|
|
|
|
purifyHTML (original) {
|
|
return DOMPurify.sanitize(original)
|
|
}
|
|
|
|
timeAgo (time) {
|
|
return timeAgo.format(time)
|
|
}
|
|
}
|
|
|
|
const lp = new LibPiped()
|
|
export { lp as LibPiped }
|