From 1340e2d592da49a023db114af7c9c6778d0d981b Mon Sep 17 00:00:00 2001 From: Andrew <76942911+alexfeed1990@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:39:12 +0200 Subject: [PATCH 1/2] Update html.ts --- src/html.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/html.ts b/src/html.ts index 984a2a3..937f408 100644 --- a/src/html.ts +++ b/src/html.ts @@ -54,6 +54,19 @@ export default class Html { queryHtml(selector: string): Html | null { return new Html(this.elm.querySelector(selector) as HTMLElement); } + /** + * Adds an ID to an element. + * @param val The ID to add. + * @returns Html + */ + class(val: string[]): Html { + if(this.elm.id != null) { + throw Error("The element already has an ID."); + } + this.elm.id = val; + return this; + } + /** * Toggle on/off a class. * @param val The class to toggle. From b547212a1bce699a1d54210cde9a3d6ba68582b4 Mon Sep 17 00:00:00 2001 From: Andrew <76942911+alexfeed1990@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:07:46 +0200 Subject: [PATCH 2/2] Add ID function and other QOL changes. --- README.md | 22 ++++++++++++++++++++++ dist/html.d.ts | 6 ++++++ dist/html.js | 12 ++++++++++++ build.js => format.js | 3 ++- package-lock.json | 4 ++-- package.json | 2 +- src/html.ts | 7 +++---- 7 files changed, 48 insertions(+), 8 deletions(-) rename build.js => format.js (79%) diff --git a/README.md b/README.md index b2c8b44..30dc6c4 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,12 @@ There are a few more advanced methods to how the Html class works: new Html("span").classOff("my-class"); // ``` +- `.id()` + Set the id of an element + ```js + new Html("div").id("my-id"); + //
+ ``` - `.on(eventName, eventHandler)` Add an event listener @@ -299,6 +305,22 @@ There are a few more advanced methods to how the Html class works: input.getValue(); // 'I typed this text' ``` +## Building + +Clone the repository: + +``` +git clone https://github.com/datkat21/html.git +cd html +``` + +Install dependencies and run build script: + +``` +npm i +npm run build # Build script. +``` + ## Repository You can find the repository [on GitHub.](https://github.com/datkat21/html) \ No newline at end of file diff --git a/dist/html.d.ts b/dist/html.d.ts index cc90cd6..203a478 100644 --- a/dist/html.d.ts +++ b/dist/html.d.ts @@ -35,6 +35,12 @@ export default class Html { * @returns The HTML element (as Html) */ queryHtml(selector: string): Html | null; + /** + * Sets the ID of the element. + * @param val The ID to set. + * @returns Html + */ + id(val: string): Html; /** * Toggle on/off a class. * @param val The class to toggle. diff --git a/dist/html.js b/dist/html.js index 5f01d39..c69a065 100644 --- a/dist/html.js +++ b/dist/html.js @@ -54,6 +54,18 @@ export default class Html { queryHtml(selector) { return new Html(this.elm.querySelector(selector)); } + /** + * Sets the ID of the element. + * @param val The ID to set. + * @returns Html + */ + id(val) { + if (this.elm.id != null) { + throw Error("The element already has an ID."); + } + this.elm.id = val; + return this; + } /** * Toggle on/off a class. * @param val The class to toggle. diff --git a/build.js b/format.js similarity index 79% rename from build.js rename to format.js index 0224c3c..cc41a9e 100644 --- a/build.js +++ b/format.js @@ -14,4 +14,5 @@ const result = await format(compiledJsContent, { filepath: compiledJsPath }); -fs.writeFileSync(compiledJsPath, result); \ No newline at end of file +fs.writeFileSync(compiledJsPath, result); +console.log(`Formatting (and building) complete. Wrote to ${compiledJsPath}`) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0732c72..ecff126 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@datkat21/html", - "version": "1.1.0", + "version": "1.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@datkat21/html", - "version": "1.1.0", + "version": "1.1.2", "license": "ISC", "devDependencies": { "prettier": "^3.0.3", diff --git a/package.json b/package.json index 97d6e7f..b4c776f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "author": "datkat21", "license": "ISC", "scripts": { - "build": "npx tsc && node build.js" + "build": "npx tsc && node format.js" }, "repository": { "type": "git", diff --git a/src/html.ts b/src/html.ts index 937f408..706df41 100644 --- a/src/html.ts +++ b/src/html.ts @@ -55,18 +55,17 @@ export default class Html { return new Html(this.elm.querySelector(selector) as HTMLElement); } /** - * Adds an ID to an element. - * @param val The ID to add. + * Sets the ID of the element. + * @param val The ID to set. * @returns Html */ - class(val: string[]): Html { + id(val: string): Html { if(this.elm.id != null) { throw Error("The element already has an ID."); } this.elm.id = val; return this; } - /** * Toggle on/off a class. * @param val The class to toggle.