@avatar-generator/core 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/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ export function getInitials(name) {
2
+ return name
3
+ .split(" ")
4
+ .map((part) => part[0].toUpperCase())
5
+ .join("");
6
+ }
7
+ export function createAvatar({ name, backgroundColor = "#ccc", textColor = "#fff", fontSize = "40px", shape = "circle", }) {
8
+ const initials = getInitials(name);
9
+ const avatar = document.createElement("div");
10
+ avatar.style.width = "100px";
11
+ avatar.style.height = "100px";
12
+ avatar.style.backgroundColor = backgroundColor;
13
+ avatar.style.color = textColor;
14
+ avatar.style.display = "flex";
15
+ avatar.style.justifyContent = "center";
16
+ avatar.style.alignItems = "center";
17
+ avatar.style.fontSize = fontSize;
18
+ avatar.style.borderRadius = shape === "circle" ? "50%" : "0";
19
+ avatar.textContent = initials;
20
+ return avatar;
21
+ }
@@ -0,0 +1,9 @@
1
+ export declare function getInitials(name: string): string;
2
+ export interface AvatarOptions {
3
+ name: string;
4
+ backgroundColor?: string;
5
+ textColor?: string;
6
+ fontSize?: string;
7
+ shape?: "circle" | "square";
8
+ }
9
+ export declare function createAvatar({ name, backgroundColor, textColor, fontSize, shape, }: AvatarOptions): HTMLElement;
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@avatar-generator/core",
3
+ "version": "1.0.0",
4
+ "description": "Core logic for avatar generation",
5
+ "main": "dist/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ }
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,38 @@
1
+ export function getInitials(name: string): string {
2
+ return name
3
+ .split(" ")
4
+ .map((part) => part[0].toUpperCase())
5
+ .join("");
6
+ }
7
+
8
+ export interface AvatarOptions {
9
+ name: string;
10
+ backgroundColor?: string;
11
+ textColor?: string;
12
+ fontSize?: string;
13
+ shape?: "circle" | "square";
14
+ }
15
+
16
+ export function createAvatar({
17
+ name,
18
+ backgroundColor = "#ccc",
19
+ textColor = "#fff",
20
+ fontSize = "40px",
21
+ shape = "circle",
22
+ }: AvatarOptions): HTMLElement {
23
+ const initials = getInitials(name);
24
+
25
+ const avatar = document.createElement("div");
26
+ avatar.style.width = "100px";
27
+ avatar.style.height = "100px";
28
+ avatar.style.backgroundColor = backgroundColor;
29
+ avatar.style.color = textColor;
30
+ avatar.style.display = "flex";
31
+ avatar.style.justifyContent = "center";
32
+ avatar.style.alignItems = "center";
33
+ avatar.style.fontSize = fontSize;
34
+ avatar.style.borderRadius = shape === "circle" ? "50%" : "0";
35
+ avatar.textContent = initials;
36
+
37
+ return avatar;
38
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationDir": "./dist/types",
5
+ "outDir": "./dist",
6
+ "esModuleInterop": true,
7
+ "module": "ESNext",
8
+ "moduleResolution": "Node",
9
+ "target": "ESNext",
10
+ "rootDir": "src"
11
+ },
12
+ "include": ["src"]
13
+ }