Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Oct 14, 2023
1 parent a439fc6 commit c4d300a
Show file tree
Hide file tree
Showing 90 changed files with 340 additions and 347 deletions.
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const app = module.exports = express();


if (!process.env.SITE_URL) {
process.env.SITE_URL = (app.get('env') === 'production') ?
process.env.SITE_URL = app.get('env') === 'production' ?
'https://liftie.info' :
'http://locahost:3000';
}
Expand Down Expand Up @@ -72,13 +72,13 @@ app.data = require('./lib/routes/data')();
require('./lib/routes')(app);

app.run = function run() {
app.data.init(function(err) {
app.data.init(function (err) {
if (err) {
console.error(err);
process.exit(1);
return;
}
http.createServer(app).listen(app.get('port'), function(){
http.createServer(app).listen(app.get('port'), function () {
console.log(`Running on: http://localhost:${app.get('port')}`);
});
});
Expand Down
5 changes: 2 additions & 3 deletions lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ module.exports = checkNames;
* Filters out the names that are not supported
*/
function checkNames(requested, valid, all) {
if(!requested) {
if (!requested) {
return all;
}
if (typeof requested === 'string') {
requested = requested.split(',');
}
return requested.filter(function(item) {
return requested.filter(function (item) {
return valid[item];
});
}

3 changes: 1 addition & 2 deletions lib/cli/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ function fetchExample(resortId) {
resort = require('../resorts/' + resortId + '/resort.json');
curl(resort.dataUrl || resort.api || resort.url, resortId);
done = true;
}
catch (e) {
} catch (e) {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/for-each-resort.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = forEachResort;

function forEachResort(fn) {
console.log('Reading:', lib);
readdir(lib, { withFileTypes: true }, function(err, dirents) {
readdir(lib, { withFileTypes: true }, function (err, dirents) {
if (err) {
console.error(err);
process.exit(1);
Expand Down
10 changes: 4 additions & 6 deletions lib/cli/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const curl = require('./curl');
const dirs = require('./dirs');

let fname;
const schema = [
{
const schema = [{
name: 'id',
description: 'Short name of the resort [acme]',
type: 'string',
Expand Down Expand Up @@ -81,8 +80,7 @@ if (program.json) {
}
execute(conf);
});
}
else {
} else {
execute();
}

Expand Down Expand Up @@ -118,7 +116,7 @@ function write(dst, json) {

function copy(src, dst, params) {
console.log('Generating %s...', dst);
fs.readFile(src, 'utf8', function(err, data) {
fs.readFile(src, 'utf8', function (err, data) {
data = template(data)(params);
fs.writeFileSync(dst, data);
});
Expand All @@ -139,7 +137,7 @@ function execute(conf) {
schema[2].before = splitHost;
conf = conf || {};
prompt.override = conf;
prompt.addProperties(conf, schema, function(err) {
prompt.addProperties(conf, schema, function (err) {
if (err) {
console.error(err);
process.exit(-1);
Expand Down
11 changes: 5 additions & 6 deletions lib/cli/noaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let done = false;

const userAgent = 'Mozilla/5.0 (compatible; Liftie/1.0; +https://liftie.info)';

function points([ lon, lat ]) {
function points([lon, lat]) {
function shorten(n) {
return n.toFixed(4).replace(/0+$/, '');
}
Expand All @@ -36,15 +36,15 @@ function noaaForResort(resortId, { overwrite }) {
superagent(url)
.accept('application/geo+json')
.set('User-Agent', userAgent)
.then(function(res) {
const { body: { properties: { gridId, gridX, gridY} } } = res;
.then(function (res) {
const { body: { properties: { gridId, gridX, gridY } } } = res;
const noaa = `${gridId}/${gridX},${gridY}`;
if (overwrite) {
descriptor.noaa = noaa;
writeDescriptor(resortId, descriptor);
}
console.log(resortId, noaa);
}, function(e) {
}, function (e) {
console.error('Cannot find NOAA station for:', resortId, e.response.text);
});
}
Expand All @@ -62,8 +62,7 @@ function writeDescriptor(resortId, descriptor) {
function readDescriptor(resortId) {
try {
return require(`../resorts/${resortId}/resort.json`);
}
catch (e) {
} catch (e) {
console.error(resortId, 'is not a valid resort ID');
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/client/boot/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = register;

/* global navigator, console */

function registrationHandler({scope, installing, waiting, active}) {
function registrationHandler({ scope, installing, waiting, active }) {
console.log('SW', scope);

if (installing) {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/minimax/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports=minimax;
module.exports = minimax;

/**
* @param {Array} elements list of affected element
Expand Down
2 changes: 1 addition & 1 deletion lib/client/resort/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function removeAllChildren(node) {
}
}

function next({nextElementSibling, nextSibling}) {
function next({ nextElementSibling, nextSibling }) {
return nextElementSibling || nextSibling;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client/resort/lifts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function renderColorBar(node, percentage) {
});
}

function render(node, {status, stats}) {
function render(node, { status, stats }) {
renderStatus(node.querySelector('.lifts'), status);
renderStats(node.querySelector('.summary'), stats);
renderColorBar(node.querySelector('.summary-color-bar'), stats.percentage);
Expand Down
5 changes: 2 additions & 3 deletions lib/client/resort/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function render(div, webcams) {
// .title
// .notice

function initCam(cam, {source, image, name, notice}) {
function initCam(cam, { source, image, name, notice }) {
cam.querySelector('a').setAttribute('href', source);
cam.querySelector('img.active').setAttribute('src', image);
cam.querySelector('img.inactive').setAttribute('src', '');
Expand All @@ -97,8 +97,7 @@ function render(div, webcams) {
let cam;
if (i < li.length) {
cam = li[i];
}
else {
} else {
cam = ul.appendChild(li[0].cloneNode(true));
}
initCam(cam.querySelector('.desktop'), webcam);
Expand Down
6 changes: 3 additions & 3 deletions lib/client/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const cookie = require('js-cookie');

const k = require('k')(window);

module.exports=state;
module.exports = state;

function state(nodes, st, keys) {
const cookieName = `resorts-${st}`;
Expand All @@ -22,7 +22,7 @@ function state(nodes, st, keys) {

function read() {
const text = cookie.get(cookieName);
return text && text.length ? text.split(',') : [];
return text && text.length ? text.split(',') : [];
}

function write(arr) {
Expand All @@ -40,7 +40,7 @@ function state(nodes, st, keys) {
return memo;
}, {});

nodes.forEach(({dataset, classList}) => {
nodes.forEach(({ dataset, classList }) => {
const id = dataset.resort;
state[id] = classList.contains(st);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/client/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ function stats() {
let ac = 0;
const { style } = pie;
Object.entries(data.percentage).forEach(
([ key, value ]) => style.setProperty(`--${key}`, `${ac += value}%`)
([key, value]) => style.setProperty(`--${key}`, `${ac += value}%`)
);
}
9 changes: 4 additions & 5 deletions lib/embed/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*global document, window */

function el(attrs) {
const attrStr = Object.keys(attrs).map(function(attr) {
return attr + '="' + attrs[attr] + '"';
const attrStr = Object.keys(attrs).map(function (attr) {
return attr + '="' + attrs[attr] + '"';
}).join(' ');

return ['<iframe ',
Expand All @@ -24,8 +24,7 @@ function addWidget(parent, resort, style) {
parent.insertAdjacentHTML('afterBegin', html);
}

function receiveMessage(event)
{
function receiveMessage(event) {
// from liftie?
if (!/^https?:\/\/liftie.info$/.test(event.origin)) {
return;
Expand All @@ -46,7 +45,7 @@ function embed() {
if (els.length) {
window.addEventListener("message", receiveMessage, false);
}
for(i = 0; i < els.length; i++) {
for (i = 0; i < els.length; i++) {
addWidget(els[i], els[i].getAttribute('data-resort'), els[i].getAttribute('data-style'));
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function fetch(resort, fn) {
}
debug("Fetch lift status for %s", resort.id);
const rfau = resort._rfau;
rfau.fn(rfau.url, resort._parseFn, function(err, data) {
Promise.resolve(data).then(function(data, err) {
rfau.fn(rfau.url, resort._parseFn, function (err, data) {
Promise.resolve(data).then(function (data, err) {
if (err || !data) {
data = {};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function getParseFn(resortId) {

return wrappedParse;

function wrappedParse (...args) {
function wrappedParse(...args) {
try {
return parse(...args);
} catch(e) {
} catch (e) {
console.error(`Exception when parsing ${resortId}`, e);
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lifts/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function (url, parse, fn) {
request(url)
.buffer(true)
.on('error', fn)
.end(function(err, res) {
.end(function (err, res) {
if (err && !url.ignoreErrors) {
console.error('Error', url, err.status);
return fn(err.status);
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function rest(url, parse, fn) {
.on('error', fn);

request.then(
function(res) {
function (res) {
let { body, text } = res;
if (url.html) {
return parseHtml(body, parse, fn);
Expand All @@ -44,7 +44,7 @@ function rest(url, parse, fn) {
fn(null, parse(body));
}
},
function({ status }) {
function ({ status }) {
fn(status);
}
);
Expand Down
38 changes: 19 additions & 19 deletions lib/lifts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ module.exports.summary = summary;
const states = ['open', 'hold', 'scheduled', 'closed'];

function empty(val) {
return states.reduce(function(memo, s) {
memo[s] = val;
return memo;
}, {});
return states.reduce(function (memo, s) {
memo[s] = val;
return memo;
}, {});
}

function percentage(status) {
const all = states.reduce(function(memo, s) {
return memo + status[s];
}, 0);
if (!all) {
return empty(25);
}
return states.reduce(function(memo, s) {
//console.log('status', s, status[s]);
memo[s] = Math.floor(status[s] * 1000 / all) / 10;
return memo;
}, empty());
const all = states.reduce(function (memo, s) {
return memo + status[s];
}, 0);
if (!all) {
return empty(25);
}
return states.reduce(function (memo, s) {
//console.log('status', s, status[s]);
memo[s] = Math.floor(status[s] * 1000 / all) / 10;
return memo;
}, empty());
}

function stats (status) {
const r = Object.keys(status).reduce(function(memo, lift) {
function stats(status) {
const r = Object.keys(status).reduce(function (memo, lift) {
memo[status[lift]] += 1;
return memo;
}, empty(0));
Expand All @@ -38,7 +38,7 @@ function summary(arr) {
if (!s) {
return sum;
}
states.forEach(function(state) {
states.forEach(function (state) {
sum[state] += s[state] || 0;
});
return sum;
Expand All @@ -47,4 +47,4 @@ function summary(arr) {
const r = arr.reduce(add, empty(0));
r.percentage = percentage(r);
return r;
}
}
4 changes: 2 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const fs = require('fs');
module.exports = load;

function load(fn) {
fs.readdir(__dirname + '/resorts', function(err, names) {
if(err) {
fs.readdir(__dirname + '/resorts', function (err, names) {
if (err) {
return fn(err);
}
const data = names.reduce(function (data, id) {
Expand Down
6 changes: 3 additions & 3 deletions lib/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function register(loader) {
}

function appendResorts(data, resorts) {
Object.keys(resorts).forEach(function(id) {
if(!data[id]) {
Object.keys(resorts).forEach(function (id) {
if (!data[id]) {
data[id] = resorts[id];
}
});
Expand All @@ -23,7 +23,7 @@ function appendResorts(data, resorts) {

function load(fn) {
debug('Loading resorts...');
async.parallel(loaders, function(err, results) {
async.parallel(loaders, function (err, results) {
const data = results.reduce(appendResorts, Object.create(null));
debug('Loaded %d resorts.', Object.keys(data).length);
fn(null, data);
Expand Down
Loading

0 comments on commit c4d300a

Please sign in to comment.