@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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # @citestyle/styles
2
2
 
3
- Pre-compiled popular CSL styles, ready to use. Each style is ~3-5KB and imports shared helpers from `@citestyle/core`.
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
- ## Available Styles
12
-
13
- | Import path | Style |
14
- |---|---|
15
- | `@citestyle/styles/apa` | American Psychological Association 7th edition |
16
- | `@citestyle/styles/mla` | Modern Language Association 9th edition |
17
- | `@citestyle/styles/chicago-author-date` | Chicago Manual of Style 17th edition (author-date) |
18
- | `@citestyle/styles/ieee` | IEEE |
19
- | `@citestyle/styles/vancouver` | Vancouver |
20
- | `@citestyle/styles/harvard` | Harvard (Cite Them Right) |
21
- | `@citestyle/styles/ama` | American Medical Association 11th edition |
22
- | `@citestyle/styles/turabian` | Turabian 9th edition |
23
- | `@citestyle/styles/nature` | Nature |
24
- | `@citestyle/styles/science` | Science |
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
- ### Direct (without registry)
37
+ ### Simplest: one-off formatting
29
38
 
30
- ```js
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: 'A theory of everything',
37
- author: [{ family: 'Einstein', given: 'Albert' }],
38
- issued: { 'date-parts': [[2024]] },
39
- 'container-title': 'Physical Review Letters',
40
- volume: '130',
41
- page: '1-10',
42
- DOI: '10.1103/example',
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
- const entry = apa.bibliography(item)
46
- console.log(entry.text)
47
- console.log(entry.html)
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 (recommended for documents)
67
+ ### With a registry (for documents)
51
68
 
52
- ```js
53
- import * as ieee from '@citestyle/styles/ieee'
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
- const citation = registry.cite([{ id: '1' }])
60
- console.log(citation.text) // [1]
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(e => console.log(e.html))
84
+ bibliography.forEach(entry => {
85
+ console.log(entry.html) // [1] J. Jumper, "Deep learning for..."
86
+ })
64
87
  ```
65
88
 
66
- ### Style metadata
89
+ ### Direct function calls (no registry, no helpers)
67
90
 
68
- Every style exports a `meta` object:
91
+ Every style module exports `bibliography()` and `citation()` as pure functions:
69
92
 
70
- ```js
93
+ ```javascript
71
94
  import * as apa from '@citestyle/styles/apa'
72
95
 
73
- console.log(apa.meta.id) // "apa"
74
- console.log(apa.meta.title) // "American Psychological Association 7th edition"
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
- ## Custom Styles
79
-
80
- For styles not included here, compile any CSL file with `@citestyle/compiler`:
100
+ ### Style metadata
81
101
 
82
- ```bash
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
- Then import the output module the same way:
104
+ ```javascript
105
+ import * as apa from '@citestyle/styles/apa'
88
106
 
89
- ```js
90
- import * as myStyle from './my-style.js'
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 Format
112
+ ## Output format
94
113
 
95
- Every `bibliography(item)` call returns:
114
+ **Bibliography entries** return four representations:
96
115
 
97
- ```js
116
+ ```javascript
98
117
  {
99
- text: '...', // Plain text
100
- html: '...', // Semantic HTML with CSS classes and linked DOIs
101
- parts: {...}, // Decomposed fields for custom layouts
102
- links: {...}, // Extracted DOI, URL, PDF 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
- Every `citation(cites)` call returns:
125
+ **Citations** return two:
107
126
 
108
- ```js
127
+ ```javascript
109
128
  {
110
- text: '...', // Plain text (e.g., "(Smith, 2024)")
111
- html: '...', // HTML with <span class="csl-citation">
129
+ text: '...', // Plain text — "(Smith, 2024)" or "[1]"
130
+ html: '...', // HTML — <span class="csl-citation">...</span>
112
131
  }
113
132
  ```