UNPKG

1.39 kBJavaScriptView Raw
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12const i18n = require('es2015-i18n-tag').default;
13const s = require('./symbols');
14
15function 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
37function gendescription(schema) {
38 return (schema && schema[s.meta]) ? schema[s.meta].shortdescription : '';
39}
40
41module.exports = {
42 gentitle, gendescription,
43};