@arkstack/common 0.1.2 → 0.1.3
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/app.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/app.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ declare global {
|
|
|
8
8
|
* Converts the string to camel case.
|
|
9
9
|
*/
|
|
10
10
|
camelCase (): string;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the string to pascal case.
|
|
13
|
+
*/
|
|
14
|
+
pascalCase (): string;
|
|
11
15
|
/**
|
|
12
16
|
* Truncates the string to a specified length while preserving words
|
|
13
17
|
* and adds a suffix if necessary.
|
package/dist/index.js
CHANGED
|
@@ -81,6 +81,11 @@ const loadPrototypes = () => {
|
|
|
81
81
|
return index === 0 ? match.toLowerCase() : match.toUpperCase();
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
+
String.prototype.pascalCase = function() {
|
|
85
|
+
return this.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match) {
|
|
86
|
+
return match.toUpperCase();
|
|
87
|
+
});
|
|
88
|
+
};
|
|
84
89
|
String.prototype.truncate = function(len = 20, suffix = "...") {
|
|
85
90
|
if (this.length <= len) return this.toString();
|
|
86
91
|
const truncated = this.substring(0, len);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/lifecycle.ts","../src/network.ts","../src/prototypes.ts"],"sourcesContent":["export const bindGracefulShutdown = (shutdown: () => Promise<void> | void) => {\n ['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => {\n process.on(signal, async () => {\n await shutdown()\n })\n })\n}\n","import { detect } from 'detect-port'\n\nexport const bootWithDetectedPort = async (\n boot: (port: number) => Promise<void>,\n preferredPort: number = 3000,\n) => {\n const port = await detect(preferredPort)\n await boot(port)\n}\n\n\nexport const buildHtmlErrorResponse = ({\n message = 'An unexpected error occurred.',\n stack,\n title,\n code = 500,\n}: {\n message?: string;\n stack?: string;\n code?: number;\n title?: string;\n}) => {\n const titleMap: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 500: 'Internal Server Error',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n }\n\n title = titleMap[code] || title || 'Error'\n\n return `\n <html>\n <head>\n <title>${code} | ${title}</title>\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f8f8f8;\n color: #333;\n padding: 20px;\n }\n h1 {\n color: #e74c3c;\n }\n h3 {\n color: #3498db;\n }\n p {\n color: #555;\n }\n pre {\n background-color: #eee;\n padding: 10px;\n border-radius: 5px;\n overflow-x: auto;\n }\n </style>\n </head>\n <body>\n <h1>${code}</h1>\n <h3>${title}</h3>\n <p>${message}</p>\n ${stack ? `<h2>Stack Trace:</h2><pre>${stack}</pre>` : ''}\n </body>\n </html>\n `\n}","export const loadPrototypes = () => {\n String.prototype.titleCase = function () {\n return this.toLowerCase()\n .replace(/_/g, ' ')\n .replace(/-/g, ' ')\n .replace(/(?:^|\\s)\\w/g, function (match) {\n return match.toUpperCase()\n })\n }\n\n String.prototype.camelCase = function () {\n return this.replace(/(?:^\\w|[A-Z]|\\b\\w|\\s+)/g, function (match, index) {\n if (+match === 0) return '' // or if (/\\s+/.test(match)) for white spaces\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/lifecycle.ts","../src/network.ts","../src/prototypes.ts"],"sourcesContent":["export const bindGracefulShutdown = (shutdown: () => Promise<void> | void) => {\n ['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => {\n process.on(signal, async () => {\n await shutdown()\n })\n })\n}\n","import { detect } from 'detect-port'\n\nexport const bootWithDetectedPort = async (\n boot: (port: number) => Promise<void>,\n preferredPort: number = 3000,\n) => {\n const port = await detect(preferredPort)\n await boot(port)\n}\n\n\nexport const buildHtmlErrorResponse = ({\n message = 'An unexpected error occurred.',\n stack,\n title,\n code = 500,\n}: {\n message?: string;\n stack?: string;\n code?: number;\n title?: string;\n}) => {\n const titleMap: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 500: 'Internal Server Error',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n }\n\n title = titleMap[code] || title || 'Error'\n\n return `\n <html>\n <head>\n <title>${code} | ${title}</title>\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f8f8f8;\n color: #333;\n padding: 20px;\n }\n h1 {\n color: #e74c3c;\n }\n h3 {\n color: #3498db;\n }\n p {\n color: #555;\n }\n pre {\n background-color: #eee;\n padding: 10px;\n border-radius: 5px;\n overflow-x: auto;\n }\n </style>\n </head>\n <body>\n <h1>${code}</h1>\n <h3>${title}</h3>\n <p>${message}</p>\n ${stack ? `<h2>Stack Trace:</h2><pre>${stack}</pre>` : ''}\n </body>\n </html>\n `\n}","export const loadPrototypes = () => {\n String.prototype.titleCase = function () {\n return this.toLowerCase()\n .replace(/_/g, ' ')\n .replace(/-/g, ' ')\n .replace(/(?:^|\\s)\\w/g, function (match) {\n return match.toUpperCase()\n })\n }\n\n String.prototype.camelCase = function () {\n return this.replace(/(?:^\\w|[A-Z]|\\b\\w|\\s+)/g, function (match, index) {\n if (+match === 0) return '' // or if (/\\s+/.test(match)) for white spaces\n\n return index === 0 ? match.toLowerCase() : match.toUpperCase()\n })\n }\n\n String.prototype.pascalCase = function () {\n return this.replace(/(?:^\\w|[A-Z]|\\b\\w|\\s+)/g, function (match) {\n return match.toUpperCase()\n })\n }\n\n String.prototype.truncate = function (len: number = 20, suffix: string = '...') {\n if (this.length <= len) {\n return this.toString()\n }\n\n const truncated = this.substring(0, len)\n const lastSpaceIndex = truncated.lastIndexOf(' ')\n if (lastSpaceIndex > 0) {\n return truncated.substring(0, lastS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,KAAK,UAAU,GAAG,IAAI;EACxC,MAAM,iBAAiB,UAAU,YAAY,IAAI;AACjD,MAAI,iBAAiB,EACjB,QAAO,UAAU,UAAU,GAAG,eAAe,GAAG;AAGpD,SAAO,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Common package for Arkstack providing common implementations of core Arkstack features such as routing, middleware, and database integration.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|