-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
interface LocationReference { | ||
_ref: string; | ||
_type: string; | ||
title?: string; | ||
} | ||
export interface DocumentWithLocation { | ||
location: LocationReference; | ||
} | ||
/** | ||
* Checks for duplicate location references in the documents array. | ||
* Ensures each location has a unique document entry. | ||
* | ||
* @param {DocumentWithLocation[] | undefined} documents - The array of documents, each with one or more locations. | ||
* @returns {string | true} - Returns an error message if duplicate locations are found, or true if all are unique. | ||
*/ | ||
export const checkForDuplicateLocations = ( | ||
documents: DocumentWithLocation[] | undefined, | ||
): boolean => { | ||
if (!documents) return true; | ||
const locationRefs = documents | ||
.map((entry) => entry.location?._ref) | ||
.filter(Boolean); | ||
const uniqueRefs = new Set(locationRefs); | ||
return uniqueRefs.size === locationRefs.length; | ||
}; | ||
_ref: string; | ||
_type: string; | ||
title?: string; | ||
} | ||
|
||
export interface DocumentWithLocation { | ||
location: LocationReference; | ||
} | ||
|
||
/** | ||
* Checks for duplicate location references in the documents array. | ||
* Ensures each location has a unique document entry. | ||
* | ||
* @param {DocumentWithLocation[] | undefined} documents - The array of documents, each with one or more locations. | ||
* @returns {string | true} - Returns an error message if duplicate locations are found, or true if all are unique. | ||
*/ | ||
export const checkForDuplicateLocations = ( | ||
documents: DocumentWithLocation[] | undefined, | ||
): boolean => { | ||
if (!documents) return true; | ||
const locationRefs = documents | ||
.map((entry) => entry.location?._ref) | ||
.filter(Boolean); | ||
const uniqueRefs = new Set(locationRefs); | ||
return uniqueRefs.size === locationRefs.length; | ||
}; |