Skip to content

Commit

Permalink
refactor: simplify regex #442
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Dec 16, 2024
1 parent 8928d34 commit e19d0d3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/Fields/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export default defineNuxtComponent({
"
:href="properties[field.field]"
class="d-inline-block pa-2 rounded-lg"
:style="{ color: '#ffffff' }"
:style="{ backgroundColor: colorfill, color: '#ffffff' }"
>
<FontAwesomeIcon icon="arrow-circle-down" />
{{ fieldTranslateK(field.field) }}
Expand Down
2 changes: 1 addition & 1 deletion pages/embedded.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { $trackingInit } = useNuxtApp()
const boundaryGeojson = ref<Polygon | MultiPolygon>()
const poiId = ref<string>()
const categoryIds = ref<number[]>()
const categoryIdsRegex = /^(?:(?<cartocode>cartocode:[a-zA-Z0-9]{2})|(?<reference>ref:[a-z0-9-]+:[a-zA-Z0-9]+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const categoryIdsRegex = /^(?:(?<cartocode>cartocode:\w{2})|(?<reference>ref:[\w-]+:\w+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
//
// Hooks
Expand Down
4 changes: 2 additions & 2 deletions pages/embedded/[p1]/[poiId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
definePageMeta({
validate: ({ params }) => {
const regexForCategoryIds = /^(?:(?<cartocode>cartocode:[a-zA-Z0-9]{2})|(?<reference>ref:[a-z0-9-]+:[a-zA-Z0-9]+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const regexForPOIIds = /^(?:cartocode:[a-zA-Z0-9]{2}|ref:[a-z0-9-]+:[a-zA-Z0-9]+|osm:[nwr]\d+|\d+)$/
const regexForCategoryIds = /^(?:(?<cartocode>cartocode:\w{2})|(?<reference>ref:[\w-]+:\w+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const regexForPOIIds = /^(?:cartocode:\w{2}|ref:[\w-]+:\w+|osm:[nwr]\d+|\d+)$/
const match = params.p1.toString().match(regexForCategoryIds)
if (match?.groups && (match.groups.cartocode || match.groups.reference || match.groups.osm)) {
Expand Down
2 changes: 1 addition & 1 deletion pages/embedded/[p1]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
definePageMeta({
validate: ({ params }) => {
const regexForIds = /^(?:cartocode:[a-zA-Z0-9]{2}|ref:[a-z0-9-]+:[a-zA-Z0-9]+|osm:[nwr]\d+|\d+(?:,\d+)*)$/
const regexForIds = /^(?:cartocode:\w{2}|ref:[\w-]+:\w+|osm:[nwr]\d+|\d+(?:,\d+)*)$/
return regexForIds.test(params.p1.toString())
},
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { $trackingInit } = useNuxtApp()
const boundaryGeojson = ref<Polygon | MultiPolygon>()
const poiId = ref<string>()
const categoryIds = ref<number[]>()
const categoryIdsRegex = /^(?:(?<cartocode>cartocode:[a-zA-Z0-9]{2})|(?<reference>ref:[a-z0-9-]+:[a-zA-Z0-9]+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const categoryIdsRegex = /^(?:(?<cartocode>cartocode:\w{2})|(?<reference>ref:[\w-]+:\w+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
//
// Hooks
Expand Down
4 changes: 2 additions & 2 deletions pages/index/[p1]/[poiId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
definePageMeta({
validate: ({ params }) => {
const regexForCategoryIds = /^(?:(?<cartocode>cartocode:[a-zA-Z0-9]{2})|(?<reference>ref:[a-z0-9-]+:[a-zA-Z0-9]+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const regexForPOIIds = /^(?:cartocode:[a-zA-Z0-9]{2}|ref:[a-z0-9-]+:[a-zA-Z0-9]+|osm:[nwr]\d+|\d+)$/
const regexForCategoryIds = /^(?:(?<cartocode>cartocode:\w{2})|(?<reference>ref:[\w-]+:\w+)|(?<osm>osm:[nwr]\d+)|\d+(?:,\d+)*)$/
const regexForPOIIds = /^(?:cartocode:\w{2}|ref:[\w-]+:\w+|osm:[nwr]\d+|\d+)$/
const match = params.p1.toString().match(regexForCategoryIds)
if (match?.groups && (match.groups.cartocode || match.groups.reference || match.groups.osm)) {
Expand Down
2 changes: 1 addition & 1 deletion pages/index/[p1]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
definePageMeta({
validate: ({ params }) => {
const regexForIds = /^(?:cartocode:[a-zA-Z0-9]{2}|ref:[a-z0-9-]+:[a-zA-Z0-9]+|osm:[nwr]\d+|\d+(?:,\d+)*)$/
const regexForIds = /^(?:cartocode:\w{2}|ref:[\w-]+:\w+|osm:[nwr]\d+|\d+(?:,\d+)*)$/
return regexForIds.test(params.p1.toString())
},
Expand Down

0 comments on commit e19d0d3

Please sign in to comment.