Skip to content

Commit 51ca3f0

Browse files
committed
Some changes proposed by copilot
1 parent 177ab18 commit 51ca3f0

File tree

5 files changed

+51
-54
lines changed

5 files changed

+51
-54
lines changed

deno.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/common.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const EXTRA_DATATYPES: string[] = [
1414
"rdf:HTML",
1515
"rdf:XMLLiteral",
1616
"rdf:PlainLiteral",
17-
"rdf:langString"
17+
"rdf:langString",
1818
]
1919

2020
/**
@@ -23,7 +23,7 @@ export const EXTRA_DATATYPES: string[] = [
2323
export enum Status {
2424
stable = "stable",
2525
reserved = "reserved",
26-
deprecated = "deprecated"
26+
deprecated = "deprecated",
2727
}
2828

2929
/**
@@ -32,9 +32,9 @@ export enum Status {
3232
* should be removed (because it is empty), or not.
3333
*/
3434
export class StatusCounter {
35-
private stableNum = 0;
36-
private reservedNum = 0;
37-
private deprecateNum = 0;
35+
private stableNum = 0;
36+
private reservedNum = 0;
37+
private deprecatedNum = 0;
3838

3939
/**
4040
* Increase the relevant counter.
@@ -52,7 +52,7 @@ export class StatusCounter {
5252
return;
5353
}
5454
case Status.deprecated: {
55-
this.deprecateNum++;
55+
this.deprecatedNum++;
5656
return;
5757
}
5858
}
@@ -66,7 +66,8 @@ export class StatusCounter {
6666
switch (status) {
6767
case Status.stable: return this.stableNum;
6868
case Status.reserved: return this.reservedNum;
69-
case Status.deprecated: return this.deprecateNum;
69+
case Status.deprecated: return this.deprecatedNum;
70+
default: throw new Error(`Unknown term status: ${status}`);
7071
}
7172
}
7273
}
@@ -86,20 +87,20 @@ export interface Contexts {
8687
*/
8788
export interface GlobalData {
8889
/** Vocabulary prefix for the vocabulary being handled. */
89-
vocab_prefix : string,
90+
vocab_prefix : string;
9091

9192
/** Vocabulary URL for the vocabulary being handled. */
92-
vocab_url : string,
93+
vocab_url : string;
9394

9495
/** Default context URL for the vocabulary being handled. */
95-
vocab_context ?: string,
96+
vocab_context ?: string;
9697

9798
/**
9899
* Counter for the terms with various status values.
99100
* Some serializers (e.g. HTML) may optimize/improve the final
100101
* output if one of the categories have no entries whatsoever.
101102
*/
102-
status_counter : StatusCounter,
103+
status_counter : StatusCounter;
103104

104105
/**
105106
* Inverted info for contexts: for each context the list of relevant terms are listed.
@@ -194,7 +195,7 @@ export interface ValidationResults {
194195
* If the content is valid, the error array is empty. Otherwise, the vocab field is null, and
195196
* the validation error(s) are returned.
196197
*/
197-
vocab : RawVocab | null,
198+
vocab : RawVocab | null;
198199
error : ValidationError[];
199200
}
200201

@@ -203,9 +204,9 @@ export interface ValidationResults {
203204
* the generic Ajv error message is way too complex for our use)
204205
*/
205206
export interface ValidationError {
206-
message ?: string,
207-
params ?: any,
208-
data ?: any,
207+
message ?: string;
208+
params ?: any;
209+
data ?: any;
209210
}
210211

211212
/* ************************************* Internal representation ***********************************/
@@ -302,11 +303,11 @@ export interface OntologyProperty {
302303
* possibly, datatypes and individuals…
303304
*/
304305
export interface Vocab {
305-
prefixes : RDFPrefix[],
306-
ontology_properties : OntologyProperty[]
307-
classes : RDFClass[],
308-
properties : RDFProperty[],
309-
individuals : RDFIndividual[],
310-
datatypes : RDFDatatype[],
306+
prefixes : RDFPrefix[];
307+
ontology_properties : OntologyProperty[];
308+
classes : RDFClass[];
309+
properties : RDFProperty[];
310+
individuals : RDFIndividual[];
311+
datatypes : RDFDatatype[];
311312
}
312313

lib/context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ const preamble: Context = {
2424
* Generate the minimal JSON-LD context for the vocabulary.
2525
*
2626
* @param vocab - The internal representation of the vocabulary
27-
* @returns
27+
* @returns - the full context in string (ready to be written to a file)
2828
*/
2929
export function toContext(vocab: Vocab): string {
3030
// Generation of a unit for properties
31-
const propertyContext = (property: RDFProperty, for_class = true): Context|string => {
31+
const propertyContext = (property: RDFProperty, forClass = true): Context|string => {
3232
// the real id of the property...
33-
const url = `${global.vocab_url}${property.id}`
33+
const url = `${global.vocab_url}${property.id}`;
3434
const output: Context = {
3535
"@id" : url
3636
}
37-
if (for_class || property.type.includes("owl:ObjectProperty")) {
37+
if (forClass || property.type.includes("owl:ObjectProperty")) {
3838
output["@type"] = "@id";
3939
}
4040
// Try to catch the datatype settings; these can be used
@@ -45,7 +45,7 @@ export function toContext(vocab: Vocab): string {
4545
output["@type"] = range.replace('xsd:', 'http://www.w3.org/2001/XMLSchema#');
4646
break;
4747
} else if (range === "rdf:List") {
48-
output["@container"] = "@list"
48+
output["@container"] = "@list";
4949
}
5050
}
5151
}
@@ -107,7 +107,7 @@ export function toContext(vocab: Vocab): string {
107107

108108
// Add the individuals
109109
for (const individual of vocab.individuals) {
110-
top_level[individual.id] = `${global.vocab_url}${individual.id}`
110+
top_level[individual.id] = `${global.vocab_url}${individual.id}`;
111111
}
112112

113113
// Add the datatypes

lib/html.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MiniDOM {
3333
private readonly _localDocument: Document;
3434

3535
constructor(html_text: string) {
36-
const doc = (new JSDOM(html_text)).window._document;
36+
const doc = (new JSDOM(html_text)).window.document;
3737
if (doc) {
3838
this._localDocument = doc;
3939
} else {
@@ -58,7 +58,9 @@ class MiniDOM {
5858
addChild(parent: Element, element: string, content: string | undefined = undefined): Element {
5959
const new_element = this._localDocument.createElement(element);
6060
parent.appendChild(new_element);
61-
if (content !== undefined) new_element.innerHTML = content;
61+
if (content !== undefined) {
62+
new_element.innerHTML = content;
63+
}
6264
return new_element;
6365
}
6466

@@ -211,17 +213,7 @@ export function toHTML(vocab: Vocab, template_text: string): string {
211213
// curie
212214
output = computeHash(curie) /* curie */;
213215

214-
// This is still a matter of discussion... I am not sure that this is the
215-
// right approach. However, I am an RDF oriented person...
216-
// h4 = document.addChild(section,'h4', `<code>${curie}</code>`);
217216
document.addChild(section,'h4', `<code>${item.id}</code>`);
218-
219-
// A single RDFa statement is added to the lot to ensure a proper relationship
220-
// to the "real" URL of the external term
221-
section.setAttribute('about', `${vocab_url}${curie}`);
222-
section.setAttribute('rel', 'owl:sameAs');
223-
section.setAttribute('resource', `${curie}`);
224-
225217
const term = document.addChild(section, 'p', `<em>${item.label}</code>`);
226218

227219
if (item.status !== Status.stable) {
@@ -368,7 +360,8 @@ export function toHTML(vocab: Vocab, template_text: string): string {
368360
return { id_prefix : 'reserved_', intro_prefix: '<em><strong>reserved</strong></em>' };
369361
case Status.stable :
370362
return { id_prefix : '', intro_prefix : '' };
371-
363+
default :
364+
throw new Error(`Unknown status: ${status}`);
372365
}
373366
}
374367

@@ -810,7 +803,11 @@ export function toHTML(vocab: Vocab, template_text: string): string {
810803
}
811804

812805
// That is it... generate the output
813-
// I wish it was possible to generate a properly formatted HTML source, but I am not sure how to do that
806+
// To generate a properly formatted HTML source, consider using a library like 'pretty' or 'js-beautify'.
807+
// Example:
808+
// import { format } from 'pretty';
809+
// return format(`<!DOCTYPE html>\n<html lang="en">${document.innerHTML()}</html>`, { ocd: true });
810+
814811
return `<!DOCTYPE html>\n<html lang="en">${document.innerHTML()}</html>`;
815812
}
816813

lib/turtle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { Vocab, global, RDFTerm, Link, Status } from './common';
1111
* Nothing complex, just a straightforward conversion of the information into the turtle syntax.
1212
*
1313
* @param vocab - The internal representation of the vocabulary
14-
* @returns
15-
* @async
14+
* @returns - the full Turtle representation of the vocabulary
1615
*/
1716
export function toTurtle(vocab: Vocab): string {
1817

0 commit comments

Comments
 (0)