mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
Replace lodash by modern JavaScript functions (#20)
Some checks are pending
test / lint (push) Waiting to run
test / unit-tests (18.x) (push) Waiting to run
test / unit-tests (20.x) (push) Waiting to run
test / unit-tests (22.x) (push) Waiting to run
test / integration-tests (18.x) (push) Waiting to run
test / integration-tests (20.x) (push) Waiting to run
test / integration-tests (22.x) (push) Waiting to run
test / e2e-tests (18.x) (push) Blocked by required conditions
Some checks are pending
test / lint (push) Waiting to run
test / unit-tests (18.x) (push) Waiting to run
test / unit-tests (20.x) (push) Waiting to run
test / unit-tests (22.x) (push) Waiting to run
test / integration-tests (18.x) (push) Waiting to run
test / integration-tests (20.x) (push) Waiting to run
test / integration-tests (22.x) (push) Waiting to run
test / e2e-tests (18.x) (push) Blocked by required conditions
* Replace lodash by built-in functions * .flatMap -> .flat
This commit is contained in:
parent
185870db3d
commit
53b385a865
8 changed files with 11 additions and 12 deletions
|
@ -29,6 +29,7 @@ const config = [
|
||||||
'@stylistic/multiline-comment-style': 'off',
|
'@stylistic/multiline-comment-style': 'off',
|
||||||
'@stylistic/multiline-ternary': ['error', 'always-multiline'],
|
'@stylistic/multiline-ternary': ['error', 'always-multiline'],
|
||||||
'@stylistic/newline-per-chained-call': ['error', {ignoreChainWithDepth: 1}],
|
'@stylistic/newline-per-chained-call': ['error', {ignoreChainWithDepth: 1}],
|
||||||
|
'@stylistic/no-extra-parens': 'off',
|
||||||
'@stylistic/no-mixed-operators': 'off',
|
'@stylistic/no-mixed-operators': 'off',
|
||||||
'@stylistic/no-tabs': 'off',
|
'@stylistic/no-tabs': 'off',
|
||||||
'@stylistic/object-property-newline': 'off',
|
'@stylistic/object-property-newline': 'off',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import isObj from 'lodash/isObject.js';
|
const isObj = element => element !== null && 'object' === typeof element && !Array.isArray(element);
|
||||||
|
|
||||||
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||||
|
|
||||||
|
|
3
index.js
3
index.js
|
@ -1,9 +1,10 @@
|
||||||
import isObj from 'lodash/isObject.js';
|
|
||||||
import distance from 'gps-distance';
|
import distance from 'gps-distance';
|
||||||
|
|
||||||
import {defaultProfile} from './lib/default-profile.js';
|
import {defaultProfile} from './lib/default-profile.js';
|
||||||
import {validateProfile} from './lib/validate-profile.js';
|
import {validateProfile} from './lib/validate-profile.js';
|
||||||
|
|
||||||
|
const isObj = element => element !== null && 'object' === typeof element && !Array.isArray(element);
|
||||||
|
|
||||||
// background info: https://github.com/public-transport/hafas-client/issues/286
|
// background info: https://github.com/public-transport/hafas-client/issues/286
|
||||||
const FORBIDDEN_USER_AGENTS = [
|
const FORBIDDEN_USER_AGENTS = [
|
||||||
'my-awesome-program', // previously used in readme.md, p/*/readme.md & docs/*.md
|
'my-awesome-program', // previously used in readme.md, p/*/readme.md & docs/*.md
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -14,7 +14,6 @@
|
||||||
"db-hafas-stations": "^1.0.0",
|
"db-hafas-stations": "^1.0.0",
|
||||||
"gps-distance": "0.0.4",
|
"gps-distance": "0.0.4",
|
||||||
"https-proxy-agent": "^7.0.0",
|
"https-proxy-agent": "^7.0.0",
|
||||||
"lodash": "^4.17.5",
|
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"qs": "^6.6.0",
|
"qs": "^6.6.0",
|
||||||
"slugg": "^1.2.0",
|
"slugg": "^1.2.0",
|
||||||
|
@ -4867,6 +4866,7 @@
|
||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/lodash-es": {
|
"node_modules/lodash-es": {
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
"db-hafas-stations": "^1.0.0",
|
"db-hafas-stations": "^1.0.0",
|
||||||
"gps-distance": "0.0.4",
|
"gps-distance": "0.0.4",
|
||||||
"https-proxy-agent": "^7.0.0",
|
"https-proxy-agent": "^7.0.0",
|
||||||
"lodash": "^4.17.5",
|
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"qs": "^6.6.0",
|
"qs": "^6.6.0",
|
||||||
"slugg": "^1.2.0",
|
"slugg": "^1.2.0",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import maxBy from 'lodash/maxBy.js';
|
|
||||||
|
|
||||||
const parsePolyline = (ctx, p) => { // p = raw polylineGroup
|
const parsePolyline = (ctx, p) => { // p = raw polylineGroup
|
||||||
const desc = p.polylineDescriptions || p.polylineDesc;
|
const desc = p.polylineDescriptions || p.polylineDesc;
|
||||||
if (desc.length < 1) {
|
if (desc.length < 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const points = maxBy(desc, d => d.coordinates.length).coordinates; // TODO initial and final poly?
|
const points = desc.reduce((max, d) => (d.coordinates.length > max.coordinates.length ? d : max),
|
||||||
|
).coordinates; // TODO: initial and final poly?
|
||||||
|
|
||||||
if (points.length === 0) {
|
if (points.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import flatMap from 'lodash/flatMap.js';
|
|
||||||
|
|
||||||
const parseRemarks = (ctx, ref) => {
|
const parseRemarks = (ctx, ref) => {
|
||||||
// TODO ereignisZusammenfassung, priorisierteMeldungen?
|
// TODO ereignisZusammenfassung, priorisierteMeldungen?
|
||||||
return flatMap([
|
return [
|
||||||
ref.disruptions || [],
|
ref.disruptions || [],
|
||||||
ref.risNotizen || [],
|
ref.risNotizen || [],
|
||||||
ref.echtzeitNotizen && ref.echtzeitNotizen.map(e => {
|
ref.echtzeitNotizen && ref.echtzeitNotizen.map(e => {
|
||||||
|
@ -18,7 +16,7 @@ const parseRemarks = (ctx, ref) => {
|
||||||
ref.attributNotizen || [],
|
ref.attributNotizen || [],
|
||||||
ref.attributes || [],
|
ref.attributes || [],
|
||||||
ref.verkehrsmittel?.zugattribute || [],
|
ref.verkehrsmittel?.zugattribute || [],
|
||||||
])
|
].flat()
|
||||||
.map(remark => {
|
.map(remark => {
|
||||||
if (remark.kategorie || remark.priority) {
|
if (remark.kategorie || remark.priority) {
|
||||||
const res = ctx.profile.parseHintByCode(remark);
|
const res = ctx.profile.parseHintByCode(remark);
|
||||||
|
|
Loading…
Add table
Reference in a new issue