react-cheminfo 0.72.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -8
- package/lib/citation/core/formats.d.ts.map +1 -1
- package/lib/citation/core/formats.js +65 -17
- package/lib/citation/core/formats.js.map +1 -1
- package/lib/citation/core/index.d.ts +3 -2
- package/lib/citation/core/index.d.ts.map +1 -1
- package/lib/citation/core/index.js +2 -1
- package/lib/citation/core/index.js.map +1 -1
- package/lib/citation/core/openChemistryPaper.d.ts +15 -0
- package/lib/citation/core/openChemistryPaper.d.ts.map +1 -0
- package/lib/citation/core/openChemistryPaper.js +33 -0
- package/lib/citation/core/openChemistryPaper.js.map +1 -0
- package/lib/citation/core/reference.d.ts +36 -3
- package/lib/citation/core/reference.d.ts.map +1 -1
- package/lib/citation/core/reference.js +11 -0
- package/lib/citation/core/reference.js.map +1 -1
- package/lib/citation/core/segments.d.ts +9 -2
- package/lib/citation/core/segments.d.ts.map +1 -1
- package/lib/citation/core/segments.js +74 -7
- package/lib/citation/core/segments.js.map +1 -1
- package/lib/citation/ui/CitationMenu.js +2 -2
- package/lib/citation/ui/CitationMenu.js.map +1 -1
- package/lib/citation/ui/WorkEntry.d.ts.map +1 -1
- package/lib/citation/ui/WorkEntry.js +4 -2
- package/lib/citation/ui/WorkEntry.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +1 -0
- package/lib/locales/en.json +1 -0
- package/lib/locales/es.json +1 -0
- package/lib/locales/fr.json +1 -0
- package/lib/locales/it.json +1 -0
- package/package.json +12 -12
- package/src/citation/core/formats.ts +81 -18
- package/src/citation/core/index.ts +11 -2
- package/src/citation/core/openChemistryPaper.ts +37 -0
- package/src/citation/core/reference.ts +43 -3
- package/src/citation/core/segments.ts +92 -16
- package/src/citation/ui/CitationMenu.tsx +2 -2
- package/src/citation/ui/WorkEntry.tsx +7 -3
- package/src/locales/de.json +1 -0
- package/src/locales/en.json +1 -0
- package/src/locales/es.json +1 -0
- package/src/locales/fr.json +1 -0
- package/src/locales/it.json +1 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ArticleReference,
|
|
3
|
+
DatasetReference,
|
|
4
|
+
Reference,
|
|
5
|
+
ReferenceAuthor,
|
|
6
|
+
} from './reference.ts';
|
|
2
7
|
import { doiUrl } from './reference.ts';
|
|
3
8
|
|
|
4
9
|
/** One piece of a written reference, with the emphasis its style asks for. */
|
|
@@ -37,6 +42,7 @@ export function citationSegments(
|
|
|
37
42
|
reference: Reference,
|
|
38
43
|
style: CitationStyleId,
|
|
39
44
|
): CitationSegment[] {
|
|
45
|
+
if (reference.kind === 'dataset') return datasetSegments(reference, style);
|
|
40
46
|
switch (style) {
|
|
41
47
|
case 'acs':
|
|
42
48
|
return acs(reference);
|
|
@@ -51,10 +57,62 @@ export function citationSegments(
|
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
/**
|
|
61
|
+
* A dataset as each style writes one: the repository stands where the journal
|
|
62
|
+
* would, and there is neither a volume nor pages. The title is kept by every
|
|
63
|
+
* style, the RSC one included, since it is what tells two datasets of the same
|
|
64
|
+
* authors and year apart.
|
|
65
|
+
* @param reference - Dataset to write.
|
|
66
|
+
* @param style - Style to write it in.
|
|
67
|
+
* @returns The segments of the citation, in reading order.
|
|
68
|
+
*/
|
|
69
|
+
function datasetSegments(
|
|
70
|
+
reference: DatasetReference,
|
|
71
|
+
style: CitationStyleId,
|
|
72
|
+
): CitationSegment[] {
|
|
73
|
+
const { repository, year, version } = reference;
|
|
74
|
+
const title =
|
|
75
|
+
version === undefined
|
|
76
|
+
? reference.title
|
|
77
|
+
: `${reference.title}, version ${version}`;
|
|
78
|
+
switch (style) {
|
|
79
|
+
case 'acs':
|
|
80
|
+
return [
|
|
81
|
+
text(`${withPeriod(familyFirst(reference, '; '))} ${title}; `),
|
|
82
|
+
italic(repository),
|
|
83
|
+
text(`, ${year}. `),
|
|
84
|
+
doiLink(reference),
|
|
85
|
+
];
|
|
86
|
+
case 'nature':
|
|
87
|
+
return [
|
|
88
|
+
text(`${withPeriod(familyFirstAmpersand(reference))} ${title}. `),
|
|
89
|
+
italic(repository),
|
|
90
|
+
text(` (${year}). `),
|
|
91
|
+
doiLink(reference),
|
|
92
|
+
];
|
|
93
|
+
case 'rsc':
|
|
94
|
+
return [
|
|
95
|
+
text(`${initialsFirst(reference, ' and ')}, ${title}, `),
|
|
96
|
+
italic(repository),
|
|
97
|
+
text(`, ${year}. `),
|
|
98
|
+
doiLink(reference),
|
|
99
|
+
];
|
|
100
|
+
case 'wiley':
|
|
101
|
+
return [
|
|
102
|
+
text(`${initialsFirst(reference, ', ')}, ${title}, `),
|
|
103
|
+
italic(repository),
|
|
104
|
+
text(`, ${year}. `),
|
|
105
|
+
doiLink(reference),
|
|
106
|
+
];
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`unknown citation style: ${String(style)}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function acs(reference: ArticleReference): CitationSegment[] {
|
|
55
113
|
const { title, journalAbbreviation, year, volume } = reference;
|
|
56
114
|
return [
|
|
57
|
-
text(`${familyFirst(reference, '; ')} ${title}. `),
|
|
115
|
+
text(`${withPeriod(familyFirst(reference, '; '))} ${title}. `),
|
|
58
116
|
italic(journalAbbreviation),
|
|
59
117
|
text(' '),
|
|
60
118
|
bold(String(year)),
|
|
@@ -65,10 +123,10 @@ function acs(reference: Reference): CitationSegment[] {
|
|
|
65
123
|
];
|
|
66
124
|
}
|
|
67
125
|
|
|
68
|
-
function nature(reference:
|
|
126
|
+
function nature(reference: ArticleReference): CitationSegment[] {
|
|
69
127
|
const { title, journalAbbreviation, year, volume } = reference;
|
|
70
128
|
return [
|
|
71
|
-
text(`${familyFirstAmpersand(reference)} ${title}. `),
|
|
129
|
+
text(`${withPeriod(familyFirstAmpersand(reference))} ${title}. `),
|
|
72
130
|
italic(journalAbbreviation),
|
|
73
131
|
text(' '),
|
|
74
132
|
bold(volume),
|
|
@@ -77,7 +135,7 @@ function nature(reference: Reference): CitationSegment[] {
|
|
|
77
135
|
];
|
|
78
136
|
}
|
|
79
137
|
|
|
80
|
-
function rsc(reference:
|
|
138
|
+
function rsc(reference: ArticleReference): CitationSegment[] {
|
|
81
139
|
const { journalAbbreviation, year, volume } = reference;
|
|
82
140
|
return [
|
|
83
141
|
text(`${initialsFirst(reference, ' and ')}, `),
|
|
@@ -89,7 +147,7 @@ function rsc(reference: Reference): CitationSegment[] {
|
|
|
89
147
|
];
|
|
90
148
|
}
|
|
91
149
|
|
|
92
|
-
function wiley(reference:
|
|
150
|
+
function wiley(reference: ArticleReference): CitationSegment[] {
|
|
93
151
|
const { journalAbbreviation, year, volume } = reference;
|
|
94
152
|
return [
|
|
95
153
|
text(`${initialsFirst(reference, ', ')}, `),
|
|
@@ -123,6 +181,16 @@ function doiLink(reference: Reference): CitationSegment {
|
|
|
123
181
|
};
|
|
124
182
|
}
|
|
125
183
|
|
|
184
|
+
/**
|
|
185
|
+
* The author list closed by a full stop. A person's name already ends on the
|
|
186
|
+
* one of their last initial; an organisation's name needs its own.
|
|
187
|
+
* @param authors - The author list.
|
|
188
|
+
* @returns It, ending with a full stop.
|
|
189
|
+
*/
|
|
190
|
+
function withPeriod(authors: string): string {
|
|
191
|
+
return authors.endsWith('.') ? authors : `${authors}.`;
|
|
192
|
+
}
|
|
193
|
+
|
|
126
194
|
/**
|
|
127
195
|
* `Vanderveen, J. R.; Patiny, L.` — the family name leads.
|
|
128
196
|
* @param reference - The work being written.
|
|
@@ -130,9 +198,7 @@ function doiLink(reference: Reference): CitationSegment {
|
|
|
130
198
|
* @returns The authors, as one string.
|
|
131
199
|
*/
|
|
132
200
|
function familyFirst(reference: Reference, separator: string): string {
|
|
133
|
-
return reference.authors
|
|
134
|
-
.map((author) => `${author.family}, ${author.given}`)
|
|
135
|
-
.join(separator);
|
|
201
|
+
return reference.authors.map(nameFamilyFirst).join(separator);
|
|
136
202
|
}
|
|
137
203
|
|
|
138
204
|
/**
|
|
@@ -141,9 +207,7 @@ function familyFirst(reference: Reference, separator: string): string {
|
|
|
141
207
|
* @returns The authors, as one string.
|
|
142
208
|
*/
|
|
143
209
|
function familyFirstAmpersand(reference: Reference): string {
|
|
144
|
-
const names = reference.authors.map(
|
|
145
|
-
(author) => `${author.family}, ${author.given}`,
|
|
146
|
-
);
|
|
210
|
+
const names = reference.authors.map(nameFamilyFirst);
|
|
147
211
|
const last = names.at(-1);
|
|
148
212
|
if (names.length < 2 || last === undefined) return names.join(', ');
|
|
149
213
|
return `${names.slice(0, -1).join(', ')} & ${last}`;
|
|
@@ -156,8 +220,8 @@ function familyFirstAmpersand(reference: Reference): string {
|
|
|
156
220
|
* @returns The authors, as one string.
|
|
157
221
|
*/
|
|
158
222
|
function initialsFirst(reference: Reference, lastSeparator: string): string {
|
|
159
|
-
const names = reference.authors.map(
|
|
160
|
-
|
|
223
|
+
const names = reference.authors.map((author) =>
|
|
224
|
+
author.given === '' ? author.family : `${author.given} ${author.family}`,
|
|
161
225
|
);
|
|
162
226
|
const last = names.at(-1);
|
|
163
227
|
if (names.length < 2 || last === undefined) return names.join(', ');
|
|
@@ -171,8 +235,20 @@ function initialsFirst(reference: Reference, lastSeparator: string): string {
|
|
|
171
235
|
* @returns One number for a journal that paginates by article number, the
|
|
172
236
|
* range otherwise.
|
|
173
237
|
*/
|
|
174
|
-
export function pageRange(reference:
|
|
238
|
+
export function pageRange(reference: ArticleReference, dash = '–'): string {
|
|
175
239
|
const { firstPage, lastPage } = reference;
|
|
176
240
|
if (firstPage === lastPage) return firstPage;
|
|
177
241
|
return `${firstPage}${dash}${lastPage}`;
|
|
178
242
|
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* An author with the family name first, `Vanderveen, J. R.`, or the name of an
|
|
246
|
+
* organisation alone.
|
|
247
|
+
* @param author - The author.
|
|
248
|
+
* @returns The name, as a reference list writes it.
|
|
249
|
+
*/
|
|
250
|
+
export function nameFamilyFirst(author: ReferenceAuthor): string {
|
|
251
|
+
return author.given === ''
|
|
252
|
+
? author.family
|
|
253
|
+
: `${author.family}, ${author.given}`;
|
|
254
|
+
}
|
|
@@ -5,7 +5,7 @@ import type { CSSProperties, ReactElement } from 'react';
|
|
|
5
5
|
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
6
6
|
import { CITATION_DOWNLOADS } from '../core/formats.ts';
|
|
7
7
|
import type { Reference } from '../core/reference.ts';
|
|
8
|
-
import { doiUrl } from '../core/reference.ts';
|
|
8
|
+
import { doiUrl, referenceVenue } from '../core/reference.ts';
|
|
9
9
|
import type { CitedWork } from '../core/works.ts';
|
|
10
10
|
import { citedReferences } from '../core/works.ts';
|
|
11
11
|
|
|
@@ -78,7 +78,7 @@ function OneWorkMenu(props: CitedReferenceProps): ReactElement {
|
|
|
78
78
|
<Menu className="citation-menu" style={MENU_STYLE}>
|
|
79
79
|
<MenuItem
|
|
80
80
|
icon={<SvgLogoDoi style={DOI_ICON_STYLE} />}
|
|
81
|
-
text={`${reference
|
|
81
|
+
text={`${referenceVenue(reference)} ${reference.year}`}
|
|
82
82
|
label={reference.doi}
|
|
83
83
|
href={doiUrl(reference)}
|
|
84
84
|
target="_blank"
|
|
@@ -4,7 +4,7 @@ import type { CSSProperties, ReactElement } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
6
6
|
import { CITATION_DOWNLOADS } from '../core/formats.ts';
|
|
7
|
-
import { doiUrl } from '../core/reference.ts';
|
|
7
|
+
import { doiUrl, referenceVenue } from '../core/reference.ts';
|
|
8
8
|
import type { CitedWork } from '../core/works.ts';
|
|
9
9
|
|
|
10
10
|
import { CopyFormatEntries } from './CopyFormatEntries.tsx';
|
|
@@ -52,11 +52,15 @@ export function WorkEntry(props: WorkEntryProps): ReactElement {
|
|
|
52
52
|
{note === undefined ? null : <div style={NOTE_STYLE}>{note}</div>}
|
|
53
53
|
</span>
|
|
54
54
|
}
|
|
55
|
-
label={`${reference
|
|
55
|
+
label={`${referenceVenue(reference)} ${reference.year}`}
|
|
56
56
|
>
|
|
57
57
|
<MenuItem
|
|
58
58
|
icon={<SvgLogoDoi style={DOI_ICON_STYLE} />}
|
|
59
|
-
text={
|
|
59
|
+
text={
|
|
60
|
+
reference.kind === 'dataset'
|
|
61
|
+
? t('cite.openDataset')
|
|
62
|
+
: t('cite.openArticle')
|
|
63
|
+
}
|
|
60
64
|
label={reference.doi}
|
|
61
65
|
href={doiUrl(reference)}
|
|
62
66
|
target="_blank"
|
package/src/locales/de.json
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"cite.copyEveryAs": "Alle Literaturangaben kopieren als",
|
|
156
156
|
"cite.importIntoManager": "In ein Literaturverwaltungsprogramm importieren",
|
|
157
157
|
"cite.openArticle": "Den Artikel öffnen",
|
|
158
|
+
"cite.openDataset": "Den Datensatz öffnen",
|
|
158
159
|
"cite.copyThisAs": "Diese Literaturangabe kopieren als",
|
|
159
160
|
"cite.importThis": "Diese Literaturangabe importieren",
|
|
160
161
|
"cite.copied": "kopiert",
|
package/src/locales/en.json
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"cite.copyEveryAs": "Copy every reference as",
|
|
156
156
|
"cite.importIntoManager": "Import into a reference manager",
|
|
157
157
|
"cite.openArticle": "Open the article",
|
|
158
|
+
"cite.openDataset": "Open the dataset",
|
|
158
159
|
"cite.copyThisAs": "Copy this reference as",
|
|
159
160
|
"cite.importThis": "Import this reference",
|
|
160
161
|
"cite.copied": "copied",
|
package/src/locales/es.json
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"cite.copyEveryAs": "Copiar todas las referencias como",
|
|
156
156
|
"cite.importIntoManager": "Importar a un gestor de referencias",
|
|
157
157
|
"cite.openArticle": "Abrir el artículo",
|
|
158
|
+
"cite.openDataset": "Abrir el conjunto de datos",
|
|
158
159
|
"cite.copyThisAs": "Copiar esta referencia como",
|
|
159
160
|
"cite.importThis": "Importar esta referencia",
|
|
160
161
|
"cite.copied": "copiado",
|
package/src/locales/fr.json
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"cite.copyEveryAs": "Copier toutes les références en",
|
|
156
156
|
"cite.importIntoManager": "Importer dans un gestionnaire de références",
|
|
157
157
|
"cite.openArticle": "Ouvrir l'article",
|
|
158
|
+
"cite.openDataset": "Ouvrir le jeu de données",
|
|
158
159
|
"cite.copyThisAs": "Copier cette référence en",
|
|
159
160
|
"cite.importThis": "Importer cette référence",
|
|
160
161
|
"cite.copied": "copié",
|
package/src/locales/it.json
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"cite.copyEveryAs": "Copia tutti i riferimenti come",
|
|
156
156
|
"cite.importIntoManager": "Importa in un gestore di riferimenti",
|
|
157
157
|
"cite.openArticle": "Apri l'articolo",
|
|
158
|
+
"cite.openDataset": "Apri il set di dati",
|
|
158
159
|
"cite.copyThisAs": "Copia questo riferimento come",
|
|
159
160
|
"cite.importThis": "Importa questo riferimento",
|
|
160
161
|
"cite.copied": "copiato",
|