Skip to content

Commit

Permalink
extract remove period method to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Dec 13, 2024
1 parent 9d59194 commit 78cf12c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/elasticsearch/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const util = require('../util')

// Configure search scopes:
const SEARCH_SCOPES = {
all: {
Expand Down Expand Up @@ -78,17 +80,11 @@ const FILTER_CONFIG = {
owner: { operator: 'match', field: ['items.owner.id', 'items.owner.label'], repeatable: true, path: 'items' },
subjectLiteral: {
transform: (val, logger) => {
const removePeriod = (x) => {
if (x.slice(-1) === '.') {
logger.debug('Removing terminal period', JSON.stringify(val, null, 4))
return x.slice(0, -1)
} else return x
}
if (typeof val === 'string') {
return removePeriod(val)
return util.removeTrailingPeriod(val, logger)
}
if (Array.isArray(val)) {
return val.map(removePeriod)
return val.map((val) => util.removeTrailingPeriod(val, logger))
}
},
operator: 'match',
Expand Down
7 changes: 7 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const logger = require('./logger')
const { isItemNyplOwned } = require('./ownership_determination')

exports.removeTrailingPeriod = (x, logger) => {
if (x.slice(-1) === '.') {
logger.debug('Removing terminal period', JSON.stringify(x, null, 4))
return x.slice(0, -1)
} else return x
}

exports.sortOnPropWithUndefinedLast = (property) => {
return function (a, b) {
// equal items sort equally
Expand Down

0 comments on commit 78cf12c

Please sign in to comment.