update getCitations() to always print jsPsych + no duplicates; update citation tool docs

This commit is contained in:
Cherrie Chang 2024-12-09 11:58:58 -05:00
parent 1b0843876c
commit 5e878d381f
3 changed files with 13 additions and 5 deletions

View File

@ -16,12 +16,12 @@ This paper is an updated description of jsPsych and includes all current core te
Citations help us demonstrate that this library is used and valued, which allows us to continue working on it. Citations help us demonstrate that this library is used and valued, which allows us to continue working on it.
#### Cite using citation tool #### Citation tool for third-party plugins/extensions
We also made a command-line citation tool that can be used to cite this library, as well as any plugins/extensions you use in your experiment that are developed by other developers. You can see this tool in action by following these steps: jsPsych is an open-source, collaborative ecosystem, and many of the plugins/extensions you end up using may be contributed by third-party developers! We want to make sure they get recognition for their good work, so we made a command-line citation tool that you should use to cite this library and the plugins/extensions used in your experiment. You can see this tool in action by following these steps:
1. Launch a jsPsych experiment in your browser 1. Launch a jsPsych experiment in your browser
2. Open up the browser console using Ctrl + ⇧ + J (Windows) or ⌘ + ⌥ + J (Mac) 2. Open up the browser console using Ctrl + ⇧ + J (Windows) or ⌘ + ⌥ + J (Mac)
3. Type `jsPsych.getCitations([jsPsychHtmlKeyboardResponse], "apa")` 3. Type `jsPsych.getCitations([], "apa")`
This should print the APA format citation for the `jsPsychHtmlKeyboardResponse` plugin, which you can then copy and paste into your working document. You can type any number of plugins/extensions by name in the array `[ ]` to generate a list of citations. We currently support APA formatting (`"apa"`) and BibTex formatting (`"bibtex"`). This should print the APA format citation for the jsPsych library, which you can then copy and paste into your working document. You can type any number of plugins/extensions by name in the array `[ ]` to generate a list of citations, e.g. `jsPsych.getCitations([jsPsychHtmlKeyboardResponse, jsPsychMouseTrackingExtension], "apa")`. We currently support APA formatting (`"apa"`) and BibTex formatting (`"bibtex"`).

View File

@ -22,6 +22,7 @@ export default function generateCitations() {
const citationCff = (() => { const citationCff = (() => {
let rawCff; let rawCff;
try { try {
// look for CITATION.cff in the current directory
rawCff = fs.readFileSync("./CITATION.cff", "utf-8").toString(); rawCff = fs.readFileSync("./CITATION.cff", "utf-8").toString();
const cffData = yaml.parse(rawCff); const cffData = yaml.parse(rawCff);
if (cffData["preferred-citation"]) { if (cffData["preferred-citation"]) {
@ -30,6 +31,7 @@ export default function generateCitations() {
return yaml.stringify(rawCff); return yaml.stringify(rawCff);
} catch (error) { } catch (error) {
try { try {
// look for CITATION.cff in the root of the repository
rawCff = fs.readFileSync(path.join(appRootPath.path, "CITATION.cff"), "utf-8").toString(); rawCff = fs.readFileSync(path.join(appRootPath.path, "CITATION.cff"), "utf-8").toString();
return yaml.stringify(rawCff); return yaml.stringify(rawCff);
} catch (error) { } catch (error) {

View File

@ -272,13 +272,19 @@ export class JsPsych {
} }
// Check if array is empty // Check if array is empty
else if (plugins.length == 0) { else if (plugins.length == 0) {
console.warn("No plugins/extensions provided"); console.log(
format == "apa"
? "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 "
: '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
);
return; return;
} }
// Check if format is supported // Check if format is supported
else if (!Object.keys(plugins[0]["info"].citations).includes(format)) { else if (!Object.keys(plugins[0]["info"].citations).includes(format)) {
throw new Error("Unsupported citation format"); throw new Error("Unsupported citation format");
} else { } else {
const pluginsSet = new Set(plugins);
plugins = Array.from(pluginsSet);
plugins.map((plugin) => { plugins.map((plugin) => {
let pluginCitations = plugin["info"].citations; let pluginCitations = plugin["info"].citations;
console.log(format == "apa" ? `${pluginCitations.apa}` : `${pluginCitations.bibtex}`); console.log(format == "apa" ? `${pluginCitations.apa}` : `${pluginCitations.bibtex}`);