Refactor Code to typescript

This commit is contained in:
Benjamin Toby
2025-01-10 20:10:28 +01:00
parent 549d0abc02
commit eb0992f28d
270 changed files with 3535 additions and 9062 deletions
@@ -1,9 +0,0 @@
export = DB_HANDLER;
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ declare function DB_HANDLER(...args: any[]): Promise<any>;
@@ -1,7 +1,5 @@
// @ts-check
const mysql = require("serverless-mysql");
const grabDbSSL = require("../grabDbSSL");
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
const MASTER = mysql({
config: {
@@ -18,14 +16,9 @@ const MASTER = mysql({
});
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ // @ts-ignore
async function DB_HANDLER(...args) {
* # DSQL user read-only DB handler
*/
export default async function DB_HANDLER(...args: any[]) {
try {
const results = await MASTER.query(...args);
@@ -33,7 +26,7 @@ async function DB_HANDLER(...args) {
await MASTER.end();
return JSON.parse(JSON.stringify(results));
} catch (/** @type {any} */ error) {
} catch (error: any) {
console.log("DB Error =>", error);
return {
success: false,
@@ -41,5 +34,3 @@ async function DB_HANDLER(...args) {
};
}
}
module.exports = DB_HANDLER;
@@ -1,18 +0,0 @@
export = DSQL_USER_DB_HANDLER;
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {"Full Access" | "FA" | "Read Only"} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/
declare function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, }: {
paradigm: "Full Access" | "FA" | "Read Only";
database: string;
queryString: string;
queryValues?: string[];
}): Promise<any> | {
success: boolean;
error: any;
};
@@ -1,10 +1,10 @@
// @ts-check
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
const mysql = require("serverless-mysql");
const grabDbSSL = require("../grabDbSSL");
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
let DSQL_USER = mysql({
config: {
@@ -16,20 +16,22 @@ let DSQL_USER = mysql({
},
});
type Param = {
paradigm: "Full Access" | "FA" | "Read Only";
database: string;
queryString: string;
queryValues?: string[];
};
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {"Full Access" | "FA" | "Read Only"} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
* # DSQL user read-only DB handler
*/
function DSQL_USER_DB_HANDLER({
export default function DSQL_USER_DB_HANDLER({
paradigm,
database,
queryString,
queryValues,
}) {
}: Param) {
try {
return new Promise((resolve, reject) => {
const fullAccess = paradigm?.match(/full.access|^fa$/i)
@@ -63,7 +65,7 @@ function DSQL_USER_DB_HANDLER({
* ### Run query Function
* @param {any} results
*/
function runQuery(results) {
function runQuery(results: any) {
DSQL_USER.end();
resolve(JSON.parse(JSON.stringify(results)));
}
@@ -72,7 +74,7 @@ function DSQL_USER_DB_HANDLER({
* ### Query Error
* @param {any} err
*/
function queryError(err) {
function queryError(err: any) {
DSQL_USER.end();
resolve({
error: err.message,
@@ -97,7 +99,7 @@ function DSQL_USER_DB_HANDLER({
}
////////////////////////////////////////
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
////////////////////////////////////////
fs.appendFileSync(
@@ -111,7 +113,7 @@ function DSQL_USER_DB_HANDLER({
});
}
});
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
return {
success: false,
error: error.message,
@@ -1,10 +0,0 @@
export = LOCAL_DB_HANDLER;
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/
declare function LOCAL_DB_HANDLER(...args: any[]): Promise<any>;
@@ -1,17 +1,10 @@
// @ts-check
const mysql = require("serverless-mysql");
const grabDbSSL = require("../grabDbSSL");
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
* # DSQL user read-only DB handler
*/
async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
export default async function LOCAL_DB_HANDLER(...args: any[]) {
const MASTER = mysql({
config: {
host: process.env.DSQL_DB_HOST,
@@ -27,10 +20,10 @@ async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
onConnect: () => {
console.log("Connection Successful!");
},
onConnectError: (/** @type {any} */ err) => {
onConnectError: (/** @type {any} */ err: any) => {
console.log("Connection Error", err.message);
},
onError: (/** @type {any} */ err) => {
onError: (/** @type {any} */ err: any) => {
console.log("Client Error", err.message);
},
});
@@ -42,7 +35,7 @@ async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
await MASTER.end();
return JSON.parse(JSON.stringify(results));
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.log("DB Error =>", error.message);
return {
success: false,
@@ -50,5 +43,3 @@ async function LOCAL_DB_HANDLER(/** @type {any[]} */ ...args) {
};
}
}
module.exports = LOCAL_DB_HANDLER;
@@ -1,12 +0,0 @@
export = NO_DB_HANDLER;
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ declare function NO_DB_HANDLER(...args: any[]): Promise<any> | {
success: boolean;
error: any;
};
@@ -1,7 +1,5 @@
// @ts-check
const mysql = require("serverless-mysql");
const grabDbSSL = require("../grabDbSSL");
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
let NO_DB = mysql({
config: {
@@ -14,14 +12,9 @@ let NO_DB = mysql({
});
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ // @ts-ignore
function ROOT_DB_HANDLER(...args) {
* # DSQL user read-only DB handler
*/
export default function NO_DB_HANDLER(...args: any[]) {
try {
return new Promise((resolve, reject) => {
NO_DB.query(...args)
@@ -37,12 +30,10 @@ function ROOT_DB_HANDLER(...args) {
});
});
});
} catch (/** @type {any} */ error) {
} catch (error: any) {
return {
success: false,
error: error.message,
};
}
}
module.exports = ROOT_DB_HANDLER;
@@ -1,7 +1,7 @@
// @ts-check
const mysql = require("serverless-mysql");
const grabDbSSL = require("../grabDbSSL");
import mysql from "serverless-mysql";
import grabDbSSL from "../grabDbSSL";
let NO_DB = mysql({
config: {
@@ -14,14 +14,9 @@ let NO_DB = mysql({
});
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ // @ts-ignore
function NO_DB_HANDLER(...args) {
* # Root DB handler
*/
export default function ROOT_DB_HANDLER(...args: any[]) {
try {
return new Promise((resolve, reject) => {
NO_DB.query(...args)
@@ -37,12 +32,10 @@ function NO_DB_HANDLER(...args) {
});
});
});
} catch (/** @type {any} */ error) {
} catch (error: any) {
return {
success: false,
error: error.message,
};
}
}
module.exports = NO_DB_HANDLER;
-4
View File
@@ -1,4 +0,0 @@
declare function _exports(): string | (import("tls").SecureContextOptions & {
rejectUnauthorized?: boolean | undefined;
}) | undefined;
export = _exports;
@@ -1,11 +1,16 @@
// @ts-check
import fs from "fs";
const fs = require("fs");
type Return =
| string
| (import("tls").SecureContextOptions & {
rejectUnauthorized?: boolean | undefined;
})
| undefined;
/**
* @returns {string | (import("tls").SecureContextOptions & { rejectUnauthorized?: boolean | undefined;}) | undefined}
* # Grall SSL
*/
module.exports = function grabDbSSL() {
export default function grabDbSSL(): Return {
const SSL_DIR = process.env.DSQL_SSL_DIR;
if (!SSL_DIR?.match(/./)) {
return undefined;
@@ -21,4 +26,4 @@ module.exports = function grabDbSSL() {
return {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
};
};
}
-10
View File
@@ -1,10 +0,0 @@
declare function _exports({ request, cookieString }: {
request?: http.IncomingMessage & {
[x: string]: any;
};
cookieString?: string;
}): {
[x: string]: string;
};
export = _exports;
import http = require("http");
@@ -1,6 +1,4 @@
// @ts-check
const http = require("http");
import { IncomingMessage } from "http";
/**
* Parse request cookies
@@ -8,16 +6,14 @@ const http = require("http");
*
* @description This function takes in a request object and
* returns the cookies as a JS object
*
* @async
*
* @param {object} params - main params object
* @param {http.IncomingMessage & Object<string, any>} [params.request] - HTTPS request object
* @param {string} [params.cookieString]
*
* @returns {Object<string, string>}
*/
module.exports = function parseCookies({ request, cookieString }) {
export default function parseCookies({
request,
cookieString,
}: {
request?: IncomingMessage & { [s: string]: any };
cookieString?: string;
}): { [s: string]: string } {
try {
/** @type {string | undefined} */
const cookieStr = request
@@ -32,11 +28,9 @@ module.exports = function parseCookies({ request, cookieString }) {
return {};
}
/** @type {string[]} */
const cookieSplitArray = cookieStr.split(";");
const cookieSplitArray: string[] = cookieStr.split(";");
/** @type {Object<string, string>} */
let cookieObject = {};
let cookieObject: { [k: string]: string } = {};
cookieSplitArray.forEach((keyValueString) => {
const [key, value] = keyValueString.split("=");
@@ -50,9 +44,9 @@ module.exports = function parseCookies({ request, cookieString }) {
});
return cookieObject;
} catch (/** @type {any} */ error) {
} catch (error: any) {
console.log(`ERROR parsing cookies: ${error.message}`);
return {};
}
};
}
-12
View File
@@ -1,12 +0,0 @@
export = camelJoinedtoCamelSpace;
/**
* Convert Camel Joined Text to Camel Spaced Text
* ==============================================================================
* @description this function takes a camel cased text without spaces, and returns
* a camel-case-spaced text
*
* @param {string} text - text string without spaces
*
* @returns {string | null}
*/
declare function camelJoinedtoCamelSpace(text: string): string | null;
@@ -1,16 +1,10 @@
// @ts-check
/**
* Convert Camel Joined Text to Camel Spaced Text
* ==============================================================================
* @description this function takes a camel cased text without spaces, and returns
* a camel-case-spaced text
*
* @param {string} text - text string without spaces
*
* @returns {string | null}
*/
function camelJoinedtoCamelSpace(text) {
export default function camelJoinedtoCamelSpace(text: string): string | null {
if (!text?.match(/./)) {
return "";
}
@@ -33,7 +27,9 @@ function camelJoinedtoCamelSpace(text) {
}
}
let textChunks = [`${textArray[0].toUpperCase()}${text.substring(1, capIndexes[0])}`];
let textChunks = [
`${textArray[0].toUpperCase()}${text.substring(1, capIndexes[0])}`,
];
for (let j = 0; j < capIndexes.length; j++) {
const capIndex = capIndexes[j];
@@ -42,7 +38,12 @@ function camelJoinedtoCamelSpace(text) {
const startIndex = capIndex + 1;
const endIndex = capIndexes[j + 1];
textChunks.push(`${textArray[capIndex].toUpperCase()}${text.substring(startIndex, endIndex)}`);
textChunks.push(
`${textArray[capIndex].toUpperCase()}${text.substring(
startIndex,
endIndex
)}`
);
}
return textChunks.join(" ");
@@ -50,5 +51,3 @@ function camelJoinedtoCamelSpace(text) {
return null;
}
}
module.exports = camelJoinedtoCamelSpace;
@@ -1,14 +1,15 @@
// @ts-check
import EJSON from "./ejson";
const EJSON = require("./ejson");
/**
*
* @param {string | Object<string,any>} query
* @returns {Object<string,any>}
* # Convert Serialized Query back to object
*/
function deserializeQuery(query) {
export default function deserializeQuery(
query: string | { [s: string]: any }
): {
[s: string]: any;
} {
/** @type {Object<string,any>} */
let queryObject =
let queryObject: { [s: string]: any } =
typeof query == "object" ? query : Object(EJSON.parse(query));
const keys = Object.keys(queryObject);
@@ -26,5 +27,3 @@ function deserializeQuery(query) {
return queryObject;
}
module.exports = deserializeQuery;
-19
View File
@@ -1,19 +0,0 @@
/**
*
* @param {string | null | number} string
* @param {(this: any, key: string, value: any) => any} [reviver]
* @returns {Object<string, any> | Object<string, any>[] | undefined}
*/
export function parse(string: string | null | number, reviver?: (this: any, key: string, value: any) => any): {
[x: string]: any;
} | {
[x: string]: any;
}[] | undefined;
/**
*
* @param {any} value
* @param {((this: any, key: string, value: any) => any) | null} [replacer]
* @param { string | number } [space]
* @returns {string | undefined}
*/
export function stringify(value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number): string | undefined;
-38
View File
@@ -1,38 +0,0 @@
/**
*
* @param {string | null | number} string
* @param {(this: any, key: string, value: any) => any} [reviver]
* @returns {Object<string, any> | Object<string, any>[] | undefined}
*/
function parse(string, reviver) {
if (!string) return undefined;
if (typeof string == "object") return string;
if (typeof string !== "string") return undefined;
try {
return JSON.parse(string, reviver);
} catch (error) {
return undefined;
}
}
/**
*
* @param {any} value
* @param {((this: any, key: string, value: any) => any) | null} [replacer]
* @param { string | number } [space]
* @returns {string | undefined}
*/
function stringify(value, replacer, space) {
try {
return JSON.stringify(value, replacer, space);
} catch (error) {
return undefined;
}
}
const EJSON = {
parse,
stringify,
};
module.exports = EJSON;
+38
View File
@@ -0,0 +1,38 @@
/**
* # EJSON parse string
*/
function parse(
string: string | null | number,
reviver?: (this: any, key: string, value: any) => any
): { [s: string]: any } | { [s: string]: any }[] | undefined {
if (!string) return undefined;
if (typeof string == "object") return string;
if (typeof string !== "string") return undefined;
try {
return JSON.parse(string, reviver);
} catch (error) {
return undefined;
}
}
/**
* # EJSON stringify object
*/
function stringify(
value: any,
replacer?: (this: any, key: string, value: any) => any,
space?: string | number
): string | undefined {
try {
return JSON.stringify(value, replacer, space);
} catch (error) {
return undefined;
}
}
const EJSON = {
parse,
stringify,
};
export default EJSON;
+23
View File
@@ -0,0 +1,23 @@
import fs from "fs";
import path from "path";
export default function emptyDirectory(dir: string) {
try {
const dirContent = fs.readdirSync(dir);
for (let i = 0; i < dirContent.length; i++) {
const fileFolder = dirContent[i];
const fullFileFolderPath = path.join(dir, fileFolder);
const stat = fs.statSync(fullFileFolderPath);
if (stat.isDirectory()) {
emptyDirectory(fullFileFolderPath);
continue;
}
fs.unlinkSync(fullFileFolderPath);
}
} catch (error: any) {
console.log(`Error Emptying ${dir}: ${error.message}`);
}
}
@@ -1,11 +1,9 @@
// @ts-check
const mysql = require("mysql");
import mysql from "mysql";
/**
* @param {mysql.Connection} connection - the active MYSQL connection
* # End MYSQL Connection
*/
function endConnection(connection) {
function endConnection(connection: mysql.Connection) {
if (connection.state !== "disconnected") {
connection.end((err) => {
console.log(err?.message);
@@ -8,18 +8,15 @@
/** ****************************************************************************** */
/**
* Generate SQL text for Field
* ==============================================================================
* @param {object} params - Single object params
* @param {import("../types").DSQL_FieldSchemaType} params.columnData - Field object
* @param {boolean} [params.primaryKeySet] - Table Name(slug)
*
* @returns {{fieldEntryText: string, newPrimaryKeySet: boolean}}
* # Generate SQL text for Field
*/
module.exports = function generateColumnDescription({
export default function generateColumnDescription({
columnData,
primaryKeySet,
}) {
}: {
columnData: import("../types").DSQL_FieldSchemaType;
primaryKeySet?: boolean;
}): { fieldEntryText: string; newPrimaryKeySet: boolean } {
/**
* Format tableInfoArray
*
@@ -71,7 +68,7 @@ module.exports = function generateColumnDescription({
////////////////////////////////////////
return { fieldEntryText, newPrimaryKeySet: primaryKeySet || false };
};
}
/** ****************************************************************************** */
/** ****************************************************************************** */
-24
View File
@@ -1,24 +0,0 @@
export = grabHostNames;
/**
* @typedef {object} GrabHostNamesReturn
* @property {string} host
* @property {number | string} port
* @property {typeof http | typeof https} scheme
* @property {string | number} user_id
*/
/**
* # Grab Names For Query
* @returns {GrabHostNamesReturn}
*/
declare function grabHostNames(): GrabHostNamesReturn;
declare namespace grabHostNames {
export { GrabHostNamesReturn };
}
type GrabHostNamesReturn = {
host: string;
port: number | string;
scheme: typeof http | typeof https;
user_id: string | number;
};
import http = require("http");
import https = require("https");
@@ -1,21 +1,19 @@
// @ts-check
const https = require("https");
const http = require("http");
import https from "https";
import http from "http";
/**
* @typedef {object} GrabHostNamesReturn
* @property {string} host
* @property {number | string} port
* @property {typeof http | typeof https} scheme
* @property {string | number} user_id
*/
type GrabHostNamesReturn = {
host: string;
port: number | string;
scheme: typeof http | typeof https;
user_id: string | number;
};
/**
* # Grab Names For Query
* @returns {GrabHostNamesReturn}
*/
function grabHostNames() {
export default function grabHostNames(): GrabHostNamesReturn {
const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
@@ -33,5 +31,3 @@ function grabHostNames() {
user_id: String(process.env.DSQL_API_USER_ID || 0),
};
}
module.exports = grabHostNames;
-2
View File
@@ -1,2 +0,0 @@
declare function _exports(num: any, decimals?: number): number;
export = _exports;
@@ -1,10 +1,5 @@
// @ts-check
/**
* # Get Number from any input
* @param {any} num input
* @param {number} [decimals] number of decimals to round to
* @returns {number} number or 0 in case of error
* @example
* numberfy("123") // 123
* numberfy("123.456") // 123
@@ -12,15 +7,15 @@
* numberfy("123.456", 0) // 123
* numberfy("123.456", 3) // 123.456
*/
module.exports = function numberfy(num, decimals) {
export default function numberfy(num: any, decimals: number): number {
try {
const numberfiedNum = Number(num);
if (typeof numberfiedNum !== "number") return 0;
if (isNaN(numberfiedNum)) return 0;
if (decimals) return Number(numberfiedNum.toFixed(decimals));
return Math.round(numberfiedNum);
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.log(`Numberfy ERROR: ${error.message}`);
return 0;
}
};
}
-10
View File
@@ -1,10 +0,0 @@
export = serializeCookies;
/**
*
* @param {object} params
* @param {import("../types").CookieObject[]} params.cookies
* @returns {string[]}
*/
declare function serializeCookies({ cookies }: {
cookies: import("../types").CookieObject[];
}): string[];
@@ -1,14 +1,17 @@
// @ts-check
import { CookieObject } from "../types";
/**
*
* @param {object} params
* @param {import("../types").CookieObject[]} params.cookies
* @returns {string[]}
* # Serialize Cookies
* @description Convert cookie object to string array
*/
function serializeCookies({ cookies }) {
/** @type {string[]} */
let cookiesStringsArray = [];
export default function serializeCookies({
cookies,
}: {
cookies: CookieObject[];
}): string[] {
let cookiesStringsArray: string[] = [];
for (let i = 0; i < cookies.length; i++) {
const cookieObject = cookies[i];
@@ -44,5 +47,3 @@ function serializeCookies({ cookies }) {
return cookiesStringsArray;
}
module.exports = serializeCookies;
-2
View File
@@ -1,2 +0,0 @@
export = serializeQuery;
declare function serializeQuery(query: any): string;
@@ -1,9 +1,9 @@
// @ts-check
import EJSON from "./ejson";
const EJSON = require("./ejson");
/** @type {import("../types").SerializeQueryFnType} */
function serializeQuery(query) {
/**
* # Serialize Query
*/
export default function serializeQuery(query: any): string {
let str = "?";
if (typeof query !== "object") {
@@ -21,8 +21,7 @@ function serializeQuery(query) {
const keys = Object.keys(query);
/** @type {string[]} */
const queryArr = [];
const queryArr: string[] = [];
keys.forEach((key) => {
if (!key || !query[key]) return;
@@ -41,5 +40,3 @@ function serializeQuery(query) {
str += queryArr.join("&");
return str;
}
module.exports = serializeQuery;
@@ -1,16 +1,13 @@
// @ts-check
/**
*
* @param {string} text
* @returns
* # Slug to Camel case Title
*/
module.exports = function slugToCamelTitle(text) {
export default function slugToCamelTitle(text: String) {
if (text) {
let addArray = text.split("-").filter((item) => item !== "");
let camelArray = addArray.map((item) => {
return (
item.substr(0, 1).toUpperCase() + item.substr(1).toLowerCase()
item.substring(0, 1).toUpperCase() +
item.substring(1).toLowerCase()
);
});
@@ -20,4 +17,4 @@ module.exports = function slugToCamelTitle(text) {
} else {
return null;
}
};
}
-2
View File
@@ -1,2 +0,0 @@
declare function _exports(str: string): string;
export = _exports;
@@ -2,14 +2,13 @@
/**
* # Return the slug of a string
* @param {string} str input
* @returns {string} slug or empty string in case of error
*
* @example
* slugify("Hello World") // "hello-world"
* slugify("Yes!") // "yes"
* slugify("Hello!!! World!") // "hello-world"
*/
module.exports = function slugify(str) {
export default function slugify(str: string): string {
try {
return String(str)
.trim()
@@ -20,8 +19,8 @@ module.exports = function slugify(str) {
.replace(/-{2,}/g, "-")
.replace(/^-/, "")
.replace(/-$/, "");
} catch (/** @type {any} */ error) {
} catch (/** @type {any} */ error: any) {
console.log(`Slugify ERROR: ${error.message}`);
return "";
}
};
}
-24
View File
@@ -1,24 +0,0 @@
export = trimSql;
/**
* @typedef {object} GrabHostNamesReturn
* @property {string} host
* @property {number | string} port
* @property {typeof http | typeof https} scheme
*/
/**
* # Trim SQL
* @description Remove Returns and miltiple spaces from SQL Query
* @param {string} sql
* @returns {string}
*/
declare function trimSql(sql: string): string;
declare namespace trimSql {
export { GrabHostNamesReturn };
}
type GrabHostNamesReturn = {
host: string;
port: number | string;
scheme: typeof http | typeof https;
};
import http = require("http");
import https = require("https");
-26
View File
@@ -1,26 +0,0 @@
// @ts-check
const https = require("https");
const http = require("http");
/**
* @typedef {object} GrabHostNamesReturn
* @property {string} host
* @property {number | string} port
* @property {typeof http | typeof https} scheme
*/
/**
* # Trim SQL
* @description Remove Returns and miltiple spaces from SQL Query
* @param {string} sql
* @returns {string}
*/
function trimSql(sql) {
return sql
.replace(/\n|\r|\n\r|\r\n/gm, " ")
.replace(/ {2,}/g, " ")
.trim();
}
module.exports = trimSql;
+10
View File
@@ -0,0 +1,10 @@
/**
* # Trim SQL
* @description Remove Returns and miltiple spaces from SQL Query
*/
export default function trimSql(sql: string) {
return sql
.replace(/\n|\r|\n\r|\r\n/gm, " ")
.replace(/ {2,}/g, " ")
.trim();
}