@citation-js/core
Advanced tools
Comparing version 0.5.7 to 0.6.0
import Cite from './index.js'; | ||
const async = function (data, options, callback) { | ||
function async(data, options, callback) { | ||
if (typeof options === 'function' && !callback) { | ||
@@ -17,4 +17,4 @@ callback = options; | ||
} | ||
}; | ||
} | ||
export default async; |
import Cite from './index.js'; | ||
const currentVersion = function () { | ||
function currentVersion() { | ||
return this.log.length; | ||
}; | ||
} | ||
const retrieveVersion = function (versnum = 1) { | ||
function retrieveVersion(versnum = 1) { | ||
if (versnum <= 0 || versnum > this.currentVersion()) { | ||
@@ -16,17 +16,17 @@ return null; | ||
} | ||
}; | ||
} | ||
const undo = function (number = 1) { | ||
function undo(number = 1) { | ||
return this.retrieveVersion(this.currentVersion() - number); | ||
}; | ||
} | ||
const retrieveLastVersion = function () { | ||
function retrieveLastVersion() { | ||
return this.retrieveVersion(this.currentVersion()); | ||
}; | ||
} | ||
const save = function () { | ||
function save() { | ||
this.log.push([JSON.stringify(this.data), JSON.stringify(this._options)]); | ||
return this; | ||
}; | ||
} | ||
export { currentVersion, retrieveVersion, retrieveLastVersion, undo, save }; |
@@ -9,3 +9,3 @@ import { validateOutputOptions as validate } from './validate.js'; | ||
const options = function (options, log) { | ||
function options(options, log) { | ||
validate(options); | ||
@@ -19,4 +19,4 @@ | ||
return this; | ||
}; | ||
} | ||
export { options, defaultOptions }; |
import { chain as parseInput, chainAsync as parseInputAsync } from '../plugins/input/index.js'; | ||
import fetchId from '../util/fetchId.js'; | ||
const add = function (data, options = {}, log = false) { | ||
function add(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -14,5 +14,5 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
const addAsync = async function (data, options = {}, log = false) { | ||
async function addAsync(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -27,5 +27,5 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
const set = function (data, options = {}, log = false) { | ||
function set(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -37,5 +37,5 @@ this.save(); | ||
return typeof options !== 'boolean' ? this.add(data, options) : this.add(data); | ||
}; | ||
} | ||
const setAsync = async function (data, options = {}, log = false) { | ||
async function setAsync(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -47,5 +47,5 @@ this.save(); | ||
return typeof options !== 'boolean' ? this.addAsync(data, options) : this.addAsync(data); | ||
}; | ||
} | ||
const reset = function (log) { | ||
function reset(log) { | ||
if (log) { | ||
@@ -58,4 +58,4 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
export { add, addAsync, set, setAsync, reset }; |
import { getLabel } from '../plugin-common/output/label.js'; | ||
import { format as getName } from '@citation-js/name'; | ||
const getComparisonValue = function (obj, prop, label = prop === 'label') { | ||
function getComparisonValue(obj, prop, label = prop === 'label') { | ||
let value = label ? getLabel(obj) : obj[prop]; | ||
@@ -28,5 +28,5 @@ | ||
} | ||
}; | ||
} | ||
const compareProp = function (entryA, entryB, prop, flip = /^!/.test(prop)) { | ||
function compareProp(entryA, entryB, prop, flip = /^!/.test(prop)) { | ||
prop = prop.replace(/^!/, ''); | ||
@@ -36,5 +36,5 @@ const a = getComparisonValue(entryA, prop); | ||
return (flip ? -1 : 1) * (a > b ? 1 : a < b ? -1 : 0); | ||
}; | ||
} | ||
const getSortCallback = function (...props) { | ||
function getSortCallback(...props) { | ||
return (a, b) => { | ||
@@ -50,5 +50,5 @@ const keys = props.slice(); | ||
}; | ||
}; | ||
} | ||
const sort = function (method = [], log) { | ||
function sort(method = [], log) { | ||
if (log) { | ||
@@ -60,4 +60,4 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
export { sort }; |
@@ -1,1 +0,3 @@ | ||
export const parse = () => []; | ||
export function parse() { | ||
return []; | ||
} |
import logger from '../../logger.js'; | ||
const substituters = [[/((?:\[|:|,)\s*)'((?:\\'|[^'])*?[^\\])?'(?=\s*(?:\]|}|,))/g, '$1"$2"'], [/((?:(?:"|]|}|\/[gmiuys]|\.|(?:\d|\.|-)*\d)\s*,|{)\s*)(?:"([^":\n]+?)"|'([^":\n]+?)'|([^":\n]+?))(\s*):/g, '$1"$2$3$4"$5:']]; | ||
const parseJSON = function (str) { | ||
function parseJSON(str) { | ||
if (typeof str !== 'string') { | ||
@@ -18,4 +18,4 @@ return JSON.parse(str); | ||
} | ||
}; | ||
} | ||
export { parseJSON as parse, parseJSON as default }; |
@@ -5,5 +5,7 @@ import * as plugins from '../../plugins/index.js'; | ||
const appendCommas = (string, index, array) => string + (index < array.length - 1 ? ',' : ''); | ||
function appendCommas(string, index, array) { | ||
return string + (index < array.length - 1 ? ',' : ''); | ||
} | ||
const getJsonObject = function (src, dict) { | ||
function getJsonObject(src, dict) { | ||
const isArray = Array.isArray(src); | ||
@@ -21,5 +23,5 @@ let entries; | ||
return isArray ? `[${entries}]` : `{${entries}}`; | ||
}; | ||
} | ||
const getJsonValue = function (src, dict) { | ||
function getJsonValue(src, dict) { | ||
if (typeof src === 'object' && src !== null) { | ||
@@ -36,5 +38,5 @@ if (src.length === 0) { | ||
} | ||
}; | ||
} | ||
const getJson = function (src, dict) { | ||
function getJson(src, dict) { | ||
let entries = src.map(entry => getJsonObject(entry, dict)); | ||
@@ -44,3 +46,3 @@ entries = entries.map(appendCommas).map(entry => dict.entry.join(entry)); | ||
return dict.bibliographyContainer.join(`[${entries}]`); | ||
}; | ||
} | ||
@@ -53,4 +55,9 @@ export function getJsonWrapper(src) { | ||
type, | ||
format = type || 'text' | ||
format = type || 'text', | ||
version = '1.0.2' | ||
} = {}) { | ||
if (version < '1.0.2') { | ||
data = util.downgradeCsl(data); | ||
} | ||
if (format === 'object') { | ||
@@ -66,3 +73,9 @@ return util.deepCopy(data); | ||
ndjson(data) { | ||
ndjson(data, { | ||
version = '1.0.2' | ||
} = {}) { | ||
if (version < '1.0.2') { | ||
data = util.downgradeCsl(data); | ||
} | ||
return data.map(entry => JSON.stringify(entry)).join('\n'); | ||
@@ -69,0 +82,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const getLabel = entry => { | ||
function getLabel(entry) { | ||
if ('citation-label' in entry) { | ||
@@ -23,3 +23,3 @@ return entry['citation-label']; | ||
return res; | ||
}; | ||
} | ||
@@ -26,0 +26,0 @@ export { getLabel }; |
const configs = {}; | ||
export const add = (ref, config) => { | ||
export function add(ref, config) { | ||
configs[ref] = config; | ||
}; | ||
export const get = ref => configs[ref]; | ||
export const has = ref => Object.prototype.hasOwnProperty.call(configs, ref); | ||
export const remove = ref => { | ||
} | ||
export function get(ref) { | ||
return configs[ref]; | ||
} | ||
export function has(ref) { | ||
return Object.prototype.hasOwnProperty.call(configs, ref); | ||
} | ||
export function remove(ref) { | ||
delete configs[ref]; | ||
}; | ||
export const list = () => Object.keys(configs); | ||
} | ||
export function list() { | ||
return Object.keys(configs); | ||
} |
import Register from '../util/register.js'; | ||
const validate = (name, dict) => { | ||
function validate(name, dict) { | ||
if (typeof name !== 'string') { | ||
@@ -17,3 +17,3 @@ throw new TypeError(`Invalid dict name, expected string, got ${typeof name}`); | ||
} | ||
}; | ||
} | ||
@@ -34,16 +34,16 @@ export const register = new Register({ | ||
}); | ||
export const add = (name, dict) => { | ||
export function add(name, dict) { | ||
validate(name, dict); | ||
register.set(name, dict); | ||
}; | ||
export const remove = name => { | ||
} | ||
export function remove(name) { | ||
register.remove(name); | ||
}; | ||
export const has = name => { | ||
} | ||
export function has(name) { | ||
return register.has(name); | ||
}; | ||
export const list = () => { | ||
} | ||
export function list() { | ||
return register.list(); | ||
}; | ||
export const get = name => { | ||
} | ||
export function get(name) { | ||
if (!register.has(name)) { | ||
@@ -54,3 +54,3 @@ throw new Error(`Dict "${name}" unavailable`); | ||
return register.get(name); | ||
}; | ||
} | ||
export const htmlDict = { | ||
@@ -57,0 +57,0 @@ wr_start: '<div class="csl-bib-body">', |
@@ -12,3 +12,3 @@ import * as input from './input/index.js'; | ||
const indices = {}; | ||
export const add = (ref, plugins = {}) => { | ||
export function add(ref, plugins = {}) { | ||
const mainIndex = indices[ref] = {}; | ||
@@ -34,4 +34,4 @@ | ||
} | ||
}; | ||
export const remove = ref => { | ||
} | ||
export function remove(ref) { | ||
const mainIndex = indices[ref]; | ||
@@ -48,5 +48,9 @@ | ||
delete indices[ref]; | ||
}; | ||
export const has = ref => ref in indices; | ||
export const list = () => Object.keys(indices); | ||
} | ||
export function has(ref) { | ||
return ref in indices; | ||
} | ||
export function list() { | ||
return Object.keys(indices); | ||
} | ||
export { input, output, dict, config }; |
@@ -1,2 +0,2 @@ | ||
import deepCopy from '../../util/deepCopy.js'; | ||
import { deepCopy, upgradeCsl } from '../../util/index.js'; | ||
import logger from '../../logger.js'; | ||
@@ -76,3 +76,3 @@ import { get as getTypeInfo } from './register.js'; | ||
} else if (this.options.target === '@csl/list+object') { | ||
return this.data.map(this.options.generateGraph ? entry => applyGraph(entry, this.graph) : removeGraph); | ||
return upgradeCsl(this.data).map(this.options.generateGraph ? entry => applyGraph(entry, this.graph) : removeGraph); | ||
} else { | ||
@@ -79,0 +79,0 @@ return this.data; |
@@ -65,15 +65,29 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
author: NAME_LIST, | ||
chair: NAME_LIST, | ||
'collection-editor': NAME_LIST, | ||
compiler: NAME_LIST, | ||
composer: NAME_LIST, | ||
'container-author': NAME_LIST, | ||
contributor: NAME_LIST, | ||
curator: NAME_LIST, | ||
director: NAME_LIST, | ||
editor: NAME_LIST, | ||
'editorial-director': NAME_LIST, | ||
director: NAME_LIST, | ||
'executive-producer': NAME_LIST, | ||
guest: NAME_LIST, | ||
host: NAME_LIST, | ||
interviewer: NAME_LIST, | ||
illustrator: NAME_LIST, | ||
narrator: NAME_LIST, | ||
organizer: NAME_LIST, | ||
'original-author': NAME_LIST, | ||
performer: NAME_LIST, | ||
producer: NAME_LIST, | ||
'reviewed-author': NAME_LIST, | ||
recipient: NAME_LIST, | ||
'script-writer': NAME_LIST, | ||
'series-creator': NAME_LIST, | ||
translator: NAME_LIST, | ||
accessed: DATE, | ||
'available-date': DATE, | ||
container: DATE, | ||
@@ -86,2 +100,3 @@ 'event-date': DATE, | ||
categories: 'object', | ||
custom: 'object', | ||
id: ['string', 'number'], | ||
@@ -94,2 +109,3 @@ language: 'string', | ||
archive: 'string', | ||
archive_collection: 'string', | ||
archive_location: 'string', | ||
@@ -101,2 +117,3 @@ 'archive-place': 'string', | ||
'citation-number': 'string', | ||
'citation-key': 'string', | ||
'citation-label': 'string', | ||
@@ -108,5 +125,7 @@ 'collection-number': 'string', | ||
dimensions: 'string', | ||
division: 'string', | ||
DOI: 'string', | ||
edition: ['string', 'number'], | ||
event: 'string', | ||
'event-title': 'string', | ||
'event-place': 'string', | ||
@@ -131,4 +150,7 @@ 'first-reference-note-number': 'string', | ||
'page-first': 'string', | ||
'part-number': ['string', 'number'], | ||
'part-title': 'string', | ||
PMCID: 'string', | ||
PMID: 'string', | ||
printing: 'string', | ||
publisher: 'string', | ||
@@ -138,2 +160,3 @@ 'publisher-place': 'string', | ||
'reviewed-title': 'string', | ||
'reviewed-genre': 'string', | ||
scale: 'string', | ||
@@ -143,2 +166,3 @@ section: 'string', | ||
status: 'string', | ||
supplement: ['string', 'number'], | ||
title: 'string', | ||
@@ -149,6 +173,8 @@ 'title-short': 'string', | ||
volume: ['string', 'number'], | ||
'volume-title': 'string', | ||
'volume-title-short': 'string', | ||
'year-suffix': 'string' | ||
}; | ||
const correctName = function (name, bestGuessConversions) { | ||
function correctName(name, bestGuessConversions) { | ||
if (typeof name === 'object' && name !== null && (name.literal || name.given || name.family)) { | ||
@@ -161,5 +187,5 @@ return name; | ||
} | ||
}; | ||
} | ||
const correctNameList = function (nameList, bestGuessConversions) { | ||
function correctNameList(nameList, bestGuessConversions) { | ||
if (nameList instanceof Array) { | ||
@@ -169,5 +195,5 @@ const names = nameList.map(name => correctName(name, bestGuessConversions)).filter(Boolean); | ||
} | ||
}; | ||
} | ||
const correctDateParts = function (dateParts, bestGuessConversions) { | ||
function correctDateParts(dateParts, bestGuessConversions) { | ||
if (dateParts.every(part => typeof part === 'number')) { | ||
@@ -180,5 +206,5 @@ return dateParts; | ||
} | ||
}; | ||
} | ||
const correctDate = function (date, bestGuessConversions) { | ||
function correctDate(date, bestGuessConversions) { | ||
const dp = 'date-parts'; | ||
@@ -206,5 +232,5 @@ | ||
} | ||
}; | ||
} | ||
const correctType = function (type, bestGuessConversions) { | ||
function correctType(type, bestGuessConversions) { | ||
type = correctField('language', type, bestGuessConversions); | ||
@@ -219,5 +245,5 @@ | ||
} | ||
}; | ||
} | ||
const correctField = function (fieldName, value, bestGuessConversions) { | ||
function correctField(fieldName, value, bestGuessConversions) { | ||
const fieldType = [].concat(fieldTypes[fieldName]); | ||
@@ -239,5 +265,3 @@ | ||
if (/^_/.test(fieldName)) { | ||
return value; | ||
} else if (bestGuessConversions) { | ||
if (bestGuessConversions) { | ||
if (typeof value === 'string' && fieldType.includes('number') && !fieldType.includes('string') && !isNaN(+value)) { | ||
@@ -255,5 +279,5 @@ return parseFloat(value); | ||
} | ||
}; | ||
} | ||
const parseCsl = function (data, bestGuessConversions = true) { | ||
function parseCsl(data, bestGuessConversions = true) { | ||
return data.map(function (entry) { | ||
@@ -272,4 +296,4 @@ const clean = {}; | ||
}); | ||
}; | ||
} | ||
export { parseCsl as clean }; |
import { chain, chainAsync } from './chain.js'; | ||
const flatten = array => [].concat(...array); | ||
const parsers = {}; | ||
@@ -10,3 +7,3 @@ const asyncParsers = {}; | ||
'@csl/list+object': input => input, | ||
'@else/list+object': input => flatten(input.map(chain)), | ||
'@else/list+object': input => input.map(chain).flat(), | ||
'@invalid': () => { | ||
@@ -17,5 +14,5 @@ throw new Error('This format is not supported or recognized'); | ||
const nativeAsyncParsers = { | ||
'@else/list+object': async input => flatten(await Promise.all(input.map(chainAsync))) | ||
'@else/list+object': async input => (await Promise.all(input.map(chainAsync))).flat() | ||
}; | ||
export const data = (input, type) => { | ||
export function data(input, type) { | ||
if (typeof parsers[type] === 'function') { | ||
@@ -28,4 +25,4 @@ return parsers[type](input); | ||
} | ||
}; | ||
export const dataAsync = async (input, type) => { | ||
} | ||
export async function dataAsync(input, type) { | ||
if (typeof asyncParsers[type] === 'function') { | ||
@@ -40,7 +37,7 @@ return asyncParsers[type](input); | ||
} | ||
}; | ||
export const addDataParser = (format, { | ||
} | ||
export function addDataParser(format, { | ||
parser, | ||
async | ||
}) => { | ||
}) { | ||
if (async) { | ||
@@ -51,7 +48,11 @@ asyncParsers[format] = parser; | ||
} | ||
}; | ||
export const hasDataParser = (type, async) => async ? asyncParsers[type] || nativeAsyncParsers[type] : parsers[type] || nativeParsers[type]; | ||
export const removeDataParser = (type, async) => { | ||
} | ||
export function hasDataParser(type, async) { | ||
return async ? asyncParsers[type] || nativeAsyncParsers[type] : parsers[type] || nativeParsers[type]; | ||
} | ||
export function removeDataParser(type, async) { | ||
delete (async ? asyncParsers : parsers)[type]; | ||
}; | ||
export const listDataParser = async => Object.keys(async ? asyncParsers : parsers); | ||
} | ||
export function listDataParser(async) { | ||
return Object.keys(async ? asyncParsers : parsers); | ||
} |
@@ -1,2 +0,2 @@ | ||
export const typeOf = thing => { | ||
export function typeOf(thing) { | ||
switch (thing) { | ||
@@ -12,4 +12,4 @@ case undefined: | ||
} | ||
}; | ||
export const dataTypeOf = thing => { | ||
} | ||
export function dataTypeOf(thing) { | ||
switch (typeof thing) { | ||
@@ -31,2 +31,2 @@ case 'string': | ||
} | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
export const applyGraph = (entry, graph) => { | ||
export function applyGraph(entry, graph) { | ||
if (entry._graph) { | ||
@@ -14,6 +14,6 @@ const index = graph.findIndex(({ | ||
return entry; | ||
}; | ||
export const removeGraph = entry => { | ||
} | ||
export function removeGraph(entry) { | ||
delete entry._graph; | ||
return entry; | ||
}; | ||
} |
@@ -5,3 +5,3 @@ import { FormatParser } from './parser.js'; | ||
const formats = {}; | ||
export const add = (format, parsers) => { | ||
export function add(format, parsers) { | ||
const formatParser = new FormatParser(format, parsers); | ||
@@ -29,7 +29,7 @@ formatParser.validate(); | ||
} | ||
}; | ||
export const get = format => { | ||
} | ||
export function get(format) { | ||
return formats[format]; | ||
}; | ||
export const remove = format => { | ||
} | ||
export function remove(format) { | ||
const index = formats[format]; | ||
@@ -54,4 +54,8 @@ | ||
delete formats[format]; | ||
}; | ||
export const has = format => format in formats; | ||
export const list = () => Object.keys(formats); | ||
} | ||
export function has(format) { | ||
return format in formats; | ||
} | ||
export function list() { | ||
return Object.keys(formats); | ||
} |
@@ -7,3 +7,3 @@ import logger from '../../logger.js'; | ||
const parseNativeTypes = (input, dataType) => { | ||
function parseNativeTypes(input, dataType) { | ||
switch (dataType) { | ||
@@ -24,5 +24,5 @@ case 'Array': | ||
} | ||
}; | ||
} | ||
const matchType = (typeList = [], data) => { | ||
function matchType(typeList = [], data) { | ||
for (const type of typeList) { | ||
@@ -33,5 +33,5 @@ if (types[type].predicate(data)) { | ||
} | ||
}; | ||
} | ||
export const type = input => { | ||
export function type(input) { | ||
const dataType = dataTypeOf(input); | ||
@@ -45,8 +45,8 @@ | ||
return match || parseNativeTypes(input, dataType); | ||
}; | ||
export const addTypeParser = (format, { | ||
} | ||
export function addTypeParser(format, { | ||
dataType, | ||
predicate, | ||
extends: extend | ||
}) => { | ||
}) { | ||
let extensions = []; | ||
@@ -83,5 +83,7 @@ | ||
} | ||
}; | ||
export const hasTypeParser = type => Object.prototype.hasOwnProperty.call(types, type); | ||
export const removeTypeParser = type => { | ||
} | ||
export function hasTypeParser(type) { | ||
return Object.prototype.hasOwnProperty.call(types, type); | ||
} | ||
export function removeTypeParser(type) { | ||
delete types[type]; | ||
@@ -96,5 +98,7 @@ const typeLists = [...Object.keys(dataTypes).map(key => dataTypes[key]), ...Object.keys(types).map(type => types[type].extensions).filter(list => list.length > 0)]; | ||
}); | ||
}; | ||
export const listTypeParser = () => Object.keys(types); | ||
export const treeTypeParser = () => { | ||
} | ||
export function listTypeParser() { | ||
return Object.keys(types); | ||
} | ||
export function treeTypeParser() { | ||
const attachNode = name => ({ | ||
@@ -112,3 +116,3 @@ name, | ||
}; | ||
}; | ||
} | ||
export const typeMatcher = /^(?:@(.+?))(?:\/(?:(.+?)\+)?(?:(.+)))?$/; |
import Register from '../util/register.js'; | ||
const validate = (name, formatter) => { | ||
function validate(name, formatter) { | ||
if (typeof name !== 'string') { | ||
@@ -9,19 +9,19 @@ throw new TypeError(`Invalid output format name, expected string, got ${typeof name}`); | ||
} | ||
}; | ||
} | ||
export const register = new Register(); | ||
export const add = (name, formatter) => { | ||
export function add(name, formatter) { | ||
validate(name, formatter); | ||
register.set(name, formatter); | ||
}; | ||
export const remove = name => { | ||
} | ||
export function remove(name) { | ||
register.remove(name); | ||
}; | ||
export const has = name => { | ||
} | ||
export function has(name) { | ||
return register.has(name); | ||
}; | ||
export const list = () => { | ||
} | ||
export function list() { | ||
return register.list(); | ||
}; | ||
export const format = (name, data, ...options) => { | ||
} | ||
export function format(name, data, ...options) { | ||
if (!register.has(name)) { | ||
@@ -32,2 +32,2 @@ throw new Error(`Output format "${name}" unavailable`); | ||
return register.get(name)(data, ...options); | ||
}; | ||
} |
import syncFetch from 'sync-fetch'; | ||
import 'isomorphic-fetch'; | ||
import fetchPolyfill from 'fetch-ponyfill'; | ||
import logger from '../logger.js'; | ||
import pkg from '../../package.json'; | ||
const { | ||
fetch, | ||
Headers | ||
} = fetchPolyfill(); | ||
const corsEnabled = typeof location !== 'undefined' && typeof document !== 'undefined'; | ||
@@ -6,0 +10,0 @@ let userAgent = corsEnabled ? '' : `Citation.js/${pkg.version} Node.js/${process.version}`; |
@@ -1,2 +0,2 @@ | ||
const fetchId = function (list, prefix) { | ||
function fetchId(list, prefix) { | ||
let id; | ||
@@ -9,4 +9,4 @@ | ||
return id; | ||
}; | ||
} | ||
export default fetchId; |
@@ -0,1 +1,2 @@ | ||
import { upgradeCsl, downgradeCsl } from './csl.js'; | ||
import deepCopy from './deepCopy.js'; | ||
@@ -8,2 +9,2 @@ import { fetchFile, fetchFileAsync, setUserAgent } from './fetchFile.js'; | ||
import { Translator } from './translator.js'; | ||
export { deepCopy, fetchFile, fetchFileAsync, setUserAgent, fetchId, TokenStack, Register, Grammar, Translator }; | ||
export { upgradeCsl, downgradeCsl, deepCopy, fetchFile, fetchFileAsync, setUserAgent, fetchId, TokenStack, Register, Grammar, Translator }; |
@@ -12,3 +12,3 @@ "use strict"; | ||
const async = function (data, options, callback) { | ||
function async(data, options, callback) { | ||
if (typeof options === 'function' && !callback) { | ||
@@ -27,5 +27,5 @@ callback = options; | ||
} | ||
}; | ||
} | ||
var _default = async; | ||
exports.default = _default; |
@@ -6,3 +6,7 @@ "use strict"; | ||
}); | ||
exports.undo = exports.save = exports.retrieveVersion = exports.retrieveLastVersion = exports.currentVersion = void 0; | ||
exports.currentVersion = currentVersion; | ||
exports.retrieveLastVersion = retrieveLastVersion; | ||
exports.retrieveVersion = retrieveVersion; | ||
exports.save = save; | ||
exports.undo = undo; | ||
@@ -13,9 +17,7 @@ var _index = _interopRequireDefault(require("./index.js")); | ||
const currentVersion = function () { | ||
function currentVersion() { | ||
return this.log.length; | ||
}; | ||
} | ||
exports.currentVersion = currentVersion; | ||
const retrieveVersion = function (versnum = 1) { | ||
function retrieveVersion(versnum = 1) { | ||
if (versnum <= 0 || versnum > this.currentVersion()) { | ||
@@ -29,23 +31,15 @@ return null; | ||
} | ||
}; | ||
} | ||
exports.retrieveVersion = retrieveVersion; | ||
const undo = function (number = 1) { | ||
function undo(number = 1) { | ||
return this.retrieveVersion(this.currentVersion() - number); | ||
}; | ||
} | ||
exports.undo = undo; | ||
const retrieveLastVersion = function () { | ||
function retrieveLastVersion() { | ||
return this.retrieveVersion(this.currentVersion()); | ||
}; | ||
} | ||
exports.retrieveLastVersion = retrieveLastVersion; | ||
const save = function () { | ||
function save() { | ||
this.log.push([JSON.stringify(this.data), JSON.stringify(this._options)]); | ||
return this; | ||
}; | ||
exports.save = save; | ||
} |
@@ -6,3 +6,4 @@ "use strict"; | ||
}); | ||
exports.options = exports.defaultOptions = void 0; | ||
exports.defaultOptions = void 0; | ||
exports.options = options; | ||
@@ -19,3 +20,3 @@ var _validate = require("./validate.js"); | ||
const options = function (options, log) { | ||
function options(options, log) { | ||
(0, _validate.validateOutputOptions)(options); | ||
@@ -29,4 +30,2 @@ | ||
return this; | ||
}; | ||
exports.options = options; | ||
} |
@@ -6,3 +6,7 @@ "use strict"; | ||
}); | ||
exports.setAsync = exports.set = exports.reset = exports.addAsync = exports.add = void 0; | ||
exports.add = add; | ||
exports.addAsync = addAsync; | ||
exports.reset = reset; | ||
exports.set = set; | ||
exports.setAsync = setAsync; | ||
@@ -15,3 +19,3 @@ var _index = require("../plugins/input/index.js"); | ||
const add = function (data, options = {}, log = false) { | ||
function add(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -26,7 +30,5 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
exports.add = add; | ||
const addAsync = async function (data, options = {}, log = false) { | ||
async function addAsync(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -41,7 +43,5 @@ this.save(); | ||
return this; | ||
}; | ||
} | ||
exports.addAsync = addAsync; | ||
const set = function (data, options = {}, log = false) { | ||
function set(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -53,7 +53,5 @@ this.save(); | ||
return typeof options !== 'boolean' ? this.add(data, options) : this.add(data); | ||
}; | ||
} | ||
exports.set = set; | ||
const setAsync = async function (data, options = {}, log = false) { | ||
async function setAsync(data, options = {}, log = false) { | ||
if (options === true || log === true) { | ||
@@ -65,7 +63,5 @@ this.save(); | ||
return typeof options !== 'boolean' ? this.addAsync(data, options) : this.addAsync(data); | ||
}; | ||
} | ||
exports.setAsync = setAsync; | ||
const reset = function (log) { | ||
function reset(log) { | ||
if (log) { | ||
@@ -78,4 +74,2 @@ this.save(); | ||
return this; | ||
}; | ||
exports.reset = reset; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.sort = void 0; | ||
exports.sort = sort; | ||
@@ -13,3 +13,3 @@ var _label = require("../plugin-common/output/label.js"); | ||
const getComparisonValue = function (obj, prop, label = prop === 'label') { | ||
function getComparisonValue(obj, prop, label = prop === 'label') { | ||
let value = label ? (0, _label.getLabel)(obj) : obj[prop]; | ||
@@ -38,5 +38,5 @@ | ||
} | ||
}; | ||
} | ||
const compareProp = function (entryA, entryB, prop, flip = /^!/.test(prop)) { | ||
function compareProp(entryA, entryB, prop, flip = /^!/.test(prop)) { | ||
prop = prop.replace(/^!/, ''); | ||
@@ -46,5 +46,5 @@ const a = getComparisonValue(entryA, prop); | ||
return (flip ? -1 : 1) * (a > b ? 1 : a < b ? -1 : 0); | ||
}; | ||
} | ||
const getSortCallback = function (...props) { | ||
function getSortCallback(...props) { | ||
return (a, b) => { | ||
@@ -60,5 +60,5 @@ const keys = props.slice(); | ||
}; | ||
}; | ||
} | ||
const sort = function (method = [], log) { | ||
function sort(method = [], log) { | ||
if (log) { | ||
@@ -70,4 +70,2 @@ this.save(); | ||
return this; | ||
}; | ||
exports.sort = sort; | ||
} |
@@ -6,6 +6,6 @@ "use strict"; | ||
}); | ||
exports.parse = void 0; | ||
exports.parse = parse; | ||
const parse = () => []; | ||
exports.parse = parse; | ||
function parse() { | ||
return []; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.parse = exports.default = void 0; | ||
exports.default = exports.parse = parseJSON; | ||
@@ -15,3 +15,3 @@ var _logger = _interopRequireDefault(require("../../logger.js")); | ||
const parseJSON = function (str) { | ||
function parseJSON(str) { | ||
if (typeof str !== 'string') { | ||
@@ -31,4 +31,2 @@ return JSON.parse(str); | ||
} | ||
}; | ||
exports.default = exports.parse = parseJSON; | ||
} |
@@ -21,5 +21,7 @@ "use strict"; | ||
const appendCommas = (string, index, array) => string + (index < array.length - 1 ? ',' : ''); | ||
function appendCommas(string, index, array) { | ||
return string + (index < array.length - 1 ? ',' : ''); | ||
} | ||
const getJsonObject = function (src, dict) { | ||
function getJsonObject(src, dict) { | ||
const isArray = Array.isArray(src); | ||
@@ -37,5 +39,5 @@ let entries; | ||
return isArray ? `[${entries}]` : `{${entries}}`; | ||
}; | ||
} | ||
const getJsonValue = function (src, dict) { | ||
function getJsonValue(src, dict) { | ||
if (typeof src === 'object' && src !== null) { | ||
@@ -52,5 +54,5 @@ if (src.length === 0) { | ||
} | ||
}; | ||
} | ||
const getJson = function (src, dict) { | ||
function getJson(src, dict) { | ||
let entries = src.map(entry => getJsonObject(entry, dict)); | ||
@@ -60,3 +62,3 @@ entries = entries.map(appendCommas).map(entry => dict.entry.join(entry)); | ||
return dict.bibliographyContainer.join(`[${entries}]`); | ||
}; | ||
} | ||
@@ -70,4 +72,9 @@ function getJsonWrapper(src) { | ||
type, | ||
format = type || 'text' | ||
format = type || 'text', | ||
version = '1.0.2' | ||
} = {}) { | ||
if (version < '1.0.2') { | ||
data = util.downgradeCsl(data); | ||
} | ||
if (format === 'object') { | ||
@@ -84,3 +91,9 @@ return util.deepCopy(data); | ||
ndjson(data) { | ||
ndjson(data, { | ||
version = '1.0.2' | ||
} = {}) { | ||
if (version < '1.0.2') { | ||
data = util.downgradeCsl(data); | ||
} | ||
return data.map(entry => JSON.stringify(entry)).join('\n'); | ||
@@ -87,0 +100,0 @@ } |
@@ -6,5 +6,6 @@ "use strict"; | ||
}); | ||
exports.getLabel = exports.default = void 0; | ||
exports.default = void 0; | ||
exports.getLabel = getLabel; | ||
const getLabel = entry => { | ||
function getLabel(entry) { | ||
if ('citation-label' in entry) { | ||
@@ -31,5 +32,4 @@ return entry['citation-label']; | ||
return res; | ||
}; | ||
} | ||
exports.getLabel = getLabel; | ||
var _default = { | ||
@@ -36,0 +36,0 @@ label(data) { |
@@ -6,27 +6,27 @@ "use strict"; | ||
}); | ||
exports.remove = exports.list = exports.has = exports.get = exports.add = void 0; | ||
exports.add = add; | ||
exports.get = get; | ||
exports.has = has; | ||
exports.list = list; | ||
exports.remove = remove; | ||
const configs = {}; | ||
const add = (ref, config) => { | ||
function add(ref, config) { | ||
configs[ref] = config; | ||
}; | ||
} | ||
exports.add = add; | ||
function get(ref) { | ||
return configs[ref]; | ||
} | ||
const get = ref => configs[ref]; | ||
function has(ref) { | ||
return Object.prototype.hasOwnProperty.call(configs, ref); | ||
} | ||
exports.get = get; | ||
const has = ref => Object.prototype.hasOwnProperty.call(configs, ref); | ||
exports.has = has; | ||
const remove = ref => { | ||
function remove(ref) { | ||
delete configs[ref]; | ||
}; | ||
} | ||
exports.remove = remove; | ||
const list = () => Object.keys(configs); | ||
exports.list = list; | ||
function list() { | ||
return Object.keys(configs); | ||
} |
@@ -6,3 +6,10 @@ "use strict"; | ||
}); | ||
exports.textDict = exports.remove = exports.register = exports.list = exports.htmlDict = exports.has = exports.get = exports.add = void 0; | ||
exports.add = add; | ||
exports.get = get; | ||
exports.has = has; | ||
exports.htmlDict = void 0; | ||
exports.list = list; | ||
exports.register = void 0; | ||
exports.remove = remove; | ||
exports.textDict = void 0; | ||
@@ -13,3 +20,3 @@ var _register = _interopRequireDefault(require("../util/register.js")); | ||
const validate = (name, dict) => { | ||
function validate(name, dict) { | ||
if (typeof name !== 'string') { | ||
@@ -28,3 +35,3 @@ throw new TypeError(`Invalid dict name, expected string, got ${typeof name}`); | ||
} | ||
}; | ||
} | ||
@@ -47,28 +54,20 @@ const register = new _register.default({ | ||
const add = (name, dict) => { | ||
function add(name, dict) { | ||
validate(name, dict); | ||
register.set(name, dict); | ||
}; | ||
} | ||
exports.add = add; | ||
const remove = name => { | ||
function remove(name) { | ||
register.remove(name); | ||
}; | ||
} | ||
exports.remove = remove; | ||
const has = name => { | ||
function has(name) { | ||
return register.has(name); | ||
}; | ||
} | ||
exports.has = has; | ||
const list = () => { | ||
function list() { | ||
return register.list(); | ||
}; | ||
} | ||
exports.list = list; | ||
const get = name => { | ||
function get(name) { | ||
if (!register.has(name)) { | ||
@@ -79,5 +78,4 @@ throw new Error(`Dict "${name}" unavailable`); | ||
return register.get(name); | ||
}; | ||
} | ||
exports.get = get; | ||
const htmlDict = { | ||
@@ -84,0 +82,0 @@ wr_start: '<div class="csl-bib-body">', |
@@ -6,3 +6,9 @@ "use strict"; | ||
}); | ||
exports.remove = exports.output = exports.list = exports.input = exports.has = exports.dict = exports.config = exports.add = void 0; | ||
exports.add = add; | ||
exports.dict = exports.config = void 0; | ||
exports.has = has; | ||
exports.input = void 0; | ||
exports.list = list; | ||
exports.output = void 0; | ||
exports.remove = remove; | ||
@@ -37,3 +43,3 @@ var input = _interopRequireWildcard(require("./input/index.js")); | ||
const add = (ref, plugins = {}) => { | ||
function add(ref, plugins = {}) { | ||
const mainIndex = indices[ref] = {}; | ||
@@ -59,7 +65,5 @@ | ||
} | ||
}; | ||
} | ||
exports.add = add; | ||
const remove = ref => { | ||
function remove(ref) { | ||
const mainIndex = indices[ref]; | ||
@@ -76,12 +80,10 @@ | ||
delete indices[ref]; | ||
}; | ||
} | ||
exports.remove = remove; | ||
function has(ref) { | ||
return ref in indices; | ||
} | ||
const has = ref => ref in indices; | ||
exports.has = has; | ||
const list = () => Object.keys(indices); | ||
exports.list = list; | ||
function list() { | ||
return Object.keys(indices); | ||
} |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _deepCopy = _interopRequireDefault(require("../../util/deepCopy.js")); | ||
var _index = require("../../util/index.js"); | ||
@@ -47,3 +47,3 @@ var _logger = _interopRequireDefault(require("../../logger.js")); | ||
this.type = this.options.forceType; | ||
this.data = typeof input === 'object' ? (0, _deepCopy.default)(input) : input; | ||
this.data = typeof input === 'object' ? (0, _index.deepCopy)(input) : input; | ||
this.graph = [{ | ||
@@ -92,3 +92,3 @@ type: this.type, | ||
} else if (this.options.target === '@csl/list+object') { | ||
return this.data.map(this.options.generateGraph ? entry => (0, _graph.applyGraph)(entry, this.graph) : _graph.removeGraph); | ||
return (0, _index.upgradeCsl)(this.data).map(this.options.generateGraph ? entry => (0, _graph.applyGraph)(entry, this.graph) : _graph.removeGraph); | ||
} else { | ||
@@ -119,3 +119,3 @@ return this.data; | ||
const type = (0, _type.type)(input); | ||
const output = type.match(/array|object/) ? (0, _deepCopy.default)(input) : input; | ||
const output = type.match(/array|object/) ? (0, _index.deepCopy)(input) : input; | ||
return (0, _data.data)(output, type); | ||
@@ -142,3 +142,3 @@ }; | ||
const type = (0, _type.type)(input); | ||
const output = type.match(/array|object/) ? (0, _deepCopy.default)(input) : input; | ||
const output = type.match(/array|object/) ? (0, _index.deepCopy)(input) : input; | ||
return (0, _data.dataAsync)(output, type); | ||
@@ -145,0 +145,0 @@ }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.clean = void 0; | ||
exports.clean = parseCsl; | ||
@@ -74,15 +74,29 @@ var _name = require("@citation-js/name"); | ||
author: NAME_LIST, | ||
chair: NAME_LIST, | ||
'collection-editor': NAME_LIST, | ||
compiler: NAME_LIST, | ||
composer: NAME_LIST, | ||
'container-author': NAME_LIST, | ||
contributor: NAME_LIST, | ||
curator: NAME_LIST, | ||
director: NAME_LIST, | ||
editor: NAME_LIST, | ||
'editorial-director': NAME_LIST, | ||
director: NAME_LIST, | ||
'executive-producer': NAME_LIST, | ||
guest: NAME_LIST, | ||
host: NAME_LIST, | ||
interviewer: NAME_LIST, | ||
illustrator: NAME_LIST, | ||
narrator: NAME_LIST, | ||
organizer: NAME_LIST, | ||
'original-author': NAME_LIST, | ||
performer: NAME_LIST, | ||
producer: NAME_LIST, | ||
'reviewed-author': NAME_LIST, | ||
recipient: NAME_LIST, | ||
'script-writer': NAME_LIST, | ||
'series-creator': NAME_LIST, | ||
translator: NAME_LIST, | ||
accessed: DATE, | ||
'available-date': DATE, | ||
container: DATE, | ||
@@ -95,2 +109,3 @@ 'event-date': DATE, | ||
categories: 'object', | ||
custom: 'object', | ||
id: ['string', 'number'], | ||
@@ -103,2 +118,3 @@ language: 'string', | ||
archive: 'string', | ||
archive_collection: 'string', | ||
archive_location: 'string', | ||
@@ -110,2 +126,3 @@ 'archive-place': 'string', | ||
'citation-number': 'string', | ||
'citation-key': 'string', | ||
'citation-label': 'string', | ||
@@ -117,5 +134,7 @@ 'collection-number': 'string', | ||
dimensions: 'string', | ||
division: 'string', | ||
DOI: 'string', | ||
edition: ['string', 'number'], | ||
event: 'string', | ||
'event-title': 'string', | ||
'event-place': 'string', | ||
@@ -140,4 +159,7 @@ 'first-reference-note-number': 'string', | ||
'page-first': 'string', | ||
'part-number': ['string', 'number'], | ||
'part-title': 'string', | ||
PMCID: 'string', | ||
PMID: 'string', | ||
printing: 'string', | ||
publisher: 'string', | ||
@@ -147,2 +169,3 @@ 'publisher-place': 'string', | ||
'reviewed-title': 'string', | ||
'reviewed-genre': 'string', | ||
scale: 'string', | ||
@@ -152,2 +175,3 @@ section: 'string', | ||
status: 'string', | ||
supplement: ['string', 'number'], | ||
title: 'string', | ||
@@ -158,6 +182,8 @@ 'title-short': 'string', | ||
volume: ['string', 'number'], | ||
'volume-title': 'string', | ||
'volume-title-short': 'string', | ||
'year-suffix': 'string' | ||
}; | ||
const correctName = function (name, bestGuessConversions) { | ||
function correctName(name, bestGuessConversions) { | ||
if (typeof name === 'object' && name !== null && (name.literal || name.given || name.family)) { | ||
@@ -170,5 +196,5 @@ return name; | ||
} | ||
}; | ||
} | ||
const correctNameList = function (nameList, bestGuessConversions) { | ||
function correctNameList(nameList, bestGuessConversions) { | ||
if (nameList instanceof Array) { | ||
@@ -178,5 +204,5 @@ const names = nameList.map(name => correctName(name, bestGuessConversions)).filter(Boolean); | ||
} | ||
}; | ||
} | ||
const correctDateParts = function (dateParts, bestGuessConversions) { | ||
function correctDateParts(dateParts, bestGuessConversions) { | ||
if (dateParts.every(part => typeof part === 'number')) { | ||
@@ -189,5 +215,5 @@ return dateParts; | ||
} | ||
}; | ||
} | ||
const correctDate = function (date, bestGuessConversions) { | ||
function correctDate(date, bestGuessConversions) { | ||
const dp = 'date-parts'; | ||
@@ -215,5 +241,5 @@ | ||
} | ||
}; | ||
} | ||
const correctType = function (type, bestGuessConversions) { | ||
function correctType(type, bestGuessConversions) { | ||
type = correctField('language', type, bestGuessConversions); | ||
@@ -228,5 +254,5 @@ | ||
} | ||
}; | ||
} | ||
const correctField = function (fieldName, value, bestGuessConversions) { | ||
function correctField(fieldName, value, bestGuessConversions) { | ||
const fieldType = [].concat(fieldTypes[fieldName]); | ||
@@ -248,5 +274,3 @@ | ||
if (/^_/.test(fieldName)) { | ||
return value; | ||
} else if (bestGuessConversions) { | ||
if (bestGuessConversions) { | ||
if (typeof value === 'string' && fieldType.includes('number') && !fieldType.includes('string') && !isNaN(+value)) { | ||
@@ -264,5 +288,5 @@ return parseFloat(value); | ||
} | ||
}; | ||
} | ||
const parseCsl = function (data, bestGuessConversions = true) { | ||
function parseCsl(data, bestGuessConversions = true) { | ||
return data.map(function (entry) { | ||
@@ -281,4 +305,2 @@ const clean = {}; | ||
}); | ||
}; | ||
exports.clean = parseCsl; | ||
} |
@@ -6,8 +6,11 @@ "use strict"; | ||
}); | ||
exports.removeDataParser = exports.listDataParser = exports.hasDataParser = exports.dataAsync = exports.data = exports.addDataParser = void 0; | ||
exports.addDataParser = addDataParser; | ||
exports.data = data; | ||
exports.dataAsync = dataAsync; | ||
exports.hasDataParser = hasDataParser; | ||
exports.listDataParser = listDataParser; | ||
exports.removeDataParser = removeDataParser; | ||
var _chain = require("./chain.js"); | ||
const flatten = array => [].concat(...array); | ||
const parsers = {}; | ||
@@ -18,3 +21,3 @@ const asyncParsers = {}; | ||
'@csl/list+object': input => input, | ||
'@else/list+object': input => flatten(input.map(_chain.chain)), | ||
'@else/list+object': input => input.map(_chain.chain).flat(), | ||
'@invalid': () => { | ||
@@ -25,6 +28,6 @@ throw new Error('This format is not supported or recognized'); | ||
const nativeAsyncParsers = { | ||
'@else/list+object': async input => flatten(await Promise.all(input.map(_chain.chainAsync))) | ||
'@else/list+object': async input => (await Promise.all(input.map(_chain.chainAsync))).flat() | ||
}; | ||
const data = (input, type) => { | ||
function data(input, type) { | ||
if (typeof parsers[type] === 'function') { | ||
@@ -37,7 +40,5 @@ return parsers[type](input); | ||
} | ||
}; | ||
} | ||
exports.data = data; | ||
const dataAsync = async (input, type) => { | ||
async function dataAsync(input, type) { | ||
if (typeof asyncParsers[type] === 'function') { | ||
@@ -52,10 +53,8 @@ return asyncParsers[type](input); | ||
} | ||
}; | ||
} | ||
exports.dataAsync = dataAsync; | ||
const addDataParser = (format, { | ||
function addDataParser(format, { | ||
parser, | ||
async | ||
}) => { | ||
}) { | ||
if (async) { | ||
@@ -66,18 +65,14 @@ asyncParsers[format] = parser; | ||
} | ||
}; | ||
} | ||
exports.addDataParser = addDataParser; | ||
function hasDataParser(type, async) { | ||
return async ? asyncParsers[type] || nativeAsyncParsers[type] : parsers[type] || nativeParsers[type]; | ||
} | ||
const hasDataParser = (type, async) => async ? asyncParsers[type] || nativeAsyncParsers[type] : parsers[type] || nativeParsers[type]; | ||
exports.hasDataParser = hasDataParser; | ||
const removeDataParser = (type, async) => { | ||
function removeDataParser(type, async) { | ||
delete (async ? asyncParsers : parsers)[type]; | ||
}; | ||
} | ||
exports.removeDataParser = removeDataParser; | ||
const listDataParser = async => Object.keys(async ? asyncParsers : parsers); | ||
exports.listDataParser = listDataParser; | ||
function listDataParser(async) { | ||
return Object.keys(async ? asyncParsers : parsers); | ||
} |
@@ -6,5 +6,6 @@ "use strict"; | ||
}); | ||
exports.typeOf = exports.dataTypeOf = void 0; | ||
exports.dataTypeOf = dataTypeOf; | ||
exports.typeOf = typeOf; | ||
const typeOf = thing => { | ||
function typeOf(thing) { | ||
switch (thing) { | ||
@@ -20,7 +21,5 @@ case undefined: | ||
} | ||
}; | ||
} | ||
exports.typeOf = typeOf; | ||
const dataTypeOf = thing => { | ||
function dataTypeOf(thing) { | ||
switch (typeof thing) { | ||
@@ -42,4 +41,2 @@ case 'string': | ||
} | ||
}; | ||
exports.dataTypeOf = dataTypeOf; | ||
} |
@@ -6,5 +6,6 @@ "use strict"; | ||
}); | ||
exports.removeGraph = exports.applyGraph = void 0; | ||
exports.applyGraph = applyGraph; | ||
exports.removeGraph = removeGraph; | ||
const applyGraph = (entry, graph) => { | ||
function applyGraph(entry, graph) { | ||
if (entry._graph) { | ||
@@ -22,11 +23,7 @@ const index = graph.findIndex(({ | ||
return entry; | ||
}; | ||
} | ||
exports.applyGraph = applyGraph; | ||
const removeGraph = entry => { | ||
function removeGraph(entry) { | ||
delete entry._graph; | ||
return entry; | ||
}; | ||
exports.removeGraph = removeGraph; | ||
} |
@@ -6,3 +6,7 @@ "use strict"; | ||
}); | ||
exports.remove = exports.list = exports.has = exports.get = exports.add = void 0; | ||
exports.add = add; | ||
exports.get = get; | ||
exports.has = has; | ||
exports.list = list; | ||
exports.remove = remove; | ||
@@ -17,3 +21,3 @@ var _parser = require("./parser.js"); | ||
const add = (format, parsers) => { | ||
function add(format, parsers) { | ||
const formatParser = new _parser.FormatParser(format, parsers); | ||
@@ -41,13 +45,9 @@ formatParser.validate(); | ||
} | ||
}; | ||
} | ||
exports.add = add; | ||
const get = format => { | ||
function get(format) { | ||
return formats[format]; | ||
}; | ||
} | ||
exports.get = get; | ||
const remove = format => { | ||
function remove(format) { | ||
const index = formats[format]; | ||
@@ -72,12 +72,10 @@ | ||
delete formats[format]; | ||
}; | ||
} | ||
exports.remove = remove; | ||
function has(format) { | ||
return format in formats; | ||
} | ||
const has = format => format in formats; | ||
exports.has = has; | ||
const list = () => Object.keys(formats); | ||
exports.list = list; | ||
function list() { | ||
return Object.keys(formats); | ||
} |
@@ -6,3 +6,9 @@ "use strict"; | ||
}); | ||
exports.typeMatcher = exports.type = exports.treeTypeParser = exports.removeTypeParser = exports.listTypeParser = exports.hasTypeParser = exports.addTypeParser = void 0; | ||
exports.addTypeParser = addTypeParser; | ||
exports.hasTypeParser = hasTypeParser; | ||
exports.listTypeParser = listTypeParser; | ||
exports.removeTypeParser = removeTypeParser; | ||
exports.treeTypeParser = treeTypeParser; | ||
exports.type = type; | ||
exports.typeMatcher = void 0; | ||
@@ -19,3 +25,3 @@ var _logger = _interopRequireDefault(require("../../logger.js")); | ||
const parseNativeTypes = (input, dataType) => { | ||
function parseNativeTypes(input, dataType) { | ||
switch (dataType) { | ||
@@ -36,5 +42,5 @@ case 'Array': | ||
} | ||
}; | ||
} | ||
const matchType = (typeList = [], data) => { | ||
function matchType(typeList = [], data) { | ||
for (const type of typeList) { | ||
@@ -45,5 +51,5 @@ if (types[type].predicate(data)) { | ||
} | ||
}; | ||
} | ||
const type = input => { | ||
function type(input) { | ||
const dataType = (0, _dataType.dataTypeOf)(input); | ||
@@ -57,11 +63,9 @@ | ||
return match || parseNativeTypes(input, dataType); | ||
}; | ||
} | ||
exports.type = type; | ||
const addTypeParser = (format, { | ||
function addTypeParser(format, { | ||
dataType, | ||
predicate, | ||
extends: extend | ||
}) => { | ||
}) { | ||
let extensions = []; | ||
@@ -100,11 +104,9 @@ | ||
} | ||
}; | ||
} | ||
exports.addTypeParser = addTypeParser; | ||
function hasTypeParser(type) { | ||
return Object.prototype.hasOwnProperty.call(types, type); | ||
} | ||
const hasTypeParser = type => Object.prototype.hasOwnProperty.call(types, type); | ||
exports.hasTypeParser = hasTypeParser; | ||
const removeTypeParser = type => { | ||
function removeTypeParser(type) { | ||
delete types[type]; | ||
@@ -119,11 +121,9 @@ const typeLists = [...Object.keys(dataTypes).map(key => dataTypes[key]), ...Object.keys(types).map(type => types[type].extensions).filter(list => list.length > 0)]; | ||
}); | ||
}; | ||
} | ||
exports.removeTypeParser = removeTypeParser; | ||
function listTypeParser() { | ||
return Object.keys(types); | ||
} | ||
const listTypeParser = () => Object.keys(types); | ||
exports.listTypeParser = listTypeParser; | ||
const treeTypeParser = () => { | ||
function treeTypeParser() { | ||
const attachNode = name => ({ | ||
@@ -141,6 +141,5 @@ name, | ||
}; | ||
}; | ||
} | ||
exports.treeTypeParser = treeTypeParser; | ||
const typeMatcher = /^(?:@(.+?))(?:\/(?:(.+?)\+)?(?:(.+)))?$/; | ||
exports.typeMatcher = typeMatcher; |
@@ -6,3 +6,8 @@ "use strict"; | ||
}); | ||
exports.remove = exports.register = exports.list = exports.has = exports.format = exports.add = void 0; | ||
exports.add = add; | ||
exports.format = format; | ||
exports.has = has; | ||
exports.list = list; | ||
exports.register = void 0; | ||
exports.remove = remove; | ||
@@ -13,3 +18,3 @@ var _register = _interopRequireDefault(require("../util/register.js")); | ||
const validate = (name, formatter) => { | ||
function validate(name, formatter) { | ||
if (typeof name !== 'string') { | ||
@@ -20,3 +25,3 @@ throw new TypeError(`Invalid output format name, expected string, got ${typeof name}`); | ||
} | ||
}; | ||
} | ||
@@ -26,28 +31,20 @@ const register = new _register.default(); | ||
const add = (name, formatter) => { | ||
function add(name, formatter) { | ||
validate(name, formatter); | ||
register.set(name, formatter); | ||
}; | ||
} | ||
exports.add = add; | ||
const remove = name => { | ||
function remove(name) { | ||
register.remove(name); | ||
}; | ||
} | ||
exports.remove = remove; | ||
const has = name => { | ||
function has(name) { | ||
return register.has(name); | ||
}; | ||
} | ||
exports.has = has; | ||
const list = () => { | ||
function list() { | ||
return register.list(); | ||
}; | ||
} | ||
exports.list = list; | ||
const format = (name, data, ...options) => { | ||
function format(name, data, ...options) { | ||
if (!register.has(name)) { | ||
@@ -58,4 +55,2 @@ throw new Error(`Output format "${name}" unavailable`); | ||
return register.get(name)(data, ...options); | ||
}; | ||
exports.format = format; | ||
} |
@@ -13,3 +13,3 @@ "use strict"; | ||
require("isomorphic-fetch"); | ||
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill")); | ||
@@ -22,2 +22,6 @@ var _logger = _interopRequireDefault(require("../logger.js")); | ||
const { | ||
fetch, | ||
Headers | ||
} = (0, _fetchPonyfill.default)(); | ||
const corsEnabled = typeof location !== 'undefined' && typeof document !== 'undefined'; | ||
@@ -24,0 +28,0 @@ let userAgent = corsEnabled ? '' : `Citation.js/${_package.default.version} Node.js/${process.version}`; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const fetchId = function (list, prefix) { | ||
function fetchId(list, prefix) { | ||
let id; | ||
@@ -17,5 +17,5 @@ | ||
return id; | ||
}; | ||
} | ||
var _default = fetchId; | ||
exports.default = _default; |
@@ -36,2 +36,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "downgradeCsl", { | ||
enumerable: true, | ||
get: function () { | ||
return _csl.downgradeCsl; | ||
} | ||
}); | ||
Object.defineProperty(exports, "fetchFile", { | ||
@@ -61,3 +67,11 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "upgradeCsl", { | ||
enumerable: true, | ||
get: function () { | ||
return _csl.upgradeCsl; | ||
} | ||
}); | ||
var _csl = require("./csl.js"); | ||
var _deepCopy = _interopRequireDefault(require("./deepCopy.js")); | ||
@@ -64,0 +78,0 @@ |
The MIT License (MIT) | ||
Copyright (c) 2015-2021 Lars Willighagen | ||
Copyright (c) 2015-2022 Lars Willighagen | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "@citation-js/core", | ||
"version": "0.5.7", | ||
"version": "0.6.0", | ||
"description": "Convert different bibliographic metadata sources", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14.0.0" | ||
}, | ||
@@ -37,4 +37,4 @@ "files": [ | ||
"@citation-js/name": "^0.4.2", | ||
"isomorphic-fetch": "^3.0.0", | ||
"sync-fetch": "^0.3.0" | ||
"fetch-ponyfill": "^7.1.0", | ||
"sync-fetch": "^0.4.1" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "e253e74b1bb444a2b29fd14a4fd818617b7c55b3" | ||
"gitHead": "204c12950afb9ab99bc2f2b8cc18643e53adbd47" | ||
} |
@@ -7,3 +7,3 @@ # @citation-js/core | ||
![License](https://img.shields.io/npm/l/@citation-js/core.svg) | ||
![Dependency status](https://david-dm.org/citation-js/citation-js/status.svg?path=packages%2Fcore) | ||
![Dependency status](https://img.shields.io/librariesio/release/npm/@citation-js/core) | ||
--- | ||
@@ -10,0 +10,0 @@ |
149559
95
4233
+ Addedfetch-ponyfill@^7.1.0
+ Addedfetch-ponyfill@7.1.0(transitive)
+ Addednode-fetch@2.6.13(transitive)
+ Addedsync-fetch@0.4.5(transitive)
- Removedisomorphic-fetch@^3.0.0
- Removedisomorphic-fetch@3.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedsync-fetch@0.3.1(transitive)
- Removedwhatwg-fetch@3.6.20(transitive)
Updatedsync-fetch@^0.4.1