UNPKG

680 BJavaScriptView Raw
1import { VALID_PLACEMENTS } from './config.js';
2export const plugin = async (schema, documents, config) => {
3 const placement = config.placement || 'prepend';
4 const { content } = config;
5 if (!VALID_PLACEMENTS.includes(placement)) {
6 throw Error(`Configuration provided for 'add' plugin is invalid: value of 'placement' field is not valid (valid values are: ${VALID_PLACEMENTS.join(', ')})`);
7 }
8 if (!content) {
9 throw Error(`Configuration provided for 'add' plugin is invalid: "content" is missing!`);
10 }
11 return {
12 content: null,
13 [placement]: Array.isArray(content) ? content : [content],
14 };
15};
16export default { plugin };