Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Jul 22, 2022
1 parent e64aac6 commit 579c483
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 272 deletions.
4 changes: 2 additions & 2 deletions signalk-client/apps-api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** Signal K server Apps API */
export class SignalKApps {
/** apps API endpoint. */
public endpoint = "";
public endpoint = '';

/** Return List of installed apps. */
async list() {
const ep = this.endpoint.indexOf("webapps") === -1
const ep = this.endpoint.indexOf('webapps') === -1
? `${this.endpoint}list`
: this.endpoint;
const response = await fetch(ep);
Expand Down
80 changes: 40 additions & 40 deletions signalk-client/http-api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Alarm, AlarmType, Path } from "./utils.ts";
import { SKServer } from "./signalk-client.ts";
import { debug } from "./mod.ts";
import { Alarm, AlarmType, Path } from './utils.ts';
import { SKServer } from './signalk-client.ts';
import { debug } from './mod.ts';

/** Signal K HTTP API operations */
export class SignalKHttp {
/** Authentication token
* @private
*/
private _token = "";
private _token = '';

/** Signal K server information */
public server: SKServer = { version: "", id: "" };
public server: SKServer = { version: '', id: '' };
/** Connection endpoint */
public endpoint = "";
public endpoint = '';
/** API version to use */
public version = 1;

Expand Down Expand Up @@ -62,14 +62,14 @@ export class SignalKHttp {
}
let ep: string;
let path: string;
if (typeof p1 === "number") {
ep = this.endpoint.replace(new RegExp("/v[0-9]+/"), `/v${p1}/`);
if (typeof p1 === 'number') {
ep = this.endpoint.replace(new RegExp('/v[0-9]+/'), `/v${p1}/`);
path = Path.dotToSlash(p2);
} else {
ep = this.endpoint;
path = Path.dotToSlash(p1);
}
if (path[0] === "/") {
if (path[0] === '/') {
path = path.slice(1);
}
const url = `${ep}${path}`;
Expand Down Expand Up @@ -114,8 +114,8 @@ export class SignalKHttp {
let path: string;
let value;
let msg;
if (typeof p1 === "number") {
ep = this.endpoint.replace(new RegExp("/v[0-9]+/"), `/v${p1}/`);
if (typeof p1 === 'number') {
ep = this.endpoint.replace(new RegExp('/v[0-9]+/'), `/v${p1}/`);
path = Path.dotToSlash(p2);
value = p3;
msg = this.parseApiPut(p1, value);
Expand All @@ -125,19 +125,19 @@ export class SignalKHttp {
value = p2;
msg = this.parseApiPut(this.version, value);
}
if (path[0] === "/") {
if (path[0] === '/') {
path = path.slice(1);
}

const url = `${ep}${path}`;
debug(`put ${url}`);
const headers = new Headers({ "Content-Type": "application/json" });
const headers = new Headers({ 'Content-Type': 'application/json' });
if (this._token) {
headers.append("Authorization", `JWT ${this._token}`);
headers.append('Authorization', `JWT ${this._token}`);
}

const options: RequestInit = {
method: "PUT",
method: 'PUT',
headers: headers,
body: JSON.stringify(msg),
};
Expand Down Expand Up @@ -176,32 +176,32 @@ export class SignalKHttp {
let context: string;
let value;
let msg;
if (typeof p1 === "number") {
ep = this.endpoint.replace(new RegExp("/v[0-9]+/"), `/v${p1}/`);
context = p2 ? `${Path.contextToPath(p2)}/` : "";
if (typeof p1 === 'number') {
ep = this.endpoint.replace(new RegExp('/v[0-9]+/'), `/v${p1}/`);
context = p2 ? `${Path.contextToPath(p2)}/` : '';
path = Path.dotToSlash(p3);
value = p4;
msg = this.parseApiPut(p1, value);
} else {
ep = this.endpoint;
context = p1 ? `${Path.contextToPath(p1)}/` : "";
context = p1 ? `${Path.contextToPath(p1)}/` : '';
path = Path.dotToSlash(p2);
value = p3;
msg = this.parseApiPut(this.version, value);
}
if (path[0] === "/") {
if (path[0] === '/') {
path = path.slice(1);
}

const url = ep + context + path;
debug(`put ${url}`);
const headers = new Headers({ "Content-Type": "application/json" });
const headers = new Headers({ 'Content-Type': 'application/json' });
if (this._token) {
headers.append("Authorization", `JWT ${this._token}`);
headers.append('Authorization', `JWT ${this._token}`);
}

const options: RequestInit = {
method: "PUT",
method: 'PUT',
headers: headers,
body: JSON.stringify(msg),
};
Expand All @@ -226,27 +226,27 @@ export class SignalKHttp {
let ep: string;
let path: string;
let value;
if (typeof p1 === "number") {
ep = this.endpoint.replace(new RegExp("/v[0-9]+/"), `/v${p1}/`);
if (typeof p1 === 'number') {
ep = this.endpoint.replace(new RegExp('/v[0-9]+/'), `/v${p1}/`);
path = Path.dotToSlash(p2);
value = p3;
} else {
ep = this.endpoint;
path = Path.dotToSlash(p1);
value = p2;
}
if (path[0] === "/") {
if (path[0] === '/') {
path = path.slice(1);
}
const url = `${ep}${path}`;
debug(`post ${url}`);
const headers = new Headers({ "Content-Type": "application/json" });
const headers = new Headers({ 'Content-Type': 'application/json' });
if (this._token) {
headers.append("Authorization", `JWT ${this._token}`);
headers.append('Authorization', `JWT ${this._token}`);
}

const options: RequestInit = {
method: "POST",
method: 'POST',
headers: headers,
body: JSON.stringify(value),
};
Expand All @@ -268,25 +268,25 @@ export class SignalKHttp {
}
let ep: string;
let path: string;
if (typeof p1 === "number") {
ep = this.endpoint.replace(new RegExp("/v[0-9]+/"), `/v${p1}/`);
if (typeof p1 === 'number') {
ep = this.endpoint.replace(new RegExp('/v[0-9]+/'), `/v${p1}/`);
path = Path.dotToSlash(p2);
} else {
ep = this.endpoint;
path = Path.dotToSlash(p1);
}
if (path[0] === "/") {
if (path[0] === '/') {
path = path.slice(1);
}
const url = `${ep}${path}`;
debug(`get ${url}`);
const headers = new Headers({ "Content-Type": "application/json" });
const headers = new Headers({ 'Content-Type': 'application/json' });
if (this._token) {
headers.append("Authorization", `JWT ${this._token}`);
headers.append('Authorization', `JWT ${this._token}`);
}

const options: RequestInit = {
method: "DELETE",
method: 'DELETE',
headers: headers,
};
return await fetch(url, options);
Expand All @@ -304,10 +304,10 @@ export class SignalKHttp {
*/
raiseAlarm(context: string, name: string, alarm: Alarm): Promise<Response>;
raiseAlarm(context: string, type: AlarmType, alarm: Alarm): Promise<Response>;
raiseAlarm(context = "*", alarmId: string | AlarmType, alarm: Alarm) {
raiseAlarm(context = '*', alarmId: string | AlarmType, alarm: Alarm) {
let path: string;
if (typeof alarmId === "string") {
path = alarmId.indexOf("notifications.") === -1
if (typeof alarmId === 'string') {
path = alarmId.indexOf('notifications.') === -1
? `notifications.${alarmId}`
: alarmId;
} else {
Expand All @@ -320,8 +320,8 @@ export class SignalKHttp {
* @param context Signal K context
* @param name Alarm name.
*/
clearAlarm(context = "*", name: string): Promise<Response> {
const path = name.indexOf("notifications.") === -1
clearAlarm(context = '*', name: string): Promise<Response> {
const path = name.indexOf('notifications.') === -1
? `notifications.${name}`
: name;
return this.putWithContext(context, path, null);
Expand Down
12 changes: 6 additions & 6 deletions signalk-client/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Signal K Client
*****************************/

export * from "./signalk-client.ts";
export * from "./utils.ts";
export * from "./stream-api.ts";
export * from "./http-api.ts";
export * from "./apps-api.ts";
export * from './signalk-client.ts';
export * from './utils.ts';
export * from './stream-api.ts';
export * from './http-api.ts';
export * from './apps-api.ts';

let _isDev = false;

Expand All @@ -18,6 +18,6 @@ export function setDev(val?: boolean) {
/** Print debug messages to console (if development mode) */
export function debug(...args: any[]) {
if (_isDev) {
console.log(`%cSignalKClient: `, "color: yellow", ...args);
console.log(`%cSignalKClient: `, 'color: yellow', ...args);
}
}
Loading

0 comments on commit 579c483

Please sign in to comment.