minor refactoring / renaming

This commit is contained in:
Martin Raifer
2025-02-13 10:55:31 +01:00
parent 55f5a96a42
commit 918522442b

View File

@@ -20,10 +20,6 @@ References:
export function actionReverse(entityID, options) {
var numeric = /^([+\-]?)(?=[\d.])/;
var directionKey = /direction$/;
const keysToKeepUnchanged = [
// https://github.com/openstreetmap/iD/issues/10736
/^red_turn:(right|left)/
];
var keyReplacements = [
[/:right$/, ':left'],
[/:left$/, ':right'],
@@ -44,27 +40,26 @@ export function actionReverse(entityID, options) {
forwards: 'backward',
backwards: 'forward',
};
// For some keys, values like left/right/... don't refer to way direction and thus
// should not be reversed.
//
// If a key matches the key regex and any of the provided context tag sets, it will
// not be reversed.
const keyValuesThatShouldNotBeReversed = [
[
/^.*(_|:)?(description|name|note|website|ref|source|comment|watch|attribution)(_|:)?/,
[{}]
],
// https://github.com/openstreetmap/iD/issues/10128
[
/^side$/,
[{highway: 'cyclist_waiting_aid'}]
],
// Turn lanes are left/right to key (not way) direction - #5674
[
/^turn:lanes:?/,
[{}]
]
// For some tags, keys or values like left/right/ don't refer to
// way direction and thus should not be reversed.
const keysToKeepUnchanged = [
// https://github.com/openstreetmap/iD/issues/10736
/^red_turn:(right|left):?/
];
// If a key matches the key regex and any of the provided context
// tag sets, it will not be reversed.
const keyValuesToKeepUnchanged = [{
keyRegex: /^.*(_|:)?(description|name|note|website|ref|source|comment|watch|attribution)(_|:)?/,
prerequisiteTags: [{}]
}, {
// Turn lanes are left/right to key (not way) direction - #5674
keyRegex: /^turn:lanes:?/,
prerequisiteTags: [{}]
}, {
// https://github.com/openstreetmap/iD/issues/10128
keyRegex: /^side$/,
prerequisiteTags: [{highway: 'cyclist_waiting_aid'}]
}
];
var roleReplacements = {
forward: 'backward',
@@ -113,10 +108,8 @@ export function actionReverse(entityID, options) {
function reverseValue(key, value, includeAbsolute, allTags) {
for (let i = 0; i < keyValuesThatShouldNotBeReversed.length; i++) {
const keyRegex = keyValuesThatShouldNotBeReversed[i][0];
const tagContexts = keyValuesThatShouldNotBeReversed[i][1];
if (keyRegex.test(key) && tagContexts.some(expectedTags =>
for (let { keyRegex, prerequisiteTags } of keyValuesToKeepUnchanged) {
if (keyRegex.test(key) && prerequisiteTags.some(expectedTags =>
Object.entries(expectedTags).every(([k, v]) => {
return allTags[k] && (v === '*' || allTags[k] === v);
})