1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const i18n = require('es2015-i18n-tag').default;
|
13 | const s = require('./symbols');
|
14 |
|
15 | function gentitle(titles, type) {
|
16 | if (!Array.isArray(titles)) {
|
17 | return i18n`Untitled schema`;
|
18 | }
|
19 | const [firsttitle] = titles;
|
20 | const lasttitle = [...titles].pop();
|
21 |
|
22 | if (titles.length === 1 && firsttitle !== undefined) {
|
23 | return firsttitle;
|
24 | }
|
25 | if (lasttitle) {
|
26 | return lasttitle;
|
27 | }
|
28 | if (typeof type === 'string') {
|
29 | return i18n`Untitled ${type} in ${firsttitle}`;
|
30 | }
|
31 | if (firsttitle === undefined) {
|
32 | return i18n`Untitled schema`;
|
33 | }
|
34 | return i18n`Untitled undefined type in ${firsttitle}`;
|
35 | }
|
36 |
|
37 | function gendescription(schema) {
|
38 | return (schema && schema[s.meta]) ? schema[s.meta].shortdescription : '';
|
39 | }
|
40 |
|
41 | module.exports = {
|
42 | gentitle, gendescription,
|
43 | };
|