Skip to content

Commit

Permalink
feat: Add eslint-config-noir version 1.2.0 (#53)
Browse files Browse the repository at this point in the history
* feat: Add `eslint-config-noir` version `1.2.0`

* refactor: Add `noir/all` eslint config

* chore: Add .gitattributes
  • Loading branch information
ardalanamini committed Jun 19, 2022
1 parent ae3a5fb commit fb2c740
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 109 deletions.
32 changes: 4 additions & 28 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,13 @@ env:
es2021: true
node: true
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
parser: '@typescript-eslint/parser'
- noir/all
parserOptions:
ecmaVersion: 12
project: ./tsconfig.json
ecmaVersion: latest
sourceType: module
plugins:
- '@typescript-eslint'
- import
rules:
indent: off
"@typescript-eslint/indent":
- error
- 2
- SwitchCase: 1
quotes: off
"@typescript-eslint/quotes":
- error
- double
- avoidEscape: true
semi: off
"@typescript-eslint/semi":
- error
- always
comma-dangle: off
"@typescript-eslint/comma-dangle":
- error
- always-multiline
max-len:
- error
- 120
import/no-unresolved: off
import/extensions:
- error
- always
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.ts text eol=lf
*.js text eol=lf
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@typescript-eslint/parser": "^5.28.0",
"axios": "^0.27.2",
"eslint": "^8.18.0",
"eslint-config-noir": "^1.2.0",
"eslint-plugin-import": "^2.26.0",
"typescript": "^4.7.4"
}
Expand Down
54 changes: 28 additions & 26 deletions src/Kutt.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Domain, Health, Link, User } from "./api/index.js";
import CONFIG, { ConfigI } from "./config.js";
import { Domain, Health, Link, User } from "./api/index.js";

/**
*
* @see {@link https://docs.kutt.it}
*/
export default class Kutt {

/**
* Sets default/global config.
*
* @param config
* @param value
* @private
*/
public static set<Config extends keyof ConfigI>(config: Config, value: ConfigI[Config]): typeof Kutt {
CONFIG[config] = value;

return this;
}
#config: ConfigI = { ...CONFIG };

/**
* Gets default/global config.
Expand All @@ -28,39 +23,33 @@ export default class Kutt {
}

/**
*
* @private
*/
#config: ConfigI = { ...CONFIG };

/**
* Sets instance config.
* Sets default/global config.
*
* @param config
* @param value
*/
public set<Config extends keyof ConfigI>(config: Config, value: ConfigI[Config]): this {
this.#config[config] = value;
public static set<Config extends keyof ConfigI>(config: Config, value: ConfigI[Config]): typeof Kutt {
CONFIG[config] = value;

return this;
}

/**
* Gets instance config.
* Domains API.
*
* @param config
* @see {@link https://docs.kutt.it/#tag/domains}
*/
public get<Config extends keyof ConfigI>(config: Config): ConfigI[Config] {
return this.#config[config];
public domains(): Domain {
return new Domain(this.#config);
}

/**
* Domains API.
* Gets instance config.
*
* @see {@link https://docs.kutt.it/#tag/domains}
* @param config
*/
public domains(): Domain {
return new Domain(this.#config);
public get<Config extends keyof ConfigI>(config: Config): ConfigI[Config] {
return this.#config[config];
}

/**
Expand All @@ -81,6 +70,18 @@ export default class Kutt {
return new Link(this.#config);
}

/**
* Sets instance config.
*
* @param config
* @param value
*/
public set<Config extends keyof ConfigI>(config: Config, value: ConfigI[Config]): this {
this.#config[config] = value;

return this;
}

/**
* Users API.
*
Expand All @@ -89,4 +90,5 @@ export default class Kutt {
public users(): User {
return new User(this.#config);
}

}
8 changes: 5 additions & 3 deletions src/api/API.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ConfigI } from "../config.js";
import axios, { AxiosInstance } from "axios";
import type { ConfigI } from "../config.js";

/**
*
*/
export default abstract class API {

/**
*
* @protected
Expand All @@ -21,7 +22,7 @@ export default abstract class API {
*
* @param config
*/
constructor(config: ConfigI) {
public constructor(config: ConfigI) {
const { api, key, timeout } = config;

this.axios = axios.create({
Expand All @@ -39,6 +40,7 @@ export default abstract class API {
* @protected
*/
protected url(url = ""): string {
return `${this.prefix}${url}`;
return `${ this.prefix }${ url }`;
}

}
12 changes: 7 additions & 5 deletions src/api/Domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import API from "./API.js";
* @see {@link https://docs.kutt.it/#tag/domains}
*/
export default class Domain extends API {

/**
*
* @protected
Expand All @@ -16,7 +17,7 @@ export default class Domain extends API {
*
* @param domain
*/
public create(domain: NewDomainI): Promise<DomainI> {
public async create(domain: NewDomainI): Promise<DomainI> {
return this.axios
.post<DomainI>(this.url(), domain)
.then(({ data }) => data);
Expand All @@ -27,11 +28,12 @@ export default class Domain extends API {
*
* @param id
*/
public remove(id: string): Promise<string> {
public async remove(id: string): Promise<string> {
return this.axios
.delete<{ message: string }>(this.url(`/${id}`))
.delete<{ message: string }>(this.url(`/${ id }`))
.then(({ data }) => data.message);
}

}

export interface NewDomainI {
Expand All @@ -40,10 +42,10 @@ export interface NewDomainI {
}

export interface DomainI {
id: string;
address: string;
banned: boolean;
created_at: string;
updated_at: string;
homepage?: string;
id: string;
updated_at: string;
}
4 changes: 3 additions & 1 deletion src/api/Health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import API from "./API.js";
* @see {@link https://docs.kutt.it/#tag/health}
*/
export default class Health extends API {

/**
*
* @protected
Expand All @@ -14,9 +15,10 @@ export default class Health extends API {
/**
* Checks API health.
*/
public check(): Promise<boolean> {
public async check(): Promise<boolean> {
return this.axios.get(this.url())
.then(() => true)
.catch(() => false);
}

}

0 comments on commit fb2c740

Please sign in to comment.