react-cheminfo 0.140.0 → 0.141.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 +14 -8
- package/lib/citation/core/citationMarkup.d.ts +14 -0
- package/lib/citation/core/citationMarkup.d.ts.map +1 -0
- package/lib/citation/core/citationMarkup.js +27 -0
- package/lib/citation/core/citationMarkup.js.map +1 -0
- package/lib/citation/core/clipboard.d.ts +7 -6
- package/lib/citation/core/clipboard.d.ts.map +1 -1
- package/lib/citation/core/clipboard.js +19 -14
- package/lib/citation/core/clipboard.js.map +1 -1
- package/lib/citation/core/download.d.ts +4 -2
- package/lib/citation/core/download.d.ts.map +1 -1
- package/lib/citation/core/download.js +5 -3
- package/lib/citation/core/download.js.map +1 -1
- package/lib/citation/core/formats.d.ts +14 -3
- package/lib/citation/core/formats.d.ts.map +1 -1
- package/lib/citation/core/formats.js +31 -13
- package/lib/citation/core/formats.js.map +1 -1
- package/lib/citation/core/index.d.ts +3 -3
- package/lib/citation/core/index.d.ts.map +1 -1
- package/lib/citation/core/index.js +2 -2
- package/lib/citation/core/index.js.map +1 -1
- package/lib/citation/core/reference.d.ts +15 -0
- package/lib/citation/core/reference.d.ts.map +1 -1
- package/lib/citation/core/reference.js +24 -0
- package/lib/citation/core/reference.js.map +1 -1
- package/lib/citation/core/styles.d.ts +35 -0
- package/lib/citation/core/styles.d.ts.map +1 -0
- package/lib/citation/core/styles.js +21 -0
- package/lib/citation/core/styles.js.map +1 -0
- package/lib/citation/core/works.d.ts +2 -3
- package/lib/citation/core/works.d.ts.map +1 -1
- package/lib/citation/core/works.js +5 -6
- package/lib/citation/core/works.js.map +1 -1
- package/lib/citation/ui/CitationHtml.d.ts +13 -0
- package/lib/citation/ui/CitationHtml.d.ts.map +1 -0
- package/lib/citation/ui/CitationHtml.js +42 -0
- package/lib/citation/ui/CitationHtml.js.map +1 -0
- package/lib/citation/ui/CitationPreview.d.ts +7 -4
- package/lib/citation/ui/CitationPreview.d.ts.map +1 -1
- package/lib/citation/ui/CitationPreview.js +17 -21
- package/lib/citation/ui/CitationPreview.js.map +1 -1
- package/lib/citation/ui/CopyFormatEntries.js +1 -1
- package/lib/citation/ui/CopyFormatEntries.js.map +1 -1
- package/lib/citation/ui/entries.d.ts +1 -1
- package/lib/citation/ui/entries.d.ts.map +1 -1
- package/lib/citation/ui/entries.js +1 -1
- package/lib/citation/ui/entries.js.map +1 -1
- package/lib/citation/ui/useCopyFeedback.d.ts +1 -2
- package/lib/citation/ui/useCopyFeedback.d.ts.map +1 -1
- package/lib/citation/ui/useCopyFeedback.js.map +1 -1
- package/lib/credits/core/credits.d.ts +13 -0
- package/lib/credits/core/credits.d.ts.map +1 -1
- package/lib/credits/core/credits.js +17 -0
- package/lib/credits/core/credits.js.map +1 -1
- package/lib/csl/core/cslItems.d.ts +97 -0
- package/lib/csl/core/cslItems.d.ts.map +1 -0
- package/lib/csl/core/cslItems.js +166 -0
- package/lib/csl/core/cslItems.js.map +1 -0
- package/lib/csl/core/cslStyles.d.ts +30 -0
- package/lib/csl/core/cslStyles.d.ts.map +1 -0
- package/lib/csl/core/cslStyles.js +48 -0
- package/lib/csl/core/cslStyles.js.map +1 -0
- package/lib/csl/core/formatCsl.d.ts +35 -0
- package/lib/csl/core/formatCsl.d.ts.map +1 -0
- package/lib/csl/core/formatCsl.js +100 -0
- package/lib/csl/core/formatCsl.js.map +1 -0
- package/lib/csl/core/referenceItem.d.ts +14 -0
- package/lib/csl/core/referenceItem.d.ts.map +1 -0
- package/lib/csl/core/referenceItem.js +60 -0
- package/lib/csl/core/referenceItem.js.map +1 -0
- package/lib/csl/core/styles/americanChemicalSociety.d.ts +8 -0
- package/lib/csl/core/styles/americanChemicalSociety.d.ts.map +1 -0
- package/lib/csl/core/styles/americanChemicalSociety.js +311 -0
- package/lib/csl/core/styles/americanChemicalSociety.js.map +1 -0
- package/lib/csl/core/styles/americanInstituteOfPhysics.d.ts +8 -0
- package/lib/csl/core/styles/americanInstituteOfPhysics.d.ts.map +1 -0
- package/lib/csl/core/styles/americanInstituteOfPhysics.js +172 -0
- package/lib/csl/core/styles/americanInstituteOfPhysics.js.map +1 -0
- package/lib/csl/core/styles/americanMathematicalSocietyNumeric.d.ts +8 -0
- package/lib/csl/core/styles/americanMathematicalSocietyNumeric.d.ts.map +1 -0
- package/lib/csl/core/styles/americanMathematicalSocietyNumeric.js +174 -0
- package/lib/csl/core/styles/americanMathematicalSocietyNumeric.js.map +1 -0
- package/lib/csl/core/styles/americanPhysicsSociety.d.ts +8 -0
- package/lib/csl/core/styles/americanPhysicsSociety.d.ts.map +1 -0
- package/lib/csl/core/styles/americanPhysicsSociety.js +227 -0
- package/lib/csl/core/styles/americanPhysicsSociety.js.map +1 -0
- package/lib/csl/core/styles/angewandteChemie.d.ts +8 -0
- package/lib/csl/core/styles/angewandteChemie.d.ts.map +1 -0
- package/lib/csl/core/styles/angewandteChemie.js +187 -0
- package/lib/csl/core/styles/angewandteChemie.js.map +1 -0
- package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.d.ts +8 -0
- package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.d.ts.map +1 -0
- package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.js +280 -0
- package/lib/csl/core/styles/beilsteinJournalOfOrganicChemistry.js.map +1 -0
- package/lib/csl/core/styles/elsevierWithTitles.d.ts +8 -0
- package/lib/csl/core/styles/elsevierWithTitles.d.ts.map +1 -0
- package/lib/csl/core/styles/elsevierWithTitles.js +156 -0
- package/lib/csl/core/styles/elsevierWithTitles.js.map +1 -0
- package/lib/csl/core/styles/helveticaChimicaActa.d.ts +8 -0
- package/lib/csl/core/styles/helveticaChimicaActa.d.ts.map +1 -0
- package/lib/csl/core/styles/helveticaChimicaActa.js +189 -0
- package/lib/csl/core/styles/helveticaChimicaActa.js.map +1 -0
- package/lib/csl/core/styles/ieee.d.ts +8 -0
- package/lib/csl/core/styles/ieee.d.ts.map +1 -0
- package/lib/csl/core/styles/ieee.js +527 -0
- package/lib/csl/core/styles/ieee.js.map +1 -0
- package/lib/csl/core/styles/instituteOfPhysicsNumeric.d.ts +8 -0
- package/lib/csl/core/styles/instituteOfPhysicsNumeric.d.ts.map +1 -0
- package/lib/csl/core/styles/instituteOfPhysicsNumeric.js +135 -0
- package/lib/csl/core/styles/instituteOfPhysicsNumeric.js.map +1 -0
- package/lib/csl/core/styles/localeEnUs.d.ts +8 -0
- package/lib/csl/core/styles/localeEnUs.d.ts.map +1 -0
- package/lib/csl/core/styles/localeEnUs.js +872 -0
- package/lib/csl/core/styles/localeEnUs.js.map +1 -0
- package/lib/csl/core/styles/nature.d.ts +8 -0
- package/lib/csl/core/styles/nature.d.ts.map +1 -0
- package/lib/csl/core/styles/nature.js +197 -0
- package/lib/csl/core/styles/nature.js.map +1 -0
- package/lib/csl/core/styles/royalSocietyOfChemistry.d.ts +8 -0
- package/lib/csl/core/styles/royalSocietyOfChemistry.d.ts.map +1 -0
- package/lib/csl/core/styles/royalSocietyOfChemistry.js +267 -0
- package/lib/csl/core/styles/royalSocietyOfChemistry.js.map +1 -0
- package/lib/csl/core/styles/springerMathphysBrackets.d.ts +8 -0
- package/lib/csl/core/styles/springerMathphysBrackets.d.ts.map +1 -0
- package/lib/csl/core/styles/springerMathphysBrackets.js +159 -0
- package/lib/csl/core/styles/springerMathphysBrackets.js.map +1 -0
- package/lib/csl/core/styles/springerPhysicsBrackets.d.ts +8 -0
- package/lib/csl/core/styles/springerPhysicsBrackets.d.ts.map +1 -0
- package/lib/csl/core/styles/springerPhysicsBrackets.js +166 -0
- package/lib/csl/core/styles/springerPhysicsBrackets.js.map +1 -0
- package/lib/csl/core/styles/styleLoaders.d.ts +6 -0
- package/lib/csl/core/styles/styleLoaders.d.ts.map +1 -0
- package/lib/csl/core/styles/styleLoaders.js +23 -0
- package/lib/csl/core/styles/styleLoaders.js.map +1 -0
- package/lib/csl/core/styles/synthesis.d.ts +8 -0
- package/lib/csl/core/styles/synthesis.d.ts.map +1 -0
- package/lib/csl/core/styles/synthesis.js +196 -0
- package/lib/csl/core/styles/synthesis.js.map +1 -0
- package/lib/csl/core/styles/tetrahedron.d.ts +8 -0
- package/lib/csl/core/styles/tetrahedron.d.ts.map +1 -0
- package/lib/csl/core/styles/tetrahedron.js +22 -0
- package/lib/csl/core/styles/tetrahedron.js.map +1 -0
- package/lib/csl.d.ts +17 -0
- package/lib/csl.d.ts.map +1 -0
- package/lib/csl.js +15 -0
- package/lib/csl.js.map +1 -0
- package/package.json +3 -1
- package/src/citation/core/citationMarkup.ts +28 -0
- package/src/citation/core/clipboard.ts +26 -17
- package/src/citation/core/download.ts +7 -5
- package/src/citation/core/formats.ts +41 -16
- package/src/citation/core/index.ts +3 -6
- package/src/citation/core/reference.ts +25 -0
- package/src/citation/core/styles.ts +34 -0
- package/src/citation/core/works.ts +7 -9
- package/src/citation/ui/CitationHtml.tsx +42 -0
- package/src/citation/ui/CitationPreview.tsx +36 -35
- package/src/citation/ui/CopyFormatEntries.tsx +1 -1
- package/src/citation/ui/entries.tsx +2 -2
- package/src/citation/ui/useCopyFeedback.ts +1 -2
- package/src/credits/core/credits.ts +17 -0
- package/src/csl/core/citeproc.d.ts +43 -0
- package/src/csl/core/cslItems.ts +208 -0
- package/src/csl/core/cslStyles.ts +52 -0
- package/src/csl/core/formatCsl.ts +135 -0
- package/src/csl/core/referenceItem.ts +75 -0
- package/src/csl/core/styles/americanChemicalSociety.ts +310 -0
- package/src/csl/core/styles/americanInstituteOfPhysics.ts +171 -0
- package/src/csl/core/styles/americanMathematicalSocietyNumeric.ts +173 -0
- package/src/csl/core/styles/americanPhysicsSociety.ts +226 -0
- package/src/csl/core/styles/angewandteChemie.ts +186 -0
- package/src/csl/core/styles/beilsteinJournalOfOrganicChemistry.ts +279 -0
- package/src/csl/core/styles/elsevierWithTitles.ts +155 -0
- package/src/csl/core/styles/helveticaChimicaActa.ts +188 -0
- package/src/csl/core/styles/ieee.ts +526 -0
- package/src/csl/core/styles/instituteOfPhysicsNumeric.ts +134 -0
- package/src/csl/core/styles/localeEnUs.ts +871 -0
- package/src/csl/core/styles/nature.ts +196 -0
- package/src/csl/core/styles/royalSocietyOfChemistry.ts +266 -0
- package/src/csl/core/styles/springerMathphysBrackets.ts +158 -0
- package/src/csl/core/styles/springerPhysicsBrackets.ts +165 -0
- package/src/csl/core/styles/styleLoaders.ts +38 -0
- package/src/csl/core/styles/synthesis.ts +195 -0
- package/src/csl/core/styles/tetrahedron.ts +21 -0
- package/src/csl.ts +31 -0
- package/styles/chrome.css +30 -6
- package/lib/citation/core/render.d.ts +0 -21
- package/lib/citation/core/render.d.ts.map +0 -1
- package/lib/citation/core/render.js +0 -74
- package/lib/citation/core/render.js.map +0 -1
- package/lib/citation/core/segments.d.ts +0 -62
- package/lib/citation/core/segments.d.ts.map +0 -1
- package/lib/citation/core/segments.js +0 -210
- package/lib/citation/core/segments.js.map +0 -1
- package/src/citation/core/render.ts +0 -78
- package/src/citation/core/segments.ts +0 -254
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { ArticleReference, Reference, ReferenceAuthor } from './reference.ts';
|
|
2
|
-
/** One piece of a written reference, with the emphasis its style asks for. */
|
|
3
|
-
export type CitationSegment = {
|
|
4
|
-
kind: 'text' | 'italic' | 'bold';
|
|
5
|
-
text: string;
|
|
6
|
-
} | {
|
|
7
|
-
kind: 'link';
|
|
8
|
-
text: string;
|
|
9
|
-
href: string;
|
|
10
|
-
};
|
|
11
|
-
/** The journal styles the reference can be written in. */
|
|
12
|
-
export type CitationStyleId = 'acs' | 'nature' | 'rsc' | 'wiley';
|
|
13
|
-
/** One entry of the style submenu. */
|
|
14
|
-
export interface CitationStyle {
|
|
15
|
-
id: CitationStyleId;
|
|
16
|
-
/** Name of the style. */
|
|
17
|
-
label: string;
|
|
18
|
-
/** Journals that ask for it, shown on the right of the entry. */
|
|
19
|
-
hint: string;
|
|
20
|
-
}
|
|
21
|
-
/** Every style offered, in the order the menu lists them. */
|
|
22
|
-
export declare const CITATION_STYLES: readonly [{
|
|
23
|
-
readonly id: "acs";
|
|
24
|
-
readonly label: "ACS";
|
|
25
|
-
readonly hint: "JACS, Org. Lett.";
|
|
26
|
-
}, {
|
|
27
|
-
readonly id: "nature";
|
|
28
|
-
readonly label: "Nature";
|
|
29
|
-
readonly hint: "Nature, Nat. Chem.";
|
|
30
|
-
}, {
|
|
31
|
-
readonly id: "rsc";
|
|
32
|
-
readonly label: "RSC";
|
|
33
|
-
readonly hint: "Chem. Sci., Green Chem.";
|
|
34
|
-
}, {
|
|
35
|
-
readonly id: "wiley";
|
|
36
|
-
readonly label: "Wiley";
|
|
37
|
-
readonly hint: "Angew. Chem., Chem. Eur. J.";
|
|
38
|
-
}];
|
|
39
|
-
/**
|
|
40
|
-
* Write a reference in one journal style, as the pieces every output format
|
|
41
|
-
* then renders with its own emphasis.
|
|
42
|
-
* @param reference - Reference to write.
|
|
43
|
-
* @param style - Style to write it in.
|
|
44
|
-
* @returns The segments of the citation, in reading order.
|
|
45
|
-
*/
|
|
46
|
-
export declare function citationSegments(reference: Reference, style: CitationStyleId): CitationSegment[];
|
|
47
|
-
/**
|
|
48
|
-
* The pages of a work, as its styles write them.
|
|
49
|
-
* @param reference - The work being written.
|
|
50
|
-
* @param dash - What joins the two ends, an en dash in every style but BibTeX.
|
|
51
|
-
* @returns One number for a journal that paginates by article number, the
|
|
52
|
-
* range otherwise.
|
|
53
|
-
*/
|
|
54
|
-
export declare function pageRange(reference: ArticleReference, dash?: string): string;
|
|
55
|
-
/**
|
|
56
|
-
* An author with the family name first, `Vanderveen, J. R.`, or the name of an
|
|
57
|
-
* organisation alone.
|
|
58
|
-
* @param author - The author.
|
|
59
|
-
* @returns The name, as a reference list writes it.
|
|
60
|
-
*/
|
|
61
|
-
export declare function nameFamilyFirst(author: ReferenceAuthor): string;
|
|
62
|
-
//# sourceMappingURL=segments.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../../src/citation/core/segments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,SAAS,EACT,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAGxB,8EAA8E;AAC9E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAEjE,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,eAAe,CAAC;IACpB,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6DAA6D;AAC7D,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;EAKiB,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,eAAe,GACrB,eAAe,EAAE,CAcnB;AA6KD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,SAAM,GAAG,MAAM,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAI/D"}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { doiUrl } from "./reference.js";
|
|
2
|
-
/** Every style offered, in the order the menu lists them. */
|
|
3
|
-
export const CITATION_STYLES = [
|
|
4
|
-
{ id: 'acs', label: 'ACS', hint: 'JACS, Org. Lett.' },
|
|
5
|
-
{ id: 'nature', label: 'Nature', hint: 'Nature, Nat. Chem.' },
|
|
6
|
-
{ id: 'rsc', label: 'RSC', hint: 'Chem. Sci., Green Chem.' },
|
|
7
|
-
{ id: 'wiley', label: 'Wiley', hint: 'Angew. Chem., Chem. Eur. J.' },
|
|
8
|
-
];
|
|
9
|
-
/**
|
|
10
|
-
* Write a reference in one journal style, as the pieces every output format
|
|
11
|
-
* then renders with its own emphasis.
|
|
12
|
-
* @param reference - Reference to write.
|
|
13
|
-
* @param style - Style to write it in.
|
|
14
|
-
* @returns The segments of the citation, in reading order.
|
|
15
|
-
*/
|
|
16
|
-
export function citationSegments(reference, style) {
|
|
17
|
-
if (reference.kind === 'dataset')
|
|
18
|
-
return datasetSegments(reference, style);
|
|
19
|
-
switch (style) {
|
|
20
|
-
case 'acs':
|
|
21
|
-
return acs(reference);
|
|
22
|
-
case 'nature':
|
|
23
|
-
return nature(reference);
|
|
24
|
-
case 'rsc':
|
|
25
|
-
return rsc(reference);
|
|
26
|
-
case 'wiley':
|
|
27
|
-
return wiley(reference);
|
|
28
|
-
default:
|
|
29
|
-
throw new Error(`unknown citation style: ${String(style)}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A dataset as each style writes one: the repository stands where the journal
|
|
34
|
-
* would, and there is neither a volume nor pages. The title is kept by every
|
|
35
|
-
* style, the RSC one included, since it is what tells two datasets of the same
|
|
36
|
-
* authors and year apart.
|
|
37
|
-
* @param reference - Dataset to write.
|
|
38
|
-
* @param style - Style to write it in.
|
|
39
|
-
* @returns The segments of the citation, in reading order.
|
|
40
|
-
*/
|
|
41
|
-
function datasetSegments(reference, style) {
|
|
42
|
-
const { repository, year, version } = reference;
|
|
43
|
-
const title = version === undefined
|
|
44
|
-
? reference.title
|
|
45
|
-
: `${reference.title}, version ${version}`;
|
|
46
|
-
switch (style) {
|
|
47
|
-
case 'acs':
|
|
48
|
-
return [
|
|
49
|
-
text(`${withPeriod(familyFirst(reference, '; '))} ${title}; `),
|
|
50
|
-
italic(repository),
|
|
51
|
-
text(`, ${year}. `),
|
|
52
|
-
doiLink(reference),
|
|
53
|
-
];
|
|
54
|
-
case 'nature':
|
|
55
|
-
return [
|
|
56
|
-
text(`${withPeriod(familyFirstAmpersand(reference))} ${title}. `),
|
|
57
|
-
italic(repository),
|
|
58
|
-
text(` (${year}). `),
|
|
59
|
-
doiLink(reference),
|
|
60
|
-
];
|
|
61
|
-
case 'rsc':
|
|
62
|
-
return [
|
|
63
|
-
text(`${initialsFirst(reference, ' and ')}, ${title}, `),
|
|
64
|
-
italic(repository),
|
|
65
|
-
text(`, ${year}. `),
|
|
66
|
-
doiLink(reference),
|
|
67
|
-
];
|
|
68
|
-
case 'wiley':
|
|
69
|
-
return [
|
|
70
|
-
text(`${initialsFirst(reference, ', ')}, ${title}, `),
|
|
71
|
-
italic(repository),
|
|
72
|
-
text(`, ${year}. `),
|
|
73
|
-
doiLink(reference),
|
|
74
|
-
];
|
|
75
|
-
default:
|
|
76
|
-
throw new Error(`unknown citation style: ${String(style)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function acs(reference) {
|
|
80
|
-
const { title, journalAbbreviation, year, volume } = reference;
|
|
81
|
-
return [
|
|
82
|
-
text(`${withPeriod(familyFirst(reference, '; '))} ${title}. `),
|
|
83
|
-
italic(journalAbbreviation),
|
|
84
|
-
text(' '),
|
|
85
|
-
bold(String(year)),
|
|
86
|
-
text(', '),
|
|
87
|
-
italic(volume),
|
|
88
|
-
text(`, ${pageRange(reference)}. `),
|
|
89
|
-
doiLink(reference),
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
function nature(reference) {
|
|
93
|
-
const { title, journalAbbreviation, year, volume } = reference;
|
|
94
|
-
return [
|
|
95
|
-
text(`${withPeriod(familyFirstAmpersand(reference))} ${title}. `),
|
|
96
|
-
italic(journalAbbreviation),
|
|
97
|
-
text(' '),
|
|
98
|
-
bold(volume),
|
|
99
|
-
text(`, ${pageRange(reference)} (${year}). `),
|
|
100
|
-
doiLink(reference),
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
function rsc(reference) {
|
|
104
|
-
const { journalAbbreviation, year, volume } = reference;
|
|
105
|
-
return [
|
|
106
|
-
text(`${initialsFirst(reference, ' and ')}, `),
|
|
107
|
-
italic(journalAbbreviation),
|
|
108
|
-
text(`, ${year}, `),
|
|
109
|
-
bold(volume),
|
|
110
|
-
text(`, ${pageRange(reference)}. `),
|
|
111
|
-
doiLink(reference),
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
function wiley(reference) {
|
|
115
|
-
const { journalAbbreviation, year, volume } = reference;
|
|
116
|
-
return [
|
|
117
|
-
text(`${initialsFirst(reference, ', ')}, `),
|
|
118
|
-
italic(journalAbbreviation),
|
|
119
|
-
text(' '),
|
|
120
|
-
bold(String(year)),
|
|
121
|
-
text(', '),
|
|
122
|
-
italic(volume),
|
|
123
|
-
text(`, ${pageRange(reference)}. `),
|
|
124
|
-
doiLink(reference),
|
|
125
|
-
];
|
|
126
|
-
}
|
|
127
|
-
function text(value) {
|
|
128
|
-
return { kind: 'text', text: value };
|
|
129
|
-
}
|
|
130
|
-
function italic(value) {
|
|
131
|
-
return { kind: 'italic', text: value };
|
|
132
|
-
}
|
|
133
|
-
function bold(value) {
|
|
134
|
-
return { kind: 'bold', text: value };
|
|
135
|
-
}
|
|
136
|
-
function doiLink(reference) {
|
|
137
|
-
return {
|
|
138
|
-
kind: 'link',
|
|
139
|
-
text: `doi:${reference.doi}`,
|
|
140
|
-
href: doiUrl(reference),
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* The author list closed by a full stop. A person's name already ends on the
|
|
145
|
-
* one of their last initial; an organisation's name needs its own.
|
|
146
|
-
* @param authors - The author list.
|
|
147
|
-
* @returns It, ending with a full stop.
|
|
148
|
-
*/
|
|
149
|
-
function withPeriod(authors) {
|
|
150
|
-
return authors.endsWith('.') ? authors : `${authors}.`;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* `Vanderveen, J. R.; Patiny, L.` — the family name leads.
|
|
154
|
-
* @param reference - The work being written.
|
|
155
|
-
* @param separator - What goes between two authors.
|
|
156
|
-
* @returns The authors, as one string.
|
|
157
|
-
*/
|
|
158
|
-
function familyFirst(reference, separator) {
|
|
159
|
-
return reference.authors.map(nameFamilyFirst).join(separator);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The same, with the last author introduced by an ampersand.
|
|
163
|
-
* @param reference - The work being written.
|
|
164
|
-
* @returns The authors, as one string.
|
|
165
|
-
*/
|
|
166
|
-
function familyFirstAmpersand(reference) {
|
|
167
|
-
const names = reference.authors.map(nameFamilyFirst);
|
|
168
|
-
const last = names.at(-1);
|
|
169
|
-
if (names.length < 2 || last === undefined)
|
|
170
|
-
return names.join(', ');
|
|
171
|
-
return `${names.slice(0, -1).join(', ')} & ${last}`;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* `J. R. Vanderveen, L. Patiny` — the initials lead.
|
|
175
|
-
* @param reference - The work being written.
|
|
176
|
-
* @param lastSeparator - What introduces the last author.
|
|
177
|
-
* @returns The authors, as one string.
|
|
178
|
-
*/
|
|
179
|
-
function initialsFirst(reference, lastSeparator) {
|
|
180
|
-
const names = reference.authors.map((author) => author.given === '' ? author.family : `${author.given} ${author.family}`);
|
|
181
|
-
const last = names.at(-1);
|
|
182
|
-
if (names.length < 2 || last === undefined)
|
|
183
|
-
return names.join(', ');
|
|
184
|
-
return `${names.slice(0, -1).join(', ')}${lastSeparator}${last}`;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* The pages of a work, as its styles write them.
|
|
188
|
-
* @param reference - The work being written.
|
|
189
|
-
* @param dash - What joins the two ends, an en dash in every style but BibTeX.
|
|
190
|
-
* @returns One number for a journal that paginates by article number, the
|
|
191
|
-
* range otherwise.
|
|
192
|
-
*/
|
|
193
|
-
export function pageRange(reference, dash = '–') {
|
|
194
|
-
const { firstPage, lastPage } = reference;
|
|
195
|
-
if (firstPage === lastPage)
|
|
196
|
-
return firstPage;
|
|
197
|
-
return `${firstPage}${dash}${lastPage}`;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* An author with the family name first, `Vanderveen, J. R.`, or the name of an
|
|
201
|
-
* organisation alone.
|
|
202
|
-
* @param author - The author.
|
|
203
|
-
* @returns The name, as a reference list writes it.
|
|
204
|
-
*/
|
|
205
|
-
export function nameFamilyFirst(author) {
|
|
206
|
-
return author.given === ''
|
|
207
|
-
? author.family
|
|
208
|
-
: `${author.family}, ${author.given}`;
|
|
209
|
-
}
|
|
210
|
-
//# sourceMappingURL=segments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"segments.js","sourceRoot":"","sources":["../../../src/citation/core/segments.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAmBxC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE;IACrD,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,oBAAoB,EAAE;IAC7D,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,yBAAyB,EAAE;IAC5D,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,6BAA6B,EAAE;CACzB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAoB,EACpB,KAAsB;IAEtB,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3E,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,KAAK;YACR,OAAO,GAAG,CAAC,SAAS,CAAC,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AC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC7C,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CACzE,CAAC;IACF,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,aAAa,GAAG,IAAI,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,SAA2B,EAAE,IAAI,GAAG,GAAG;IAC/D,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAC1C,IAAI,SAAS,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC7C,OAAO,GAAG,SAAS,GAAG,IAAI,GAAG,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,OAAO,MAAM,CAAC,KAAK,KAAK,EAAE;QACxB,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { CitationSegment } from './segments.ts';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Write the segments as they read in an email or a manuscript.
|
|
5
|
-
* @param segments - Segments of the citation.
|
|
6
|
-
* @returns The citation, with no markup at all.
|
|
7
|
-
*/
|
|
8
|
-
export function renderText(segments: readonly CitationSegment[]): string {
|
|
9
|
-
let result = '';
|
|
10
|
-
for (const segment of segments) {
|
|
11
|
-
result += segment.kind === 'link' ? segment.href : segment.text;
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Write the segments as HTML, so a paste into Word or a web page keeps the
|
|
18
|
-
* italics and the bold the style asks for.
|
|
19
|
-
* @param segments - Segments of the citation.
|
|
20
|
-
* @returns The citation as one line of HTML.
|
|
21
|
-
*/
|
|
22
|
-
export function renderHtml(segments: readonly CitationSegment[]): string {
|
|
23
|
-
let result = '';
|
|
24
|
-
for (const segment of segments) {
|
|
25
|
-
switch (segment.kind) {
|
|
26
|
-
case 'italic':
|
|
27
|
-
result += `<em>${escapeHtml(segment.text)}</em>`;
|
|
28
|
-
break;
|
|
29
|
-
case 'bold':
|
|
30
|
-
result += `<strong>${escapeHtml(segment.text)}</strong>`;
|
|
31
|
-
break;
|
|
32
|
-
case 'link':
|
|
33
|
-
result += `<a href="${escapeHtml(segment.href)}">${escapeHtml(segment.text)}</a>`;
|
|
34
|
-
break;
|
|
35
|
-
case 'text':
|
|
36
|
-
result += escapeHtml(segment.text);
|
|
37
|
-
break;
|
|
38
|
-
default:
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Write the segments as Markdown, for a README or an issue.
|
|
47
|
-
* @param segments - Segments of the citation.
|
|
48
|
-
* @returns The citation as one line of Markdown.
|
|
49
|
-
*/
|
|
50
|
-
export function renderMarkdown(segments: readonly CitationSegment[]): string {
|
|
51
|
-
let result = '';
|
|
52
|
-
for (const segment of segments) {
|
|
53
|
-
switch (segment.kind) {
|
|
54
|
-
case 'italic':
|
|
55
|
-
result += `*${segment.text}*`;
|
|
56
|
-
break;
|
|
57
|
-
case 'bold':
|
|
58
|
-
result += `**${segment.text}**`;
|
|
59
|
-
break;
|
|
60
|
-
case 'link':
|
|
61
|
-
result += `[${segment.text}](${segment.href})`;
|
|
62
|
-
break;
|
|
63
|
-
case 'text':
|
|
64
|
-
result += segment.text;
|
|
65
|
-
break;
|
|
66
|
-
default:
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function escapeHtml(value: string): string {
|
|
74
|
-
return value
|
|
75
|
-
.replaceAll('&', '&')
|
|
76
|
-
.replaceAll('<', '<')
|
|
77
|
-
.replaceAll('>', '>');
|
|
78
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ArticleReference,
|
|
3
|
-
DatasetReference,
|
|
4
|
-
Reference,
|
|
5
|
-
ReferenceAuthor,
|
|
6
|
-
} from './reference.ts';
|
|
7
|
-
import { doiUrl } from './reference.ts';
|
|
8
|
-
|
|
9
|
-
/** One piece of a written reference, with the emphasis its style asks for. */
|
|
10
|
-
export type CitationSegment =
|
|
11
|
-
| { kind: 'text' | 'italic' | 'bold'; text: string }
|
|
12
|
-
| { kind: 'link'; text: string; href: string };
|
|
13
|
-
|
|
14
|
-
/** The journal styles the reference can be written in. */
|
|
15
|
-
export type CitationStyleId = 'acs' | 'nature' | 'rsc' | 'wiley';
|
|
16
|
-
|
|
17
|
-
/** One entry of the style submenu. */
|
|
18
|
-
export interface CitationStyle {
|
|
19
|
-
id: CitationStyleId;
|
|
20
|
-
/** Name of the style. */
|
|
21
|
-
label: string;
|
|
22
|
-
/** Journals that ask for it, shown on the right of the entry. */
|
|
23
|
-
hint: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Every style offered, in the order the menu lists them. */
|
|
27
|
-
export const CITATION_STYLES = [
|
|
28
|
-
{ id: 'acs', label: 'ACS', hint: 'JACS, Org. Lett.' },
|
|
29
|
-
{ id: 'nature', label: 'Nature', hint: 'Nature, Nat. Chem.' },
|
|
30
|
-
{ id: 'rsc', label: 'RSC', hint: 'Chem. Sci., Green Chem.' },
|
|
31
|
-
{ id: 'wiley', label: 'Wiley', hint: 'Angew. Chem., Chem. Eur. J.' },
|
|
32
|
-
] as const satisfies readonly CitationStyle[];
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Write a reference in one journal style, as the pieces every output format
|
|
36
|
-
* then renders with its own emphasis.
|
|
37
|
-
* @param reference - Reference to write.
|
|
38
|
-
* @param style - Style to write it in.
|
|
39
|
-
* @returns The segments of the citation, in reading order.
|
|
40
|
-
*/
|
|
41
|
-
export function citationSegments(
|
|
42
|
-
reference: Reference,
|
|
43
|
-
style: CitationStyleId,
|
|
44
|
-
): CitationSegment[] {
|
|
45
|
-
if (reference.kind === 'dataset') return datasetSegments(reference, style);
|
|
46
|
-
switch (style) {
|
|
47
|
-
case 'acs':
|
|
48
|
-
return acs(reference);
|
|
49
|
-
case 'nature':
|
|
50
|
-
return nature(reference);
|
|
51
|
-
case 'rsc':
|
|
52
|
-
return rsc(reference);
|
|
53
|
-
case 'wiley':
|
|
54
|
-
return wiley(reference);
|
|
55
|
-
default:
|
|
56
|
-
throw new Error(`unknown citation style: ${String(style)}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
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[] {
|
|
113
|
-
const { title, journalAbbreviation, year, volume } = reference;
|
|
114
|
-
return [
|
|
115
|
-
text(`${withPeriod(familyFirst(reference, '; '))} ${title}. `),
|
|
116
|
-
italic(journalAbbreviation),
|
|
117
|
-
text(' '),
|
|
118
|
-
bold(String(year)),
|
|
119
|
-
text(', '),
|
|
120
|
-
italic(volume),
|
|
121
|
-
text(`, ${pageRange(reference)}. `),
|
|
122
|
-
doiLink(reference),
|
|
123
|
-
];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function nature(reference: ArticleReference): CitationSegment[] {
|
|
127
|
-
const { title, journalAbbreviation, year, volume } = reference;
|
|
128
|
-
return [
|
|
129
|
-
text(`${withPeriod(familyFirstAmpersand(reference))} ${title}. `),
|
|
130
|
-
italic(journalAbbreviation),
|
|
131
|
-
text(' '),
|
|
132
|
-
bold(volume),
|
|
133
|
-
text(`, ${pageRange(reference)} (${year}). `),
|
|
134
|
-
doiLink(reference),
|
|
135
|
-
];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function rsc(reference: ArticleReference): CitationSegment[] {
|
|
139
|
-
const { journalAbbreviation, year, volume } = reference;
|
|
140
|
-
return [
|
|
141
|
-
text(`${initialsFirst(reference, ' and ')}, `),
|
|
142
|
-
italic(journalAbbreviation),
|
|
143
|
-
text(`, ${year}, `),
|
|
144
|
-
bold(volume),
|
|
145
|
-
text(`, ${pageRange(reference)}. `),
|
|
146
|
-
doiLink(reference),
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function wiley(reference: ArticleReference): CitationSegment[] {
|
|
151
|
-
const { journalAbbreviation, year, volume } = reference;
|
|
152
|
-
return [
|
|
153
|
-
text(`${initialsFirst(reference, ', ')}, `),
|
|
154
|
-
italic(journalAbbreviation),
|
|
155
|
-
text(' '),
|
|
156
|
-
bold(String(year)),
|
|
157
|
-
text(', '),
|
|
158
|
-
italic(volume),
|
|
159
|
-
text(`, ${pageRange(reference)}. `),
|
|
160
|
-
doiLink(reference),
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function text(value: string): CitationSegment {
|
|
165
|
-
return { kind: 'text', text: value };
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function italic(value: string): CitationSegment {
|
|
169
|
-
return { kind: 'italic', text: value };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function bold(value: string): CitationSegment {
|
|
173
|
-
return { kind: 'bold', text: value };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function doiLink(reference: Reference): CitationSegment {
|
|
177
|
-
return {
|
|
178
|
-
kind: 'link',
|
|
179
|
-
text: `doi:${reference.doi}`,
|
|
180
|
-
href: doiUrl(reference),
|
|
181
|
-
};
|
|
182
|
-
}
|
|
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
|
-
|
|
194
|
-
/**
|
|
195
|
-
* `Vanderveen, J. R.; Patiny, L.` — the family name leads.
|
|
196
|
-
* @param reference - The work being written.
|
|
197
|
-
* @param separator - What goes between two authors.
|
|
198
|
-
* @returns The authors, as one string.
|
|
199
|
-
*/
|
|
200
|
-
function familyFirst(reference: Reference, separator: string): string {
|
|
201
|
-
return reference.authors.map(nameFamilyFirst).join(separator);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* The same, with the last author introduced by an ampersand.
|
|
206
|
-
* @param reference - The work being written.
|
|
207
|
-
* @returns The authors, as one string.
|
|
208
|
-
*/
|
|
209
|
-
function familyFirstAmpersand(reference: Reference): string {
|
|
210
|
-
const names = reference.authors.map(nameFamilyFirst);
|
|
211
|
-
const last = names.at(-1);
|
|
212
|
-
if (names.length < 2 || last === undefined) return names.join(', ');
|
|
213
|
-
return `${names.slice(0, -1).join(', ')} & ${last}`;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* `J. R. Vanderveen, L. Patiny` — the initials lead.
|
|
218
|
-
* @param reference - The work being written.
|
|
219
|
-
* @param lastSeparator - What introduces the last author.
|
|
220
|
-
* @returns The authors, as one string.
|
|
221
|
-
*/
|
|
222
|
-
function initialsFirst(reference: Reference, lastSeparator: string): string {
|
|
223
|
-
const names = reference.authors.map((author) =>
|
|
224
|
-
author.given === '' ? author.family : `${author.given} ${author.family}`,
|
|
225
|
-
);
|
|
226
|
-
const last = names.at(-1);
|
|
227
|
-
if (names.length < 2 || last === undefined) return names.join(', ');
|
|
228
|
-
return `${names.slice(0, -1).join(', ')}${lastSeparator}${last}`;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* The pages of a work, as its styles write them.
|
|
233
|
-
* @param reference - The work being written.
|
|
234
|
-
* @param dash - What joins the two ends, an en dash in every style but BibTeX.
|
|
235
|
-
* @returns One number for a journal that paginates by article number, the
|
|
236
|
-
* range otherwise.
|
|
237
|
-
*/
|
|
238
|
-
export function pageRange(reference: ArticleReference, dash = '–'): string {
|
|
239
|
-
const { firstPage, lastPage } = reference;
|
|
240
|
-
if (firstPage === lastPage) return firstPage;
|
|
241
|
-
return `${firstPage}${dash}${lastPage}`;
|
|
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
|
-
}
|