{"version":3,"file":"dcat-state-to-csl.mjs","sources":["../../../lib/citation/plugins/dcat-state-to-csl.ts"],"sourcesContent":["// @ts-nocheck\nimport dgs from './dg';\n\n/**\n * Regex check for DOI\n * @param {String} doi the given string to check\n * @returns true, if doi is a DOI\n */\nfunction checkDoi(doi = '') {\n  return doi.match(/^10\\.\\d{4,9}\\/[-._;()/:A-Z0-9]+$/i);\n}\n\n/**\n * Regex check for pURI (EU Persistent URI)\n * @param {String} puri the given string to check\n * @returns true, if puri is a pURI\n */\nfunction checkpUri(puri = '') {\n  return puri.match(/^http:\\/\\/data\\.europa\\.eu(\\/[^/]+){1,3}\\/?$/i);\n}\n\nfunction dcatStateToCsl(state) {\n  // eslint-disable-next-line no-underscore-dangle\n  const meta = state.__meta;\n  let doi;\n\n  // If there is a DOI, return it directly for DOI content negotiation\n  if (state.admsIdentifiers) {\n    // check if there is a DOI\n    const admsIdentifier = state.admsIdentifiers.find(({ identifier }) => checkDoi(identifier));\n    doi = admsIdentifier && admsIdentifier.identifier;\n\n    // return doi to let citation-js do their work\n    if (!meta.skipDoiNegotiation && doi) return doi;\n  }\n\n  // If there is no DOI, create CSL object\n\n  // Selected language and URL\n  const lang = meta && (meta.lang || 'en');\n  const URL = state.identifiers.find(checkpUri)\n   || (meta && (meta.url || ''));\n\n  // EUROSTAT identifier\n  // Match all strings that are not pURI or DOI\n  const hasPublisher = state.publisher && state.publisher.name;\n  const publisherTrimmed = (hasPublisher && state.publisher.name.trim().toLowerCase()) || '';\n  const isEurostat = publisherTrimmed === 'eurostat';\n  const eurostatId = isEurostat\n    ? state.identifiers.find(\n      identifier => !checkDoi(identifier) && !checkpUri(identifier),\n    )\n    : null;\n\n  // Creator\n  const author = state.creator?.name && [{ literal: state.creator?.name }];\n\n  // Provider\n  // If publisher is in DG, prepend 'European Commission, ' before it\n  const EUROPEAN_COMISSION = 'European Commission';\n  const isDg = dgs.map(dg => dg.toLowerCase()).includes(publisherTrimmed);\n  let publisher = isDg\n    ? `${EUROPEAN_COMISSION}, ${state.publisher.name}`\n    : state.publisher.name;\n  // If author and publisher are identical, remove publisher;\n  publisher = publisher === author ? null : publisher;\n\n  // Date\n  // If there are both release date and modification date available, prefer\n  // modification date as the issued date.\n  const issuedDate = state.modificationDate || state.releaseDate\n    ? new Date(state.modificationDate || state.releaseDate)\n    : null;\n\n  // take release date as original date only if there's both release and\n  // modification date available\n  const originalDate = state.modificationDate && state.releaseDate\n    ? new Date(state.releaseDate)\n    : null;\n\n  const date = {\n    ...(issuedDate && {\n      issued: {\n        'date-parts': [[\n          issuedDate.getFullYear(),\n          issuedDate.getMonth() + 1,\n          issuedDate.getDate(),\n        ]],\n      },\n    }),\n    ...(originalDate && {\n      'original-date': {\n        'date-parts': [[\n          originalDate.getFullYear(),\n          originalDate.getMonth() + 1,\n          originalDate.getDate(),\n        ]],\n      },\n    }),\n  };\n\n  const csl = [\n    {\n      type: 'dataset',\n      id:\n        state.admsIdentifiers && state.admsIdentifiers.length > 0\n          ? `https://doi.org/${state.admsIdentifiers[0].identifier}`\n          : state.identifiers[0],\n      categories: state.categories.map(({ label }) => label[lang]) || [],\n      language: lang,\n      author,\n      // contains 'issued' and 'original-date'\n      ...date,\n      // 'original-date': originalDate,\n      abstract: state.description[lang],\n      DOI: state.admsIdentifiers && state.admsIdentifiers.length > 0\n        ? doi || state.admsIdentifiers\n        : undefined,\n      publisher,\n      title: state.title[lang],\n      'title-short': eurostatId || undefined,\n      URL,\n      version: state.versionInfo,\n    },\n  ];\n  return csl;\n}\n\nexport default function install(plugins: typeof import('@citation-js/core').plugins) {\n  // Add custom Vuex DatasetDetails state parser to citation-js\n  plugins.input.add('@piveau/dcat-state', {\n    parse: dcatStateToCsl,\n  });\n}\n"],"names":["checkDoi","doi","checkpUri","puri","dcatStateToCsl","state","meta","admsIdentifier","identifier","lang","URL","publisherTrimmed","eurostatId","author","_a","_b","EUROPEAN_COMISSION","publisher","dgs","dg","issuedDate","originalDate","date","label","install","plugins"],"mappings":";AAQA,SA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