mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
refactor: use typeof for undefined in client-side
I didn't notice anything breaking prior to this, but just to be safe.
This commit is contained in:
parent
0f1ba57737
commit
0b428171bb
@ -519,7 +519,7 @@ page.getUploads = (params = {}) => {
|
||||
params.pageNum = 0
|
||||
}
|
||||
|
||||
const url = params.album !== undefined
|
||||
const url = typeof params.album !== 'undefined'
|
||||
? `api/album/${params.album}/${params.pageNum}`
|
||||
: `api/uploads/${params.pageNum}`
|
||||
|
||||
@ -673,9 +673,7 @@ page.getUploads = (params = {}) => {
|
||||
let unselected = false
|
||||
|
||||
const showOriginalNames = page.views[page.currentView].originalNames
|
||||
const hasExpiryDateColumn = files.some(file => {
|
||||
return file.expirydate !== undefined
|
||||
})
|
||||
const hasExpiryDateColumn = files.some(file => typeof file.expirydate !== 'undefined')
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
// Build full URLs
|
||||
@ -727,7 +725,7 @@ page.getUploads = (params = {}) => {
|
||||
files[i].appendix = files[i].userid
|
||||
? users[files[i].userid] || ''
|
||||
: ''
|
||||
} else if (params.album === undefined) {
|
||||
} else if (typeof params.album === 'undefined') {
|
||||
files[i].appendix = files[i].albumid
|
||||
? albums[files[i].albumid] || ''
|
||||
: ''
|
||||
@ -754,7 +752,7 @@ page.getUploads = (params = {}) => {
|
||||
div.className = 'image-container column'
|
||||
div.dataset.id = upload.id
|
||||
|
||||
if (upload.thumb !== undefined) {
|
||||
if (typeof upload.thumb !== 'undefined') {
|
||||
div.innerHTML = `<a class="image" href="${upload.file}" target="_blank"><img alt="${upload.name}" data-src="${upload.thumb}"/></a>`
|
||||
} else {
|
||||
div.innerHTML = `<a class="image" href="${upload.file}" target="_blank"><h1 class="title">${upload.extname || 'N/A'}</h1></a>`
|
||||
@ -812,7 +810,7 @@ page.getUploads = (params = {}) => {
|
||||
<th class="controls"><input id="selectAll" class="checkbox" type="checkbox" title="Select all" data-action="select-all"></th>
|
||||
<th title="Key: name">File name</th>
|
||||
${showOriginalNames ? '<th title="Key: original">Original name</th>' : ''}
|
||||
${params.album === undefined ? `<th title="Key: ${params.all ? 'userid">User' : 'albumid">Album'}</th>` : ''}
|
||||
${typeof params.album === 'undefined' ? `<th title="Key: ${params.all ? 'userid">User' : 'albumid">Album'}</th>` : ''}
|
||||
${allAlbums ? '<th title="Key: albumid">Album</th>' : ''}
|
||||
<th title="Key: size">Size</th>
|
||||
${params.all ? '<th title="Key: ip">IP</th>' : ''}
|
||||
@ -840,7 +838,7 @@ page.getUploads = (params = {}) => {
|
||||
<td class="controls"><input type="checkbox" class="checkbox" title="Select" data-index="${i}" data-action="select"${upload.selected ? ' checked' : ''}></td>
|
||||
<th class="name"><a href="${upload.file}" target="_blank" title="${upload.file}">${upload.name}</a></th>
|
||||
${showOriginalNames ? `<th class="originalname" title="${upload.original}">${upload.original}</th>` : ''}
|
||||
${params.album === undefined ? `<th class="appendix">${upload.appendix}</th>` : ''}
|
||||
${typeof params.album === 'undefined' ? `<th class="appendix">${upload.appendix}</th>` : ''}
|
||||
${allAlbums ? `<th class="album">${upload.albumid ? (albums[upload.albumid] || '') : ''}</th>` : ''}
|
||||
<td class="prettybytes">${upload.prettyBytes}</td>
|
||||
${params.all ? `<td class="ip">${upload.ip || ''}</td>` : ''}
|
||||
@ -3021,13 +3019,13 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
Object.defineProperty(Object, 'assign', {
|
||||
value: function assign (target, varArgs) { // .length of function is 2
|
||||
'use strict'
|
||||
if (target === null || target === undefined) {
|
||||
if (target === null || typeof target === 'undefined') {
|
||||
throw new TypeError('Cannot convert undefined or null to object')
|
||||
}
|
||||
const to = Object(target)
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
const nextSource = arguments[i]
|
||||
if (nextSource !== null && nextSource !== undefined) {
|
||||
if (nextSource !== null && typeof nextSource !== 'undefined') {
|
||||
for (const nextKey in nextSource) {
|
||||
// Avoid bugs when hasOwnProperty is shadowed
|
||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
||||
|
@ -399,7 +399,7 @@ page.prepareDropzone = () => {
|
||||
}
|
||||
|
||||
// Attach necessary data for initial upload speed calculation
|
||||
if (xhr._uplSpeedCalc === undefined) {
|
||||
if (typeof xhr._uplSpeedCalc === 'undefined') {
|
||||
xhr._uplSpeedCalc = {
|
||||
lastSent: 0,
|
||||
data: [{ timestamp: Date.now(), bytes: 0 }]
|
||||
@ -947,9 +947,9 @@ page.prepareUploadConfig = () => {
|
||||
|
||||
let value
|
||||
if (!conf.disabled) {
|
||||
if (conf.value !== undefined) {
|
||||
if (typeof conf.value !== 'undefined') {
|
||||
value = conf.value
|
||||
} else if (conf.number !== undefined) {
|
||||
} else if (typeof conf.number !== 'undefined') {
|
||||
const parsed = parseInt(localStorage[lsKeys[key]])
|
||||
if (!isNaN(parsed) && parsed <= conf.number.max && parsed >= conf.number.min) {
|
||||
value = parsed
|
||||
@ -969,9 +969,9 @@ page.prepareUploadConfig = () => {
|
||||
// otherwise pass value to global page object
|
||||
if (typeof conf.valueHandler === 'function') {
|
||||
conf.valueHandler(value)
|
||||
} else if (value !== undefined) {
|
||||
} else if (typeof value !== 'undefined') {
|
||||
page[key] = value
|
||||
} else if (fallback[key] !== undefined) {
|
||||
} else if (typeof fallback[key] !== 'undefined') {
|
||||
page[key] = fallback[key]
|
||||
}
|
||||
}
|
||||
@ -985,7 +985,7 @@ page.prepareUploadConfig = () => {
|
||||
for (let j = 0; j < conf.select.length; j++) {
|
||||
const opt = conf.select[j]
|
||||
const selected = (value && (opt.value === String(value))) ||
|
||||
(value === undefined && opt.value === 'default')
|
||||
(typeof value === 'undefined' && opt.value === 'default')
|
||||
opts.push(`
|
||||
<option value="${opt.value}"${selected ? ' selected' : ''}>
|
||||
${opt.text}${opt.value === 'default' ? ' (default)' : ''}
|
||||
@ -1004,10 +1004,10 @@ page.prepareUploadConfig = () => {
|
||||
control.className = 'input is-fullwidth'
|
||||
control.type = 'number'
|
||||
|
||||
if (conf.number.min !== undefined) control.min = conf.number.min
|
||||
if (conf.number.max !== undefined) control.max = conf.number.max
|
||||
if (typeof conf.number.min !== 'undefined') control.min = conf.number.min
|
||||
if (typeof conf.number.max !== 'undefined') control.max = conf.number.max
|
||||
if (typeof value === 'number') control.value = value
|
||||
else if (conf.number.default !== undefined) control.value = conf.number.default
|
||||
else if (typeof conf.number.default !== 'undefined') control.value = conf.number.default
|
||||
}
|
||||
|
||||
let help
|
||||
@ -1020,16 +1020,16 @@ page.prepareUploadConfig = () => {
|
||||
help = 'This option is currently not configurable.'
|
||||
} else if (typeof conf.help === 'string') {
|
||||
help = conf.help
|
||||
} else if (conf.help === true && conf.number !== undefined) {
|
||||
} else if (conf.help === true && typeof conf.number !== 'undefined') {
|
||||
const tmp = []
|
||||
|
||||
if (conf.number.default !== undefined) {
|
||||
if (typeof conf.number.default !== 'undefined') {
|
||||
tmp.push(`Default is ${conf.number.default}${conf.number.suffix || ''}.`)
|
||||
}
|
||||
if (conf.number.min !== undefined) {
|
||||
if (typeof conf.number.min !== 'undefined') {
|
||||
tmp.push(`Min is ${conf.number.min}${conf.number.suffix || ''}.`)
|
||||
}
|
||||
if (conf.number.max !== undefined) {
|
||||
if (typeof conf.number.max !== 'undefined') {
|
||||
tmp.push(`Max is ${conf.number.max}${conf.number.suffix || ''}.`)
|
||||
}
|
||||
|
||||
@ -1073,18 +1073,18 @@ page.prepareUploadConfig = () => {
|
||||
const key = keys[i]
|
||||
|
||||
let value
|
||||
if (config[key].select !== undefined) {
|
||||
if (typeof config[key].select !== 'undefined') {
|
||||
if (form.elements[key].value !== 'default') {
|
||||
value = form.elements[key].value
|
||||
}
|
||||
} else if (config[key].number !== undefined) {
|
||||
} else if (typeof config[key].number !== 'undefined') {
|
||||
const parsed = parseInt(form.elements[key].value)
|
||||
if (!isNaN(parsed) && parsed !== config[key].number.default) {
|
||||
value = Math.min(Math.max(parsed, config[key].number.min), config[key].number.max)
|
||||
}
|
||||
}
|
||||
|
||||
if (value !== undefined) localStorage[lsKeys[key]] = value
|
||||
if (typeof value !== 'undefined') localStorage[lsKeys[key]] = value
|
||||
else localStorage.removeItem(lsKeys[key])
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ newsfeed.simpleParseDate = string => {
|
||||
// Probably better to use a library if it needs to support other formats.
|
||||
const months = { Jan: 0, Feb: 1, Mar: 2, Apr: 3, May: 4, Jun: 5, Jul: 6, Aug: 7, Sep: 8, Oct: 9, Nov: 10, Dec: 11 }
|
||||
const match = string.match(/[a-zA-Z]*,\s(\d{2})\s([a-zA-Z]{3})\s(\d{4})\s(\d{2}):(\d{2}):(\d{2})\sGMT/)
|
||||
if (match && (months[match[2]] !== undefined)) {
|
||||
if (match && (typeof months[match[2]] !== 'undefined')) {
|
||||
const date = new Date()
|
||||
date.setUTCDate(match[1])
|
||||
date.setUTCMonth(months[match[2]])
|
||||
|
@ -123,7 +123,7 @@ render.do = reload => {
|
||||
if (previousElement) previousElement.remove()
|
||||
|
||||
const doRender = () => {
|
||||
if (render.version === undefined) {
|
||||
if (typeof render.version === 'undefined') {
|
||||
render.version = render.parseVersion()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user