@citestyle/styles 0.0.2 → 1.0.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 +79 -60
- package/ama.js +1139 -0
- package/apa.js +3707 -0
- package/chicago-author-date.js +6125 -0
- package/harvard.js +1235 -0
- package/ieee.js +1316 -0
- package/mla.js +2349 -0
- package/nature.js +1035 -0
- package/package.json +30 -5
- package/science.js +1070 -0
- package/types.d.ts +5 -1
- package/vancouver.js +993 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @citestyle/styles
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The 10 most popular citation styles, pre-compiled and ready to import. Each style is ~3-5KB — a compiled JavaScript module that formats citations and bibliographies as pure function calls with zero runtime overhead.
|
|
4
|
+
|
|
5
|
+
These are the same styles you'd get by running the `@citestyle/compiler` on official `.csl` files, just pre-built so you can `npm install` and go.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -8,106 +10,123 @@ Pre-compiled popular CSL styles, ready to use. Each style is ~3-5KB and imports
|
|
|
8
10
|
npm install @citestyle/styles
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
|
16
|
-
|
|
17
|
-
| `@citestyle/styles/
|
|
18
|
-
| `@citestyle/styles/
|
|
19
|
-
| `@citestyle/styles/
|
|
20
|
-
| `@citestyle/styles/harvard` | Harvard
|
|
21
|
-
| `@citestyle/styles/
|
|
22
|
-
| `@citestyle/styles/
|
|
23
|
-
| `@citestyle/styles/
|
|
24
|
-
| `@citestyle/styles/
|
|
13
|
+
Requires `@citestyle/core` as a peer dependency (installed automatically).
|
|
14
|
+
|
|
15
|
+
## Available styles
|
|
16
|
+
|
|
17
|
+
| Import | Style | Class |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `@citestyle/styles/apa` | American Psychological Association 7th ed. | Author-date |
|
|
20
|
+
| `@citestyle/styles/mla` | Modern Language Association 9th ed. | Author-date |
|
|
21
|
+
| `@citestyle/styles/chicago-author-date` | Chicago Manual of Style 17th ed. | Author-date |
|
|
22
|
+
| `@citestyle/styles/harvard` | Harvard — Cite Them Right 12th ed. | Author-date |
|
|
23
|
+
| `@citestyle/styles/ieee` | IEEE | Numeric |
|
|
24
|
+
| `@citestyle/styles/vancouver` | Vancouver | Numeric |
|
|
25
|
+
| `@citestyle/styles/ama` | American Medical Association 11th ed. | Numeric |
|
|
26
|
+
| `@citestyle/styles/nature` | Nature | Numeric |
|
|
27
|
+
| `@citestyle/styles/science` | Science | Numeric |
|
|
28
|
+
|
|
29
|
+
**Need a different style?** Any of the 10,000+ `.csl` files from the [official CSL repository](https://github.com/citation-style-language/styles) can be compiled with [`@citestyle/compiler`](../compiler):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx citestyle compile my-journal.csl -o my-journal.js
|
|
33
|
+
```
|
|
25
34
|
|
|
26
35
|
## Usage
|
|
27
36
|
|
|
28
|
-
###
|
|
37
|
+
### Simplest: one-off formatting
|
|
29
38
|
|
|
30
|
-
```
|
|
39
|
+
```javascript
|
|
40
|
+
import { format, formatCitation } from '@citestyle/registry'
|
|
31
41
|
import * as apa from '@citestyle/styles/apa'
|
|
32
42
|
|
|
33
43
|
const item = {
|
|
34
44
|
id: '1',
|
|
35
45
|
type: 'article-journal',
|
|
36
|
-
title: '
|
|
37
|
-
author: [{ family: '
|
|
38
|
-
issued: { 'date-parts': [[
|
|
39
|
-
'container-title': '
|
|
40
|
-
volume: '
|
|
41
|
-
page: '
|
|
42
|
-
DOI: '10.
|
|
46
|
+
title: 'Deep learning for protein structure prediction',
|
|
47
|
+
author: [{ family: 'Jumper', given: 'John' }],
|
|
48
|
+
issued: { 'date-parts': [[2021]] },
|
|
49
|
+
'container-title': 'Nature',
|
|
50
|
+
volume: '596',
|
|
51
|
+
page: '583-589',
|
|
52
|
+
DOI: '10.1038/s41586-021-03819-2',
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
// Bibliography entry
|
|
56
|
+
const entry = format(apa, item)
|
|
57
|
+
entry.text // Jumper, J. (2021). Deep learning for protein structure prediction. Nature, 596, 583–589.
|
|
58
|
+
entry.html // Semantic HTML with CSS classes (.csl-author, .csl-title, ...) and linked DOI
|
|
59
|
+
entry.parts // { authors, year, title, container, volume, page, doi }
|
|
60
|
+
entry.links // { doi: 'https://doi.org/10.1038/s41586-021-03819-2' }
|
|
61
|
+
|
|
62
|
+
// Inline citation
|
|
63
|
+
const cite = formatCitation(apa, [{ item }])
|
|
64
|
+
cite.text // (Jumper, 2021)
|
|
48
65
|
```
|
|
49
66
|
|
|
50
|
-
### With registry (
|
|
67
|
+
### With a registry (for documents)
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
When your document has multiple citations that need to interact — numbering, disambiguation, sorting — use a registry:
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
54
72
|
import { createRegistry } from '@citestyle/registry'
|
|
73
|
+
import * as ieee from '@citestyle/styles/ieee'
|
|
55
74
|
|
|
56
75
|
const registry = createRegistry(ieee)
|
|
57
76
|
registry.addItems([item1, item2, item3])
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
// Citations are auto-numbered
|
|
79
|
+
registry.cite([{ id: 'jumper2021' }])
|
|
80
|
+
// → { text: '[1]', html: '...' }
|
|
61
81
|
|
|
82
|
+
// Bibliography is sorted per IEEE rules
|
|
62
83
|
const bibliography = registry.getBibliography()
|
|
63
|
-
bibliography.forEach(
|
|
84
|
+
bibliography.forEach(entry => {
|
|
85
|
+
console.log(entry.html) // [1] J. Jumper, "Deep learning for..."
|
|
86
|
+
})
|
|
64
87
|
```
|
|
65
88
|
|
|
66
|
-
###
|
|
89
|
+
### Direct function calls (no registry, no helpers)
|
|
67
90
|
|
|
68
|
-
Every style exports
|
|
91
|
+
Every style module exports `bibliography()` and `citation()` as pure functions:
|
|
69
92
|
|
|
70
|
-
```
|
|
93
|
+
```javascript
|
|
71
94
|
import * as apa from '@citestyle/styles/apa'
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
console.log(apa.meta.class) // "in-text"
|
|
96
|
+
const entry = apa.bibliography(item) // → { text, html, parts, links }
|
|
97
|
+
const cite = apa.citation([{ item }]) // → { text, html }
|
|
76
98
|
```
|
|
77
99
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
For styles not included here, compile any CSL file with `@citestyle/compiler`:
|
|
100
|
+
### Style metadata
|
|
81
101
|
|
|
82
|
-
|
|
83
|
-
npm install @citestyle/compiler
|
|
84
|
-
citestyle compile my-style.csl -o my-style.js
|
|
85
|
-
```
|
|
102
|
+
Every style exports a `meta` object with information from the CSL source:
|
|
86
103
|
|
|
87
|
-
|
|
104
|
+
```javascript
|
|
105
|
+
import * as apa from '@citestyle/styles/apa'
|
|
88
106
|
|
|
89
|
-
|
|
90
|
-
|
|
107
|
+
apa.meta.id // "apa"
|
|
108
|
+
apa.meta.title // "American Psychological Association 7th edition"
|
|
109
|
+
apa.meta.class // "in-text"
|
|
91
110
|
```
|
|
92
111
|
|
|
93
|
-
## Output
|
|
112
|
+
## Output format
|
|
94
113
|
|
|
95
|
-
|
|
114
|
+
**Bibliography entries** return four representations:
|
|
96
115
|
|
|
97
|
-
```
|
|
116
|
+
```javascript
|
|
98
117
|
{
|
|
99
|
-
text: '...',
|
|
100
|
-
html: '...',
|
|
101
|
-
parts: {...},
|
|
102
|
-
links: {...},
|
|
118
|
+
text: '...', // Plain text — for copy-paste, accessibility, search indexing
|
|
119
|
+
html: '...', // Semantic HTML — CSS classes per field, auto-linked DOIs
|
|
120
|
+
parts: { ... }, // Decomposed fields — for building cards, profiles, custom layouts
|
|
121
|
+
links: { ... }, // Extracted links — DOI, URL, ready for buttons/badges
|
|
103
122
|
}
|
|
104
123
|
```
|
|
105
124
|
|
|
106
|
-
|
|
125
|
+
**Citations** return two:
|
|
107
126
|
|
|
108
|
-
```
|
|
127
|
+
```javascript
|
|
109
128
|
{
|
|
110
|
-
text: '...',
|
|
111
|
-
html: '...',
|
|
129
|
+
text: '...', // Plain text — "(Smith, 2024)" or "[1]"
|
|
130
|
+
html: '...', // HTML — <span class="csl-citation">...</span>
|
|
112
131
|
}
|
|
113
132
|
```
|