arky-js
Version:
**Arky.js** is a powerful, annotation-based framework for building serverless applications on **AWS Lambda and API Gateway**. Inspired by Angular and NestJS, Arky.js simplifies serverless development by providing decorators for defining modules, controlle
51 lines (50 loc) • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFileNameFromVarName = getFileNameFromVarName;
exports.getFunctionName = getFunctionName;
exports.getFilePathName = getFilePathName;
exports.getClassNameWithSuffix = getClassNameWithSuffix;
function getFileNameFromVarName(varName) {
return varName
.replace(/([A-Z])/g, "-$1") // Insert a hyphen before uppercase letters
.toLowerCase() // Convert the entire string to lowercase
.replace(/^-/, "");
}
function getFunctionName(name, filePath) {
return (getFileNameFromVarName(name) +
`-${getFileNameSuffix(filePath).toLowerCase()}` +
"-function");
}
/**
* This function return lambda function file path name for local machine.
* This is to handle same name controller issue.
*/
function getFilePathName(varName, filePath) {
return getFileNameFromVarName(varName) + `-${getFileNameSuffix(filePath)}`;
}
function getClassNameWithSuffix(className, filePath) {
return `${className}${getFileNameSuffix(filePath).toUpperCase()}`;
}
function getFileNameSuffix(filePath) {
// Extract the first letters
const firstLetters = extractFirstLetters(filePath);
// Encrypt the extracted string
const encryptedSuffix = encryptString(firstLetters);
return encryptedSuffix;
}
function extractFirstLetters(path) {
// Split the path into components
const components = path.split(/[\\/]/); // Handle both forward and backward slashes
const srcDirIndex = components.findIndex((val) => val === "src");
const selectedProjectFilePaths = components.slice(srcDirIndex > -1 ? srcDirIndex : 0);
// Extract the first letter of each component
const firstLetters = selectedProjectFilePaths
.filter((component) => component.length > 0) // Ignore empty components
.map((component) => component[0]) // Get the first letter
.join(""); // Combine into a single string
return firstLetters;
}
function encryptString(input) {
// Simple encryption: reverse the string
return input.split("").reverse().join("");
}