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

* Replace lodash by built-in functions

* .flatMap -> .flat
This commit is contained in:
Kristjan ESPERANTO 2025-03-01 17:30:58 +01:00 committed by GitHub
parent 185870db3d
commit 53b385a865
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 11 additions and 12 deletions

View file

@ -29,6 +29,7 @@ const config = [
'@stylistic/multiline-comment-style': 'off',
'@stylistic/multiline-ternary': ['error', 'always-multiline'],
'@stylistic/newline-per-chained-call': ['error', {ignoreChainWithDepth: 1}],
'@stylistic/no-extra-parens': 'off',
'@stylistic/no-mixed-operators': 'off',
'@stylistic/no-tabs': 'off',
'@stylistic/object-property-newline': 'off',

View file

@ -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);

View file

@ -1,9 +1,10 @@
import isObj from 'lodash/isObject.js';
import distance from 'gps-distance';
import {defaultProfile} from './lib/default-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
const FORBIDDEN_USER_AGENTS = [
'my-awesome-program', // previously used in readme.md, p/*/readme.md & docs/*.md

2
package-lock.json generated
View file

@ -14,7 +14,6 @@
"db-hafas-stations": "^1.0.0",
"gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.0",
"lodash": "^4.17.5",
"luxon": "^3.1.1",
"qs": "^6.6.0",
"slugg": "^1.2.0",
@ -4867,6 +4866,7 @@
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash-es": {

View file

@ -61,7 +61,6 @@
"db-hafas-stations": "^1.0.0",
"gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.0",
"lodash": "^4.17.5",
"luxon": "^3.1.1",
"qs": "^6.6.0",
"slugg": "^1.2.0",

View file

@ -1,11 +1,11 @@
import maxBy from 'lodash/maxBy.js';
const parsePolyline = (ctx, p) => { // p = raw polylineGroup
const desc = p.polylineDescriptions || p.polylineDesc;
if (desc.length < 1) {
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) {
return null;
}

View file

@ -1,8 +1,6 @@
import flatMap from 'lodash/flatMap.js';
const parseRemarks = (ctx, ref) => {
// TODO ereignisZusammenfassung, priorisierteMeldungen?
return flatMap([
return [
ref.disruptions || [],
ref.risNotizen || [],
ref.echtzeitNotizen && ref.echtzeitNotizen.map(e => {
@ -18,7 +16,7 @@ const parseRemarks = (ctx, ref) => {
ref.attributNotizen || [],
ref.attributes || [],
ref.verkehrsmittel?.zugattribute || [],
])
].flat()
.map(remark => {
if (remark.kategorie || remark.priority) {
const res = ctx.profile.parseHintByCode(remark);