@uniweb/scholar 0.2.0 → 0.2.1

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.
@@ -1,335 +0,0 @@
1
- /**
2
- * MLA 9th Edition Reference Formatter
3
- *
4
- * Formats references according to MLA 9th edition guidelines.
5
- *
6
- * @module @uniweb/scholar/bibliography/formatters/mla
7
- */
8
-
9
- import { formatMlaAuthors, parseAuthorString } from '../utils/authors.js'
10
- import { formatMlaDate, getYear } from '../utils/dates.js'
11
-
12
- /**
13
- * Format a journal article in MLA style
14
- *
15
- * @param {Object} pub - Publication data
16
- * @returns {string}
17
- */
18
- function formatArticle(pub) {
19
- const parts = []
20
-
21
- // Authors
22
- const authors = Array.isArray(pub.authors)
23
- ? pub.authors
24
- : parseAuthorString(pub.authors || pub.author)
25
- if (authors.length) {
26
- parts.push(`${formatMlaAuthors(authors)}.`)
27
- }
28
-
29
- // Title in quotes
30
- if (pub.title) {
31
- parts.push(`"${pub.title}."`)
32
- }
33
-
34
- // Container (journal name, italicized)
35
- if (pub.journal) {
36
- let container = pub.journal
37
- if (pub.volume) {
38
- container += `, vol. ${pub.volume}`
39
- }
40
- if (pub.issue) {
41
- container += `, no. ${pub.issue}`
42
- }
43
- // Date
44
- const year = getYear(pub.year || pub.date)
45
- if (year) {
46
- container += `, ${year}`
47
- }
48
- // Pages
49
- if (pub.pages) {
50
- container += `, pp. ${pub.pages}`
51
- }
52
- parts.push(`${container}.`)
53
- }
54
-
55
- // DOI
56
- if (pub.doi) {
57
- const doi = pub.doi.startsWith('http')
58
- ? pub.doi
59
- : `https://doi.org/${pub.doi}`
60
- parts.push(doi)
61
- }
62
-
63
- return parts.join(' ')
64
- }
65
-
66
- /**
67
- * Format a book in MLA style
68
- *
69
- * @param {Object} pub - Publication data
70
- * @returns {string}
71
- */
72
- function formatBook(pub) {
73
- const parts = []
74
-
75
- // Authors or editors
76
- const authors = Array.isArray(pub.authors)
77
- ? pub.authors
78
- : parseAuthorString(pub.authors || pub.author)
79
- const editors = Array.isArray(pub.editors)
80
- ? pub.editors
81
- : parseAuthorString(pub.editors || pub.editor)
82
-
83
- if (authors.length) {
84
- parts.push(`${formatMlaAuthors(authors)}.`)
85
- } else if (editors.length) {
86
- parts.push(
87
- `${formatMlaAuthors(editors)}, editor${editors.length > 1 ? 's' : ''}.`
88
- )
89
- }
90
-
91
- // Title (italicized)
92
- if (pub.title) {
93
- parts.push(`${pub.title}.`)
94
- }
95
-
96
- // Edition
97
- if (pub.edition && pub.edition !== '1') {
98
- parts.push(`${pub.edition} ed.,`)
99
- }
100
-
101
- // Publisher
102
- if (pub.publisher) {
103
- parts.push(`${pub.publisher},`)
104
- }
105
-
106
- // Year
107
- const year = getYear(pub.year || pub.date)
108
- if (year) {
109
- parts.push(`${year}.`)
110
- }
111
-
112
- return parts.join(' ')
113
- }
114
-
115
- /**
116
- * Format a book chapter in MLA style
117
- *
118
- * @param {Object} pub - Publication data
119
- * @returns {string}
120
- */
121
- function formatInBook(pub) {
122
- const parts = []
123
-
124
- // Chapter authors
125
- const authors = Array.isArray(pub.authors)
126
- ? pub.authors
127
- : parseAuthorString(pub.authors || pub.author)
128
- if (authors.length) {
129
- parts.push(`${formatMlaAuthors(authors)}.`)
130
- }
131
-
132
- // Chapter title in quotes
133
- if (pub.title) {
134
- parts.push(`"${pub.title}."`)
135
- }
136
-
137
- // Book title (italicized)
138
- if (pub.bookTitle) {
139
- parts.push(`${pub.bookTitle},`)
140
- }
141
-
142
- // Editors
143
- const editors = Array.isArray(pub.editors)
144
- ? pub.editors
145
- : parseAuthorString(pub.editors || pub.editor)
146
- if (editors.length) {
147
- parts.push(
148
- `edited by ${formatMlaAuthors(editors)},`
149
- )
150
- }
151
-
152
- // Publisher
153
- if (pub.publisher) {
154
- parts.push(`${pub.publisher},`)
155
- }
156
-
157
- // Year
158
- const year = getYear(pub.year || pub.date)
159
- if (year) {
160
- parts.push(`${year},`)
161
- }
162
-
163
- // Pages
164
- if (pub.pages) {
165
- parts.push(`pp. ${pub.pages}.`)
166
- }
167
-
168
- return parts.join(' ')
169
- }
170
-
171
- /**
172
- * Format conference proceedings in MLA style
173
- *
174
- * @param {Object} pub - Publication data
175
- * @returns {string}
176
- */
177
- function formatConference(pub) {
178
- const parts = []
179
-
180
- // Authors
181
- const authors = Array.isArray(pub.authors)
182
- ? pub.authors
183
- : parseAuthorString(pub.authors || pub.author)
184
- if (authors.length) {
185
- parts.push(`${formatMlaAuthors(authors)}.`)
186
- }
187
-
188
- // Title in quotes
189
- if (pub.title) {
190
- parts.push(`"${pub.title}."`)
191
- }
192
-
193
- // Conference/Proceedings (italicized)
194
- if (pub.booktitle || pub.conference) {
195
- parts.push(`${pub.booktitle || pub.conference},`)
196
- }
197
-
198
- // Year
199
- const year = getYear(pub.year || pub.date)
200
- if (year) {
201
- parts.push(`${year},`)
202
- }
203
-
204
- // Pages
205
- if (pub.pages) {
206
- parts.push(`pp. ${pub.pages}.`)
207
- }
208
-
209
- // DOI
210
- if (pub.doi) {
211
- const doi = pub.doi.startsWith('http')
212
- ? pub.doi
213
- : `https://doi.org/${pub.doi}`
214
- parts.push(doi)
215
- }
216
-
217
- return parts.join(' ')
218
- }
219
-
220
- /**
221
- * Format a website/webpage in MLA style
222
- *
223
- * @param {Object} pub - Publication data
224
- * @returns {string}
225
- */
226
- function formatWebsite(pub) {
227
- const parts = []
228
-
229
- // Authors
230
- const authors = Array.isArray(pub.authors)
231
- ? pub.authors
232
- : parseAuthorString(pub.authors || pub.author)
233
- if (authors.length) {
234
- parts.push(`${formatMlaAuthors(authors)}.`)
235
- }
236
-
237
- // Title in quotes
238
- if (pub.title) {
239
- parts.push(`"${pub.title}."`)
240
- }
241
-
242
- // Site name (italicized)
243
- if (pub.siteName) {
244
- parts.push(`${pub.siteName},`)
245
- }
246
-
247
- // Date
248
- const date = formatMlaDate(pub.date || pub.year)
249
- if (date) {
250
- parts.push(`${date},`)
251
- }
252
-
253
- // URL
254
- if (pub.url) {
255
- parts.push(`${pub.url}.`)
256
- }
257
-
258
- return parts.join(' ')
259
- }
260
-
261
- /**
262
- * Format a thesis/dissertation in MLA style
263
- *
264
- * @param {Object} pub - Publication data
265
- * @returns {string}
266
- */
267
- function formatThesis(pub) {
268
- const parts = []
269
-
270
- // Author
271
- const authors = Array.isArray(pub.authors)
272
- ? pub.authors
273
- : parseAuthorString(pub.authors || pub.author)
274
- if (authors.length) {
275
- parts.push(`${formatMlaAuthors(authors)}.`)
276
- }
277
-
278
- // Title (italicized)
279
- if (pub.title) {
280
- parts.push(`${pub.title}.`)
281
- }
282
-
283
- // Year
284
- const year = getYear(pub.year || pub.date)
285
- if (year) {
286
- parts.push(`${year}.`)
287
- }
288
-
289
- // Institution and type
290
- if (pub.school || pub.institution) {
291
- const type = pub.type === 'mastersthesis' ? 'MA thesis' : 'PhD dissertation'
292
- parts.push(`${pub.school || pub.institution}, ${type}.`)
293
- }
294
-
295
- return parts.join(' ')
296
- }
297
-
298
- /**
299
- * Format a reference in MLA 9th edition style
300
- *
301
- * @param {Object} pub - Publication data
302
- * @param {Object} [options] - Formatting options
303
- * @returns {string}
304
- */
305
- export function formatMla(pub, options = {}) {
306
- const type = (pub.type || pub.entryType || 'article').toLowerCase()
307
-
308
- switch (type) {
309
- case 'article':
310
- case 'journal':
311
- return formatArticle(pub)
312
- case 'book':
313
- return formatBook(pub)
314
- case 'inbook':
315
- case 'incollection':
316
- case 'chapter':
317
- return formatInBook(pub)
318
- case 'inproceedings':
319
- case 'conference':
320
- case 'proceedings':
321
- return formatConference(pub)
322
- case 'webpage':
323
- case 'website':
324
- case 'online':
325
- return formatWebsite(pub)
326
- case 'thesis':
327
- case 'phdthesis':
328
- case 'mastersthesis':
329
- return formatThesis(pub)
330
- default:
331
- return formatArticle(pub)
332
- }
333
- }
334
-
335
- export default formatMla