api drop unused code
This commit is contained in:
1 parent
d859fdb302
commit
06745b45f4
26 files changed
+32
-788
No files matched your search
@@ -1,7 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Date -> Unix time
|
||||
*
|
||||
* @param date
|
||||
*/
|
||||
export const timestamp = (date: Date) => date.getTime()
|
||||
@@ -1,23 +0,0 @@
|
||||
const getExt = (name: string) => /\.(\w+)$/.exec(name)[1]
|
||||
const defaultExt = (ext: string) => ext.toUpperCase()
|
||||
const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc']
|
||||
const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК']
|
||||
const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
|
||||
|
||||
export function ext(filname: string): string {
|
||||
const ext = getExt(filname)
|
||||
const i = exts.indexOf(ext)
|
||||
|
||||
return i > -1
|
||||
? extd[i]
|
||||
: defaultExt(ext)
|
||||
}
|
||||
|
||||
export function size(bytes: any, precision = 1): string {
|
||||
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return ''
|
||||
|
||||
const number = Math.floor(Math.log(bytes) / Math.log(1024))
|
||||
const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision)
|
||||
|
||||
return `${size} ${units[number]}`
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
function sort(list, fn, reverse = false) {
|
||||
return list
|
||||
.map(i => [fn(i), i])
|
||||
.sort((a, b) => reverse
|
||||
? a[0] - b[0]
|
||||
: b[0] - a[0])
|
||||
.map(i => i[1])
|
||||
}
|
||||
|
||||
function sortBy(fn, reverse = false) {
|
||||
return (i1, i2) => {
|
||||
const t1 = fn(i1)
|
||||
const t2 = fn(i2)
|
||||
|
||||
return reverse
|
||||
? t1 - t2
|
||||
: t2 - t1
|
||||
}
|
||||
}
|
||||
|
||||
exports.sortBy = sortBy
|
||||
exports.sort = sort
|
||||
@@ -1,19 +1,19 @@
|
||||
export async function find(collection, query, {sort, skip, limit}) {
|
||||
const cursor = collection.find(query)
|
||||
export async function find(collection, query, { sort, skip, limit }) {
|
||||
const cursor = collection.find(query)
|
||||
|
||||
if (sort) cursor.sort(sort)
|
||||
if (skip) cursor.skip(skip)
|
||||
if (limit) cursor.limit(limit)
|
||||
if (sort) cursor.sort(sort)
|
||||
if (skip) cursor.skip(skip)
|
||||
if (limit) cursor.limit(limit)
|
||||
|
||||
return cursor.toArray()
|
||||
return cursor.toArray()
|
||||
}
|
||||
|
||||
export async function findOne(collection, query) {
|
||||
return collection.findOne(query)
|
||||
return collection.findOne(query)
|
||||
}
|
||||
|
||||
export async function total(collection, query) {
|
||||
return collection
|
||||
.find(query)
|
||||
.count()
|
||||
return collection
|
||||
.find(query)
|
||||
.count()
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
function titleCase(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||
}
|
||||
|
||||
function trim(string) {
|
||||
return string
|
||||
.replace(/^\s+/, '')
|
||||
.replace(/\s+$/, '')
|
||||
}
|
||||
|
||||
exports.titleCase = titleCase
|
||||
exports.trim = trim
|
||||
Reference in new issue
Block a user