cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf). It produces a JSON summary and a GUI for exploring the complexity of your codebase.
75 lines • 1.76 kB
JavaScript
export function addStyleSheet(jsUrl) {
const finalDot = jsUrl.length - 3;
const urlWithoutExtension = jsUrl.substring(0, finalDot);
document.head.appendChild(element("link", {
href: urlWithoutExtension + ".css",
rel: "stylesheet",
}));
}
export function element(tagName, attrs, ...inner) {
const elem = document.createElement(tagName);
if (attrs) {
for (const key in attrs) {
elem[key] = attrs[key];
}
}
if (inner) {
elem.append(...inner);
}
return elem;
}
export function fragment(...children) {
const fragment = document.createDocumentFragment();
fragment.append(...children);
return fragment;
}
export class Observable {
constructor(value) {
this.value = value;
}
get() {
return this.value;
}
onChange(handler) {
this.handler = handler;
}
set(newValue) {
this.value = newValue;
if (this.handler) {
this.handler(this.value);
}
}
}
export class Store {
constructor() {
this.map = new Map();
}
get(id) {
return this.map.get(id);
}
set(item) {
if (this.map.has(item.id)) {
const obs = this.map.get(item.id);
obs.set(item);
return obs;
}
else {
const obs = new Observable(item);
this.map.set(item.id, obs);
return obs;
}
}
*values() {
const iter = this.map.values();
for (const obs of iter) {
yield obs.get();
}
}
}
export class UniqueId {
static next() {
return UniqueId.nextId++;
}
}
UniqueId.nextId = Number.MIN_SAFE_INTEGER;
//# sourceMappingURL=framework.js.map