@citation-js/plugin-csl
Advanced tools
Comparing version 0.5.0-alpha.9 to 0.5.0-alpha.10
@@ -13,10 +13,9 @@ import prepareEngine from './engines'; | ||
} = options; | ||
const ids = options.entry ? [].concat(options.entry) : data.map(({ | ||
id | ||
}) => id); | ||
const citeproc = prepareEngine(data, template, lang, format); | ||
const sortedIds = citeproc.updateItems(data.map(entry => entry.id), nosort); | ||
const sortedIds = citeproc.updateItems(ids, nosort); | ||
if (options.append || options.prepend) { | ||
const { | ||
append, | ||
prepend | ||
} = options; | ||
const items = data.reduce((items, entry) => { | ||
@@ -29,3 +28,3 @@ items[entry.id] = entry; | ||
const entry = items[id]; | ||
return [getAffix(entry, prepend), getAffix(entry, append)]; | ||
return [getAffix(entry, options.prepend), getAffix(entry, options.append)]; | ||
}; | ||
@@ -42,3 +41,8 @@ } else { | ||
const entries = bibBody.map((element, index) => getPrefixedEntry(element, sortedIds[index])); | ||
if (options.asEntryArray) { | ||
return entries.map((element, index) => [sortedIds[index], element]); | ||
} | ||
return bibstart + entries.join('') + bibend; | ||
} |
@@ -23,10 +23,9 @@ "use strict"; | ||
} = options; | ||
const ids = options.entry ? [].concat(options.entry) : data.map(({ | ||
id | ||
}) => id); | ||
const citeproc = (0, _engines.default)(data, template, lang, format); | ||
const sortedIds = citeproc.updateItems(data.map(entry => entry.id), nosort); | ||
const sortedIds = citeproc.updateItems(ids, nosort); | ||
if (options.append || options.prepend) { | ||
const { | ||
append, | ||
prepend | ||
} = options; | ||
const items = data.reduce((items, entry) => { | ||
@@ -39,3 +38,3 @@ items[entry.id] = entry; | ||
const entry = items[id]; | ||
return [getAffix(entry, prepend), getAffix(entry, append)]; | ||
return [getAffix(entry, options.prepend), getAffix(entry, options.append)]; | ||
}; | ||
@@ -52,3 +51,8 @@ } else { | ||
const entries = bibBody.map((element, index) => (0, _attr.getPrefixedEntry)(element, sortedIds[index])); | ||
if (options.asEntryArray) { | ||
return entries.map((element, index) => [sortedIds[index], element]); | ||
} | ||
return bibstart + entries.join('') + bibend; | ||
} |
{ | ||
"name": "@citation-js/plugin-csl", | ||
"version": "0.5.0-alpha.9", | ||
"version": "0.5.0-alpha.10", | ||
"description": "Plugin for CSL output for Citation.js", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@citation-js/core": "^0.5.0-alpha.9" | ||
"@citation-js/core": "^0.5.0-alpha.10" | ||
}, | ||
@@ -43,3 +43,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "ebcf91e8aa39c6230df76192ce5b1ed5147a7a0f" | ||
"gitHead": "d6879a3d1b884d089577fbe136604802b280c6ca" | ||
} |
@@ -37,2 +37,3 @@ # @citation-js/plugin-csl | ||
* `format`: output (markup) format. Note: this doesn't support the output format dictionaries | ||
* `entry` (`String`, `Array[String]`): entry ID or list of entry IDs to identify the items to cite | ||
@@ -46,2 +47,3 @@ ### Bibliography | ||
* `nosort` (`Boolean`, default: `false`): do not sort according to the style-defined rules | ||
* `asEntryArray` (`Boolean`, default: `false`): return an array of entries consisting of an id and the output for that individual entry | ||
@@ -51,8 +53,8 @@ Here's an example for `prepend` and `append`: | ||
```js | ||
let cite = new Cite({id: 'a', title: 'Item A'}) | ||
let cite = new Cite({ id: 'a', title: 'Item A' }) | ||
cite.format('bibliography', {append: ' [foobar]'}) | ||
cite.format('bibliography', { append: ' [foobar]' }) | ||
// 'Item A. (n.d.). [foobar]\n' | ||
cite.format('bibliography', {prepend (entry) { return `${entry.id}: ` }}) | ||
cite.format('bibliography', { prepend (entry) { return `${entry.id}: ` } }) | ||
// 'a: Item A. (n.d.).\n' | ||
@@ -86,8 +88,25 @@ ``` | ||
### Citation | ||
Here's an example for `asEntryArray`: | ||
This plugin adds the output format `citation`, and accepts the following specific options: | ||
```js | ||
const cite = new Cite([ | ||
{ id: 'a', title: 'Item A', issued: { literal: 2021 } }, | ||
{ id: 'b', title: 'Item B', issued: { literal: 2021 } } | ||
]) | ||
* `entry` (`String`, `Array[String]`): entry ID or list of entry IDs to identify the items to cite | ||
cite.format('bibliography', { asEntryArray: true }) | ||
// [ | ||
// [ | ||
// "a" | ||
// "Item A. (2021).\n" | ||
// ], | ||
// [ | ||
// "b" | ||
// "Item B. (2021).\n" | ||
// ] | ||
// ] | ||
``` | ||
### Citation | ||
Here's an example for `entry`: | ||
@@ -97,5 +116,5 @@ | ||
let cite = new Cite([ | ||
{id: 'a', title: 'Item A', issued: {'date-parts': [[2016]]}}, | ||
{id: 'b', title: 'Item B', issued: {'date-parts': [[2017]]}}, | ||
{id: 'c', title: 'Item C', issued: {'date-parts': [[2018]]}} | ||
{ id: 'a', title: 'Item A', issued: { 'date-parts': [[2016]] } }, | ||
{ id: 'b', title: 'Item B', issued: { 'date-parts': [[2017]] } }, | ||
{ id: 'c', title: 'Item C', issued: { 'date-parts': [[2018]] } } | ||
]) | ||
@@ -106,6 +125,6 @@ | ||
cite.format('citation', {entry: ['a', 'b']}) | ||
cite.format('citation', { entry: ['a', 'b'] }) | ||
// '(“Item A,” 2016; “Item B,” 2017)' | ||
cite.format('citation', {entry: 'a'}) | ||
cite.format('citation', { entry: 'a' }) | ||
// '(“Item A,” 2016)' | ||
@@ -168,3 +187,3 @@ ``` | ||
let citeproc = plugins.engine( | ||
/* data: */ [{...}], | ||
/* data: */ [{ ... }], | ||
/* template: */ 'apa', | ||
@@ -171,0 +190,0 @@ /* locale: */ 'en-US', |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
220578
1134
190