Skip to content

Commit

Permalink
Run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
KristjanESPERANTO committed Feb 6, 2024
1 parent 9949953 commit 22441fd
Show file tree
Hide file tree
Showing 246 changed files with 5,677 additions and 5,677 deletions.
10 changes: 5 additions & 5 deletions docs/profile-boilerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const products = [
short: 'M',
default: true,
},
]
];

const transformReqBody = (body) => {
// get these from the recorded app requests
// body.client = { … }
// body.ver = …
// body.auth = { … }
// body.lang = …
return body
}
return body;
};

const insaProfile = {
// locale: …,
Expand All @@ -38,8 +38,8 @@ const insaProfile = {

trip: false,
radar: false,
}
};

export {
insaProfile,
}
};
16 changes: 8 additions & 8 deletions format/address.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
import {formatLocationIdentifier} from './location-identifier.js';
import {formatCoord} from './coord.js';

const formatAddress = (a) => {
if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) {
throw new TypeError('invalid address')
throw new TypeError('invalid address');
}

const data = {
A: '2', // address?
O: a.address,
X: formatCoord(a.longitude),
Y: formatCoord(a.latitude),
}
};
if (a.id) {
data.L = a.id
data.L = a.id;
}
return {
type: 'A', // address
name: a.address,
lid: formatLocationIdentifier(data),
}
}
};
};

export {
formatAddress,
}
};
4 changes: 2 additions & 2 deletions format/coord.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatCoord = x => Math.round(x * 1000000)
const formatCoord = x => Math.round(x * 1000000);

export {
formatCoord,
}
};
18 changes: 9 additions & 9 deletions format/date.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {DateTime, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
import {DateTime, IANAZone} from 'luxon';
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';

// todo: change to `(profile) => (when) => {}`
const formatDate = (profile, when) => {
let timezone
let timezone;
if (timezones.has(profile)) {
timezone = timezones.get(profile)
timezone = timezones.get(profile);
} else {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
timezone = new IANAZone(profile.timezone);
timezones.set(profile, timezone);
}

return DateTime.fromMillis(Number(when), {
locale: profile.locale,
zone: timezone,
})
.toFormat('yyyyMMdd')
}
.toFormat('yyyyMMdd');
};

export {
formatDate,
}
};
6 changes: 3 additions & 3 deletions format/filters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const bike = {type: 'BC', mode: 'INC'}
const bike = {type: 'BC', mode: 'INC'};

const accessibility = {
none: {type: 'META', mode: 'INC', meta: 'notBarrierfree'},
partial: {type: 'META', mode: 'INC', meta: 'limitedBarrierfree'},
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'},
}
};

export {
bike,
accessibility,
}
};
6 changes: 3 additions & 3 deletions format/lines-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const formatLinesReq = (ctx, query) => {
req: {
input: query,
},
}
}
};
};

export {
formatLinesReq,
}
};
8 changes: 4 additions & 4 deletions format/location-filter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const formatLocationFilter = (stops, addresses, poi) => {
if (stops && addresses && poi) {
return 'ALL'
return 'ALL';
}
return (stops
? 'S'
: '') + (addresses
? 'A'
: '') + (poi
? 'P'
: '')
}
: '');
};

export {
formatLocationFilter,
}
};
14 changes: 7 additions & 7 deletions format/location-identifier.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const sep = '@'
const sep = '@';

const formatLocationIdentifier = (data) => {
let str = ''
let str = '';
for (let key in data) {
if (!Object.prototype.hasOwnProperty.call(data, key)) {
continue
continue;
}

str += key + '=' + data[key] + sep // todo: escape, but how?
str += key + '=' + data[key] + sep; // todo: escape, but how?
}

return str
}
return str;
};

export {
formatLocationIdentifier,
}
};
18 changes: 9 additions & 9 deletions format/location.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) {
return profile.formatStation(l)
return profile.formatStation(l);
}
if ('object' === typeof l && !Array.isArray(l)) {
if (l.type === 'station' || l.type === 'stop') {
return profile.formatStation(l.id)
return profile.formatStation(l.id);
}
if (l.poi) {
return profile.formatPoi(l)
return profile.formatPoi(l);
}
if ('string' === typeof l.address) {
return profile.formatAddress(l)
return profile.formatAddress(l);
}
if (!l.type) {
throw new TypeError(`missing ${name}.type`)
throw new TypeError(`missing ${name}.type`);
}
throw new TypeError(`invalid ${name}.type: ${l.type}`)
throw new TypeError(`invalid ${name}.type: ${l.type}`);
}
throw new TypeError(name + ': valid station, address or poi required.')
}
throw new TypeError(name + ': valid station, address or poi required.');
};

export {
formatLocation,
}
};
8 changes: 4 additions & 4 deletions format/locations-req.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatLocationsReq = (ctx, query) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
cfg: {polyEnc: 'GPA'},
Expand All @@ -14,9 +14,9 @@ const formatLocationsReq = (ctx, query) => {
maxLoc: opt.results,
field: 'S', // todo: what is this?
}},
}
}
};
};

export {
formatLocationsReq,
}
};
8 changes: 4 additions & 4 deletions format/nearby-req.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatNearbyReq = (ctx, location) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
cfg: {polyEnc: 'GPA'},
Expand All @@ -20,9 +20,9 @@ const formatNearbyReq = (ctx, location) => {
getStops: Boolean(opt.stops),
maxLoc: opt.results,
},
}
}
};
};

export {
formatNearbyReq,
}
};
12 changes: 6 additions & 6 deletions format/poi.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
import {formatLocationIdentifier} from './location-identifier.js';
import {formatCoord} from './coord.js';

const formatPoi = (p) => {
// todo: use Number.isFinite()!
if (p.type !== 'location' || !p.latitude || !p.longitude || !p.id || !p.name) {
throw new TypeError('invalid POI')
throw new TypeError('invalid POI');
}

return {
Expand All @@ -17,9 +17,9 @@ const formatPoi = (p) => {
X: formatCoord(p.longitude),
Y: formatCoord(p.latitude),
}),
}
}
};
};

export {
formatPoi,
}
};
36 changes: 18 additions & 18 deletions format/products-filter.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import isObj from 'lodash/isObject.js'
import isObj from 'lodash/isObject.js';

const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k);

const formatProductsFilter = (ctx, filter) => {
if (!isObj(filter)) {
throw new TypeError('products filter must be an object')
throw new TypeError('products filter must be an object');
}
const {profile} = ctx
const {profile} = ctx;

const byProduct = {}
const defaultProducts = {}
const byProduct = {};
const defaultProducts = {};
for (let product of profile.products) {
byProduct[product.id] = product
defaultProducts[product.id] = product.default
byProduct[product.id] = product;
defaultProducts[product.id] = product.default;
}
filter = Object.assign({}, defaultProducts, filter)
filter = Object.assign({}, defaultProducts, filter);

let res = 0, products = 0
let res = 0, products = 0;
for (let product in filter) {
if (!hasProp(filter, product) || filter[product] !== true) {
continue
continue;
}
if (!byProduct[product]) {
throw new TypeError('unknown product ' + product)
throw new TypeError('unknown product ' + product);
}
products++
products++;
for (let bitmask of byProduct[product].bitmasks) {
res = res | bitmask
res = res | bitmask;
}
}
if (products === 0) {
throw new Error('no products used')
throw new Error('no products used');
}

return {
type: 'PROD',
mode: 'INC',
value: String(res),
}
}
};
};

export {
formatProductsFilter,
}
};
8 changes: 4 additions & 4 deletions format/radar-req.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatRadarReq = (ctx, north, west, south, east) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
meth: 'JourneyGeoPos',
Expand All @@ -21,9 +21,9 @@ const formatRadarReq = (ctx, north, west, south, east) => {
// - CALC_REPORT (as seen in the INSA Young app)
trainPosMode: 'CALC',
},
}
}
};
};

export {
formatRadarReq,
}
};
8 changes: 4 additions & 4 deletions format/reachable-from-req.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatReachableFromReq = (ctx, address) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
meth: 'LocGeoReach',
Expand All @@ -16,9 +16,9 @@ const formatReachableFromReq = (ctx, address) => {
profile.formatProductsFilter(ctx, opt.products || {}),
],
},
}
}
};
};

export {
formatReachableFromReq,
}
};
Loading

0 comments on commit 22441fd

Please sign in to comment.