@ankitraj026/ngsdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +24 -0
- package/dist/ngsdk.js +40 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# ngSdk
|
|
2
|
+
|
|
3
|
+
A minimal TypeScript SDK that logs `"start"` when a button is clicked.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
**Option 1 – Attach to a specific button:**
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { onButtonClick } from 'ngsdk';
|
|
18
|
+
|
|
19
|
+
const btn = document.querySelector('button');
|
|
20
|
+
if (btn) onButtonClick(btn);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Option 2 – Init with a selector (default: first `button`):**
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { init } from 'ngsdk';
|
|
27
|
+
|
|
28
|
+
init(); // uses first <button>
|
|
29
|
+
init('#my-btn'); // uses element matching #my-btn
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Clicking the button will log `start` in the console.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach a click handler to a button that logs "start".
|
|
3
|
+
* @param button - The button element to attach the handler to
|
|
4
|
+
*/
|
|
5
|
+
export declare function onButtonClick(button: HTMLButtonElement): void;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the SDK by attaching the click handler to the first button
|
|
8
|
+
* matching the given selector (default: "button").
|
|
9
|
+
*/
|
|
10
|
+
export declare function init(selector?: string): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onButtonClick = onButtonClick;
|
|
4
|
+
exports.init = init;
|
|
5
|
+
/**
|
|
6
|
+
* Attach a click handler to a button that logs "start".
|
|
7
|
+
* @param button - The button element to attach the handler to
|
|
8
|
+
*/
|
|
9
|
+
function onButtonClick(button) {
|
|
10
|
+
button.addEventListener('click', () => {
|
|
11
|
+
console.log('start');
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the SDK by attaching the click handler to the first button
|
|
16
|
+
* matching the given selector (default: "button").
|
|
17
|
+
*/
|
|
18
|
+
function init(selector = 'button') {
|
|
19
|
+
console.log('init ############');
|
|
20
|
+
const button = document.querySelector(selector);
|
|
21
|
+
if (button) {
|
|
22
|
+
onButtonClick(button);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/ngsdk.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ngSdk = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
init: () => init,
|
|
25
|
+
onButtonClick: () => onButtonClick
|
|
26
|
+
});
|
|
27
|
+
function onButtonClick(button) {
|
|
28
|
+
button.addEventListener("click", () => {
|
|
29
|
+
console.log("start");
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function init(selector = "button") {
|
|
33
|
+
console.log("init ############");
|
|
34
|
+
const button = document.querySelector(selector);
|
|
35
|
+
if (button) {
|
|
36
|
+
onButtonClick(button);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return __toCommonJS(src_exports);
|
|
40
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ankitraj026/ngsdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A minimal TypeScript SDK that logs \"start\" when a button is clicked.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"build:ngsdk": "npm run build",
|
|
14
|
+
"build:browser": "esbuild src/index.ts --bundle --format=iife --global-name=ngSdk --outfile=dist/ngsdk.js",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"ngsdk:publish": "npm publish --access public",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
},
|
|
19
|
+
"keywords": ["sdk", "button", "typescript"],
|
|
20
|
+
"author": "Ankit Raj",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"esbuild": "^0.19.0",
|
|
24
|
+
"typescript": "^5.3.0"
|
|
25
|
+
}
|
|
26
|
+
}
|