@xenterprises/fastify-xconfig 2.0.1 → 2.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/package.json +9 -1
- package/src/utils/formatBytes.js +1 -1
- package/src/utils/xSlugify.js +1 -1
- package/src/utils/xUUID.js +2 -2
- package/test/xConfig.test.js +18 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xenterprises/fastify-xconfig",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"description": "Fastify configuration plugin for setting up middleware, services, and route handling.",
|
|
6
6
|
"main": "src/xConfig.js",
|
|
7
7
|
"scripts": {
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
},
|
|
12
12
|
"author": "Tim Mushen",
|
|
13
13
|
"license": "ISC",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://gitlab.com/x-enterprises/fastify-plugins/fastify-x-config"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://gitlab.com/x-enterprises/fastify-plugins/fastify-x-config/-/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://gitlab.com/x-enterprises/fastify-plugins/fastify-x-config#readme",
|
|
14
22
|
"devDependencies": {
|
|
15
23
|
"@types/node": "^22.7.4",
|
|
16
24
|
"c8": "^9.0.0",
|
package/src/utils/formatBytes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fp from "fastify-plugin";
|
|
2
2
|
|
|
3
3
|
async function formatBytesPlugin(fastify, options) {
|
|
4
|
-
fastify.decorate("
|
|
4
|
+
fastify.decorate("xFormatBytes", (bytes, decimals = 2) => {
|
|
5
5
|
if (bytes === 0) return "0 Bytes";
|
|
6
6
|
|
|
7
7
|
const k = 1024;
|
package/src/utils/xSlugify.js
CHANGED
package/src/utils/xUUID.js
CHANGED
|
@@ -2,9 +2,9 @@ import fp from "fastify-plugin";
|
|
|
2
2
|
import { randomUUID } from "uncrypto";
|
|
3
3
|
|
|
4
4
|
async function xUUID(fastify, options) {
|
|
5
|
-
fastify.decorate("
|
|
5
|
+
fastify.decorate("xGenerateUUID", randomUUID);
|
|
6
6
|
|
|
7
|
-
fastify.decorate('
|
|
7
|
+
fastify.decorate('xRandomUUID', () => {
|
|
8
8
|
return randomUUID(); // Generate a UUID using uncrypto's randomUUID
|
|
9
9
|
});
|
|
10
10
|
}
|
package/test/xConfig.test.js
CHANGED
|
@@ -133,11 +133,11 @@ test("xConfig Utilities - xUUID generates valid UUIDs", async () => {
|
|
|
133
133
|
try {
|
|
134
134
|
await fastify.register(xConfig, minimalConfig);
|
|
135
135
|
|
|
136
|
-
const uuid1 = fastify.
|
|
137
|
-
const uuid2 = fastify.
|
|
136
|
+
const uuid1 = fastify.xRandomUUID();
|
|
137
|
+
const uuid2 = fastify.xRandomUUID();
|
|
138
138
|
|
|
139
139
|
// Check that randomUUID is a function
|
|
140
|
-
assert.equal(typeof fastify.
|
|
140
|
+
assert.equal(typeof fastify.xRandomUUID, "function", "randomUUID is a function");
|
|
141
141
|
|
|
142
142
|
// Check that UUIDs are generated
|
|
143
143
|
assert.ok(uuid1, "UUID is generated");
|
|
@@ -159,21 +159,21 @@ test("xConfig Utilities - xSlugify handles various inputs", async () => {
|
|
|
159
159
|
await fastify.register(xConfig, minimalConfig);
|
|
160
160
|
|
|
161
161
|
// Test basic slugification
|
|
162
|
-
assert.equal(fastify.
|
|
163
|
-
assert.equal(fastify.
|
|
164
|
-
assert.equal(fastify.
|
|
162
|
+
assert.equal(fastify.xSlugify("Hello World"), "hello-world", "Converts to lowercase and replaces spaces");
|
|
163
|
+
assert.equal(fastify.xSlugify("UPPERCASE"), "uppercase", "Converts uppercase to lowercase");
|
|
164
|
+
assert.equal(fastify.xSlugify("Multiple Spaces"), "multiple-spaces", "Collapses multiple spaces");
|
|
165
165
|
|
|
166
166
|
// Test special character removal
|
|
167
|
-
assert.equal(fastify.
|
|
168
|
-
assert.equal(fastify.
|
|
167
|
+
assert.equal(fastify.xSlugify("Hello@World!"), "helloworld", "Removes special characters");
|
|
168
|
+
assert.equal(fastify.xSlugify("Test-String"), "test-string", "Preserves dashes");
|
|
169
169
|
|
|
170
170
|
// Test edge cases
|
|
171
|
-
assert.equal(fastify.
|
|
172
|
-
assert.equal(fastify.
|
|
173
|
-
assert.equal(fastify.
|
|
171
|
+
assert.equal(fastify.xSlugify(" Trim "), "trim", "Trims leading and trailing spaces");
|
|
172
|
+
assert.equal(fastify.xSlugify("---multiple-dashes---"), "multiple-dashes", "Collapses multiple dashes");
|
|
173
|
+
assert.equal(fastify.xSlugify(""), "", "Handles empty string");
|
|
174
174
|
|
|
175
175
|
// Test with numbers
|
|
176
|
-
assert.equal(fastify.
|
|
176
|
+
assert.equal(fastify.xSlugify("Test123"), "test123", "Preserves numbers");
|
|
177
177
|
} finally {
|
|
178
178
|
await fastify.close();
|
|
179
179
|
}
|
|
@@ -263,15 +263,15 @@ test("xConfig Integration - all decorators available together", async () => {
|
|
|
263
263
|
|
|
264
264
|
// Verify all expected decorators exist
|
|
265
265
|
assert.ok(fastify.xEcho, "xEcho decorator available");
|
|
266
|
-
assert.ok(fastify.
|
|
267
|
-
assert.ok(fastify.
|
|
268
|
-
assert.ok(fastify.
|
|
266
|
+
assert.ok(fastify.xRandomUUID, "randomUUID decorator available");
|
|
267
|
+
assert.ok(fastify.xGenerateUUID, "generateUUID decorator available");
|
|
268
|
+
assert.ok(fastify.xSlugify, "slugify decorator available");
|
|
269
269
|
|
|
270
270
|
// Verify they're functions
|
|
271
271
|
assert.equal(typeof fastify.xEcho, "function", "xEcho is a function");
|
|
272
|
-
assert.equal(typeof fastify.
|
|
273
|
-
assert.equal(typeof fastify.
|
|
274
|
-
assert.equal(typeof fastify.
|
|
272
|
+
assert.equal(typeof fastify.xRandomUUID, "function", "randomUUID is a function");
|
|
273
|
+
assert.equal(typeof fastify.xGenerateUUID, "function", "generateUUID is a function");
|
|
274
|
+
assert.equal(typeof fastify.xSlugify, "function", "slugify is a function");
|
|
275
275
|
} finally {
|
|
276
276
|
await fastify.close();
|
|
277
277
|
}
|