pixelheads 1.0.1 → 1.0.2

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 CHANGED
@@ -1,4 +1,6 @@
1
1
  # pixelheads
2
+ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/jojomatik/pixelheads?sort=semver)](https://github.com/jojomatik/pixel/releases) [![GitHub](https://img.shields.io/github/license/jojomatik/pixelheads)](LICENSE) [![Build and publish npm package](https://github.com/jojomatik/pixelheads/actions/workflows/publish.yml/badge.svg)](https://github.com/jojomatik/pixelheads/actions/workflows/publish.yml) [![npm](https://img.shields.io/npm/v/pixelheads)](https://www.npmjs.com/package/pixelheads) [![npm](https://img.shields.io/npm/dw/pixelheads)](https://www.npmjs.com/package/pixelheads)
3
+
2
4
  A library that makes it easy to retrieve skins and faces of minecraft players based on their uuid.
3
5
 
4
6
  ## Usage
@@ -14,8 +16,9 @@ A library that makes it easy to retrieve skins and faces of minecraft players ba
14
16
  const playerFace = pixelheads.getFaceAsBase64("uuid");
15
17
  ```
16
18
  3. Use one of the return values, e.g. in an `img`-tag:
17
- ```
18
- <img src="'data:image/png;base64,' + playerFace" alt="face of player"></img>
19
+ ```html
20
+ <img src="'data:image/png;base64,' + playerFace"
21
+ alt="face of player"/>
19
22
  ```
20
23
 
21
24
  ## Building
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /**
2
- * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
3
- * @param uuid the uuid of the player
4
- * @return the skin of the player encoded as a base64-string.
5
- */
6
- export declare function getSkinAsBase64(uuid: string): Promise<string>;
7
- /**
8
- * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
9
- * @param uuid the uuid of the player
10
- * @return the face of the player encoded as a base64-string.
11
- */
12
- export declare function getFaceAsBase64(uuid: string): Promise<string>;
1
+ /**
2
+ * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
3
+ * @param uuid the uuid of the player
4
+ * @return the skin of the player encoded as a base64-string.
5
+ */
6
+ export declare function getSkinAsBase64(uuid: string): Promise<string>;
7
+ /**
8
+ * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
9
+ * @param uuid the uuid of the player
10
+ * @return the face of the player encoded as a base64-string.
11
+ */
12
+ export declare function getFaceAsBase64(uuid: string): Promise<string>;
package/dist/index.js CHANGED
@@ -1,91 +1,91 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getFaceAsBase64 = exports.getSkinAsBase64 = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const sharp_1 = __importDefault(require("sharp"));
18
- /**
19
- * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
20
- * @param uuid the uuid of the player
21
- * @return the skin of the player encoded as a base64-string.
22
- */
23
- function getSkinAsBase64(uuid) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const response = yield axios_1.default.get("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
26
- // Fetch profile.
27
- const data = response.data;
28
- // Define error prefix.
29
- const errorMessage = "Couldn't retrieve skin for uuid " + uuid + ". Reason: ";
30
- if (data.error) {
31
- throw new Error(errorMessage + data.error + ": " + JSON.stringify(data));
32
- }
33
- if (!data.properties) {
34
- throw new Error(errorMessage + "No properties in response: " + JSON.stringify(data));
35
- }
36
- // Loop through properties and find 'textures' property.
37
- for (const property of data.properties) {
38
- if (property.name === "textures") {
39
- // Find object containing the skin URL.
40
- const response = JSON.parse(Buffer.from(property.value, "base64").toString());
41
- let skinURL;
42
- // Check if skin URL exists and retrieve it.
43
- if (response.textures &&
44
- response.textures.SKIN &&
45
- (skinURL = response.textures.SKIN.url)) {
46
- // Fetch skin URL and returns as base64.
47
- const b64 = yield axios_1.default
48
- .get(skinURL, { responseType: "arraybuffer" })
49
- .then((response) => response.data)
50
- .then((buffer) => {
51
- return Buffer.from(buffer).toString("base64");
52
- })
53
- .catch((error) => console.error(errorMessage + "Could not load buffer for URL " + skinURL, error));
54
- if (b64)
55
- return b64;
56
- else
57
- throw new Error(errorMessage + "No skin returned for URL " + skinURL);
58
- }
59
- else
60
- throw new Error(errorMessage +
61
- "No url to skin in response: " +
62
- JSON.stringify(response));
63
- }
64
- }
65
- throw new Error(errorMessage + "No textures object in response: " + JSON.stringify(data));
66
- });
67
- }
68
- exports.getSkinAsBase64 = getSkinAsBase64;
69
- /**
70
- * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
71
- * @param uuid the uuid of the player
72
- * @return the face of the player encoded as a base64-string.
73
- */
74
- function getFaceAsBase64(uuid) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const skin = yield getSkinAsBase64(uuid);
77
- const buffer = Buffer.from(skin, "base64");
78
- const sharpSkin = (0, sharp_1.default)(buffer);
79
- const sharpHead = sharpSkin.extract({ left: 8, top: 8, width: 8, height: 8 });
80
- return sharpHead
81
- .toBuffer()
82
- .then((data) => {
83
- return data.toString("base64");
84
- })
85
- .catch((error) => {
86
- throw new Error("Couldn't extract head of skin for uuid " + uuid + ". Reason: " + error);
87
- });
88
- });
89
- }
90
- exports.getFaceAsBase64 = getFaceAsBase64;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getFaceAsBase64 = exports.getSkinAsBase64 = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const sharp_1 = __importDefault(require("sharp"));
18
+ /**
19
+ * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
20
+ * @param uuid the uuid of the player
21
+ * @return the skin of the player encoded as a base64-string.
22
+ */
23
+ function getSkinAsBase64(uuid) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const response = yield axios_1.default.get("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
26
+ // Fetch profile.
27
+ const data = response.data;
28
+ // Define error prefix.
29
+ const errorMessage = "Couldn't retrieve skin for uuid " + uuid + ". Reason: ";
30
+ if (data.error) {
31
+ throw new Error(errorMessage + data.error + ": " + JSON.stringify(data));
32
+ }
33
+ if (!data.properties) {
34
+ throw new Error(errorMessage + "No properties in response: " + JSON.stringify(data));
35
+ }
36
+ // Loop through properties and find 'textures' property.
37
+ for (const property of data.properties) {
38
+ if (property.name === "textures") {
39
+ // Find object containing the skin URL.
40
+ const response = JSON.parse(Buffer.from(property.value, "base64").toString());
41
+ let skinURL;
42
+ // Check if skin URL exists and retrieve it.
43
+ if (response.textures &&
44
+ response.textures.SKIN &&
45
+ (skinURL = response.textures.SKIN.url)) {
46
+ // Fetch skin URL and returns as base64.
47
+ const b64 = yield axios_1.default
48
+ .get(skinURL, { responseType: "arraybuffer" })
49
+ .then((response) => response.data)
50
+ .then((buffer) => {
51
+ return Buffer.from(buffer).toString("base64");
52
+ })
53
+ .catch((error) => console.error(errorMessage + "Could not load buffer for URL " + skinURL, error));
54
+ if (b64)
55
+ return b64;
56
+ else
57
+ throw new Error(errorMessage + "No skin returned for URL " + skinURL);
58
+ }
59
+ else
60
+ throw new Error(errorMessage +
61
+ "No url to skin in response: " +
62
+ JSON.stringify(response));
63
+ }
64
+ }
65
+ throw new Error(errorMessage + "No textures object in response: " + JSON.stringify(data));
66
+ });
67
+ }
68
+ exports.getSkinAsBase64 = getSkinAsBase64;
69
+ /**
70
+ * Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
71
+ * @param uuid the uuid of the player
72
+ * @return the face of the player encoded as a base64-string.
73
+ */
74
+ function getFaceAsBase64(uuid) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const skin = yield getSkinAsBase64(uuid);
77
+ const buffer = Buffer.from(skin, "base64");
78
+ const sharpSkin = (0, sharp_1.default)(buffer);
79
+ const sharpHead = sharpSkin.extract({ left: 8, top: 8, width: 8, height: 8 });
80
+ return sharpHead
81
+ .toBuffer()
82
+ .then((data) => {
83
+ return data.toString("base64");
84
+ })
85
+ .catch((error) => {
86
+ throw new Error("Couldn't extract head of skin for uuid " + uuid + ". Reason: " + error);
87
+ });
88
+ });
89
+ }
90
+ exports.getFaceAsBase64 = getFaceAsBase64;
91
91
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelheads",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A library that makes it easy to retrieve skins and faces of minecraft players based on their uuid.",
5
5
  "keywords": [
6
6
  "minecraft",
@@ -21,12 +21,11 @@
21
21
  "main": "dist/index.js",
22
22
  "types": "dist/index.d.ts",
23
23
  "dependencies": {
24
- "axios": "^0.25.0",
25
- "sharp": "^0.29.3"
24
+ "axios": "^0.26.0",
25
+ "sharp": "^0.30.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/sharp": "^0.29.5",
29
- "@types/uuid": "^8.3.3",
30
29
  "@typescript-eslint/eslint-plugin": "^5.7.0",
31
30
  "@typescript-eslint/parser": "^5.7.0",
32
31
  "eslint": "^8.5.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWnE;AAED,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,EACD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAsBjB"}