Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Nov 14, 2024
1 parent 073dc0d commit 425edbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ An ES (JavaScript & TypeScript) module to provide an easier and simplified metho
encryptToRequestBody(value: string): GitHubRESTSetPublicKeyRequestBody;
getKeyID(): string | undefined;
get keyID(): string | undefined;
static createFromJSON(input: JSONObject): GitHubSodiumSealer;
static async createFromResponse(input: Response): Promise<GitHubSodiumSealer>;
static fromJSON(input: JSONObject): GitHubSodiumSealer;
static async fromResponse(input: Response): Promise<GitHubSodiumSealer>;
}
```
- ```ts
Expand Down
10 changes: 5 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class GitHubSodiumSealer {
typeof keyID === "undefined" ||
(typeof keyID === "string" && keyID.length > 0)
)) {
throw new SyntaxError(`Parameter \`keyID\` is not \`undefined\`, or a string which is non empty!`);
throw new TypeError(`Parameter \`keyID\` is not \`undefined\`, or a string which is non empty!`);
}
if (!(publicKey.length > 0)) {
throw new SyntaxError(`Parameter \`publicKey\` is not a string which is non empty!`);
Expand All @@ -54,7 +54,7 @@ export class GitHubSodiumSealer {
*/
encryptToRequestBody(value: string): GitHubRESTSetPublicKeyRequestBody {
if (this.#keyID !== "string") {
throw new Error(`\`keyID\` was not defined at the initialize stage!`);
throw new Error(`Key ID was not defined at the initialize stage!`);
}
return {
encrypted_value: this.encrypt(value),
Expand All @@ -80,7 +80,7 @@ export class GitHubSodiumSealer {
* @param {JSONObject} input {@linkcode Response} JSON body.
* @returns {GitHubSodiumSealer} GitHub sodium sealer.
*/
static createFromJSON(input: JSONObject): GitHubSodiumSealer {
static fromJSON(input: JSONObject): GitHubSodiumSealer {
if (
typeof input.key !== "string" ||
typeof input.key_id !== "string"
Expand All @@ -94,12 +94,12 @@ export class GitHubSodiumSealer {
* @param {Response} input {@linkcode Response}.
* @returns {Promise<GitHubSodiumSealer>} GitHub sodium sealer.
*/
static async createFromResponse(input: Response): Promise<GitHubSodiumSealer> {
static async fromResponse(input: Response): Promise<GitHubSodiumSealer> {
const responsePayload = await input.clone().json();
if (!isJSONObject(responsePayload)) {
throw new Error(`Parameter \`input\` is not a valid response!`);
}
return GitHubSodiumSealer.createFromJSON(responsePayload);
return GitHubSodiumSealer.fromJSON(responsePayload);
}
/**
* Encrypt value to the GitHub secret value.
Expand Down

0 comments on commit 425edbd

Please sign in to comment.