-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatJp.js
58 lines (52 loc) · 1.31 KB
/
formatJp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const { read } = require('@customcommander/ris');
const SEPARATOR = ', ';
function formatJpArticle(ris) {
const fragments = [
ris.A1[0].last_name,
[ris.T1[0] + (ris.T2 ? `:${ris.T2[0]}` : ''), (str) => `「${str}」`],
ris.TA ? `${ris.TA[0].last_name}訳${SEPARATOR}` : '',
[ris.JO[0], (str) => `『${str}』`],
`${ris.IS[0]}: pp. ${ris.SP[0]}-${ris.EP[0]}`,
ris.PB[0],
ris.Y1[0],
];
const separated = fragments.reduce((acc, val, i) => {
if (
!Array.isArray(val) &&
fragments[i + 1] &&
!Array.isArray(fragments[i + 1])
) {
return [...acc, val, SEPARATOR];
}
return [...acc, val];
}, []);
return separated.map((v) => (Array.isArray(v) ? v[1](v[0]) : v));
}
//{
// TY: [ 'JOUR' ],
// T1: [ 'ウィトゲンシュタインは誰のための哲学者か' ],
// A1: [
// {
// last_name: 'G・E・M・アンスコム',
// first_name: '',
// suffix: '',
// initials: ''
// }
// ],
// JO: [ '現代思想' ],
// IS: [ '50(2)' ],
// SP: [ '89' ],
// EP: [ '97' ],
// SN: [ '0289-825X' ],
// Y1: [ '2021' ],
// PB: [ '青土社' ],
// TA: [
// {
// last_name: '吉田廉・京念屋隆史',
// first_name: '',
// suffix: '',
// initials: ''
// }
// ]
//}
exports.formatJpArticle = formatJpArticle;