feature/nodejs_implementation #1

Merged
revengeday merged 11 commits from zeyus/hit-counter:feature/nodejs_implementation into main 2024-11-07 15:30:00 +00:00
3 changed files with 12 additions and 11 deletions
Showing only changes of commit a2e698d2f6 - Show all commits

View file

@ -90,7 +90,7 @@ interface HitCounterConfig {
## Usage
```ts
import { HitCounter, ImageHitCounterRenderer } from "./hit-counter";
import { HitCounter } from "./hit-counter";
// default config
@ -113,13 +113,14 @@ defaultHitCounterConfig = {
secondaryTextColorRGB: { r: 0, g: 255, b: 0 },
numberColorRGB: { r: 255, g: 255, b: 255 },
frameColorRGB: { r: 255, g: 0, b: 0 },
drawFrame: true,
renderer: ImageHitCounterRenderer
drawFrame: true
};
// the default config will be used, but you can pass a custom config object as
// the second argument to the HitCounter constructor
const hitCounter = new HitCounter(ImageHitCounterRenderer);
// the first argument to the HitCounter constructor
// e.g. const hitCounter = new HitCounter(customConfig);
// the second argument is reserved for the renderer, but currently only the ImageHitCounterRenderer is implemented
const hitCounter = new HitCounter();
// increment the hit counter
hitCounter.increment(); // async function

View file

@ -346,12 +346,12 @@ class HitCounter {
/**
* Creates an instance of HitCounter.
*
* @param {Type<BaseHitCounterRenderer>} renderer
* The hit counter renderer.
* @param {HitCounterConfig} [config=defaultHitCounterConfig]
* The hit counter configuration.
* The hit counter configuration. Defaults to defaultHitCounterConfig.
* @param {Type<BaseHitCounterRenderer>} renderer
* The hit counter renderer. Defaults to ImageHitCounterRenderer.
*/
constructor(renderer: Type<BaseHitCounterRenderer>, config: HitCounterConfig = defaultHitCounterConfig) {
constructor(config: HitCounterConfig = defaultHitCounterConfig, renderer: Type<BaseHitCounterRenderer> = ImageHitCounterRenderer) {
config = { ...defaultHitCounterConfig, ...config };
this.config = config;
this.renderer = new renderer(this, config);

View file

@ -1,9 +1,9 @@
import express, { Express, Request, Response } from "express";
import { HitCounter, ImageHitCounterRenderer } from "./hit-counter";
import { HitCounter } from "./hit-counter";
const app: Express = express();
const PORT: number = 8000;
const hitCounter = new HitCounter(ImageHitCounterRenderer);
const hitCounter = new HitCounter();
const imageMimeType = hitCounter.getMimeType();
app.get("/", (req: Request, res: Response) => {