@citestyle/styles 0.1.0 → 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/package.json +29 -3
- package/types.d.ts +5 -1
- package/build.js +0 -97
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
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citestyle/styles",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Pre-compiled popular CSL styles (~3-5KB each)",
|
|
5
|
+
"author": "Uniweb",
|
|
6
|
+
"homepage": "https://github.com/uniweb/csl/tree/main/packages/styles",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/uniweb/csl.git",
|
|
10
|
+
"directory": "packages/styles"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"csl",
|
|
14
|
+
"citation",
|
|
15
|
+
"styles",
|
|
16
|
+
"apa",
|
|
17
|
+
"mla",
|
|
18
|
+
"chicago",
|
|
19
|
+
"ieee",
|
|
20
|
+
"vancouver",
|
|
21
|
+
"bibliography"
|
|
22
|
+
],
|
|
5
23
|
"type": "module",
|
|
6
24
|
"exports": {
|
|
7
25
|
"./apa": "./apa.js",
|
|
@@ -22,12 +40,20 @@
|
|
|
22
40
|
}
|
|
23
41
|
},
|
|
24
42
|
"files": [
|
|
25
|
-
"
|
|
43
|
+
"apa.js",
|
|
44
|
+
"mla.js",
|
|
45
|
+
"chicago-author-date.js",
|
|
46
|
+
"ieee.js",
|
|
47
|
+
"vancouver.js",
|
|
48
|
+
"harvard.js",
|
|
49
|
+
"ama.js",
|
|
50
|
+
"nature.js",
|
|
51
|
+
"science.js",
|
|
26
52
|
"types.d.ts",
|
|
27
53
|
"README.md"
|
|
28
54
|
],
|
|
29
55
|
"dependencies": {
|
|
30
|
-
"@citestyle/core": "
|
|
56
|
+
"@citestyle/core": "1.0.0"
|
|
31
57
|
},
|
|
32
58
|
"license": "MIT",
|
|
33
59
|
"scripts": {
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { CompiledStyle } from '@citestyle/types'
|
|
2
2
|
|
|
3
3
|
declare const style: CompiledStyle
|
|
4
|
-
export
|
|
4
|
+
export default style
|
|
5
|
+
export declare const meta: CompiledStyle['meta']
|
|
6
|
+
export declare function bibliography(item: import('@citestyle/types').CslItem, ctx?: import('@citestyle/types').FormatContext): import('@citestyle/types').FormattedEntry
|
|
7
|
+
export declare function citation(cites: import('@citestyle/types').CiteRef[], ctx?: import('@citestyle/types').FormatContext): import('@citestyle/types').FormattedCitation
|
|
8
|
+
export declare function bibliographySort(a: import('@citestyle/types').CslItem, b: import('@citestyle/types').CslItem): number
|
package/build.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Build script for @citestyle/styles
|
|
5
|
-
*
|
|
6
|
-
* Compiles CSL XML source files into JavaScript modules using the
|
|
7
|
-
* @citestyle/compiler. The CSL sources live in test/fixtures/ at the
|
|
8
|
-
* monorepo root — these are the canonical CSL style definitions.
|
|
9
|
-
*
|
|
10
|
-
* Each compiled style is a self-contained ES module (~3-50KB) that
|
|
11
|
-
* exports { meta, bibliography, citation, bibliographySort }.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* node build.js # Compile all styles listed in STYLES
|
|
15
|
-
* node build.js --clean # Remove compiled files first
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { execSync } from 'node:child_process'
|
|
19
|
-
import { existsSync, unlinkSync, readdirSync } from 'node:fs'
|
|
20
|
-
import { join, dirname } from 'node:path'
|
|
21
|
-
import { fileURLToPath } from 'node:url'
|
|
22
|
-
|
|
23
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
24
|
-
const ROOT = join(__dirname, '../..')
|
|
25
|
-
const FIXTURES = join(ROOT, 'test/fixtures')
|
|
26
|
-
const CLI = join(ROOT, 'packages/compiler/src/cli.js')
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Styles to compile.
|
|
30
|
-
*
|
|
31
|
-
* Each entry maps a CSL filename (in test/fixtures/) to its output name.
|
|
32
|
-
* The output name must match the exports map in package.json.
|
|
33
|
-
*
|
|
34
|
-
* To add a new style:
|
|
35
|
-
* 1. Add the .csl file to test/fixtures/
|
|
36
|
-
* 2. Add an entry here
|
|
37
|
-
* 3. Add the export to package.json: "./name": "./name.js"
|
|
38
|
-
*/
|
|
39
|
-
const STYLES = [
|
|
40
|
-
// Core academic styles
|
|
41
|
-
'apa',
|
|
42
|
-
'mla',
|
|
43
|
-
'chicago-author-date',
|
|
44
|
-
'ieee',
|
|
45
|
-
'vancouver',
|
|
46
|
-
'harvard',
|
|
47
|
-
|
|
48
|
-
// Additional popular styles
|
|
49
|
-
'ama',
|
|
50
|
-
'nature',
|
|
51
|
-
'science',
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
// Parse args
|
|
55
|
-
const args = process.argv.slice(2)
|
|
56
|
-
const clean = args.includes('--clean')
|
|
57
|
-
|
|
58
|
-
if (clean) {
|
|
59
|
-
console.log('Cleaning compiled styles...')
|
|
60
|
-
for (const file of readdirSync(__dirname)) {
|
|
61
|
-
if (file.endsWith('.js') && file !== 'build.js') {
|
|
62
|
-
unlinkSync(join(__dirname, file))
|
|
63
|
-
console.log(` Removed ${file}`)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
console.log(`Compiling ${STYLES.length} styles...\n`)
|
|
69
|
-
|
|
70
|
-
let failed = 0
|
|
71
|
-
|
|
72
|
-
for (const style of STYLES) {
|
|
73
|
-
const input = join(FIXTURES, `${style}.csl`)
|
|
74
|
-
const output = join(__dirname, `${style}.js`)
|
|
75
|
-
|
|
76
|
-
if (!existsSync(input)) {
|
|
77
|
-
console.error(`✗ ${style}: source not found at ${input}`)
|
|
78
|
-
failed++
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
execSync(`node ${CLI} compile ${input} -o ${output}`, {
|
|
84
|
-
cwd: ROOT,
|
|
85
|
-
stdio: 'inherit',
|
|
86
|
-
})
|
|
87
|
-
} catch {
|
|
88
|
-
console.error(`✗ ${style}: compilation failed`)
|
|
89
|
-
failed++
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
console.log(`\nDone. ${STYLES.length - failed}/${STYLES.length} styles compiled.`)
|
|
94
|
-
|
|
95
|
-
if (failed > 0) {
|
|
96
|
-
process.exit(1)
|
|
97
|
-
}
|