18 lines
672 B
TypeScript
18 lines
672 B
TypeScript
import { DuplicateCollection } from '../errors';
|
|
import { Collection } from '../collections/config/types';
|
|
|
|
const getDuplicates = (arr) => arr.filter((item, index) => arr.indexOf(item) !== index);
|
|
|
|
const checkDuplicateCollections = (collections: Collection[]): void => {
|
|
const duplicateSlugs = getDuplicates(collections.map((c) => c.slug));
|
|
if (duplicateSlugs.length > 0) {
|
|
throw new DuplicateCollection('slug', duplicateSlugs);
|
|
}
|
|
const duplicateLabels = getDuplicates(collections.map((c) => c.labels.singular));
|
|
if (duplicateLabels.length > 0) {
|
|
throw new DuplicateCollection('label', duplicateLabels);
|
|
}
|
|
};
|
|
|
|
export default checkDuplicateCollections;
|