Updates
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// @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) {
|
||||
if (!text?.match(/./)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (text?.match(/ /)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
if (text) {
|
||||
let textArray = text.split("");
|
||||
|
||||
let capIndexes = [];
|
||||
|
||||
for (let i = 0; i < textArray.length; i++) {
|
||||
const char = textArray[i];
|
||||
|
||||
if (i === 0) continue;
|
||||
if (char.match(/[A-Z]/)) {
|
||||
capIndexes.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
let textChunks = [`${textArray[0].toUpperCase()}${text.substring(1, capIndexes[0])}`];
|
||||
|
||||
for (let j = 0; j < capIndexes.length; j++) {
|
||||
const capIndex = capIndexes[j];
|
||||
if (capIndex === 0) continue;
|
||||
|
||||
const startIndex = capIndex + 1;
|
||||
const endIndex = capIndexes[j + 1];
|
||||
|
||||
textChunks.push(`${textArray[capIndex].toUpperCase()}${text.substring(startIndex, endIndex)}`);
|
||||
}
|
||||
|
||||
return textChunks.join(" ");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = camelJoinedtoCamelSpace;
|
||||
@@ -0,0 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
const mysql = require("mysql");
|
||||
|
||||
/**
|
||||
* @param {mysql.Connection} connection - the active MYSQL connection
|
||||
*/
|
||||
function endConnection(connection) {
|
||||
if (connection.state !== "disconnected") {
|
||||
connection.end((err) => {
|
||||
console.log(err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = endConnection;
|
||||
@@ -0,0 +1,80 @@
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* 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}}
|
||||
*/
|
||||
module.exports = function generateColumnDescription({
|
||||
columnData,
|
||||
primaryKeySet,
|
||||
}) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const {
|
||||
fieldName,
|
||||
dataType,
|
||||
nullValue,
|
||||
primaryKey,
|
||||
autoIncrement,
|
||||
defaultValue,
|
||||
defaultValueLiteral,
|
||||
notNullValue,
|
||||
} = columnData;
|
||||
|
||||
let fieldEntryText = "";
|
||||
|
||||
fieldEntryText += `\`${fieldName}\` ${dataType}`;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (nullValue) {
|
||||
fieldEntryText += " DEFAULT NULL";
|
||||
} else if (defaultValueLiteral) {
|
||||
fieldEntryText += ` DEFAULT ${defaultValueLiteral}`;
|
||||
} else if (defaultValue) {
|
||||
fieldEntryText += ` DEFAULT '${defaultValue}'`;
|
||||
} else if (notNullValue) {
|
||||
fieldEntryText += ` NOT NULL`;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (primaryKey && !primaryKeySet) {
|
||||
fieldEntryText += " PRIMARY KEY";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (autoIncrement) {
|
||||
fieldEntryText += " AUTO_INCREMENT";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return { fieldEntryText, newPrimaryKeySet: primaryKeySet || false };
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -0,0 +1,23 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} text
|
||||
* @returns
|
||||
*/
|
||||
module.exports = function slugToCamelTitle(text) {
|
||||
if (text) {
|
||||
let addArray = text.split("-").filter((item) => item !== "");
|
||||
let camelArray = addArray.map((item) => {
|
||||
return (
|
||||
item.substr(0, 1).toUpperCase() + item.substr(1).toLowerCase()
|
||||
);
|
||||
});
|
||||
|
||||
let parsedAddress = camelArray.join(" ");
|
||||
|
||||
return parsedAddress;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user