@autorest/powershell
Version:
AutoRest PowerShell Cmdlet Generator
29 lines • 1.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChildResourceNameFromPath = exports.getResourceNameFromPath = void 0;
const codegen_1 = require("@azure-tools/codegen");
const pluralizationService = new codegen_1.EnglishPluralizationService();
pluralizationService.addWord('Database', 'Databases');
pluralizationService.addWord('database', 'databases');
pluralizationService.addWord('Premise', 'Premises');
pluralizationService.addWord('premise', 'premises');
//for sliced path: "/parentName/{name}/chileName", the second splited element is the parent name, and the fourth element is the child name
function slicePath(path, name, index) {
return path.slice(path.search(new RegExp(`/[^/]*/{${name}}`))).split('/')[index];
}
function get(path, name, singularize = false, index) {
const resourceName = path ? slicePath(path, name, index) : undefined;
return resourceName && !isResourceNameVariable(resourceName) ? (singularize ? pluralizationService.singularize(resourceName) : resourceName) : undefined;
}
function getResourceNameFromPath(path, name, singularize = false) {
return get(path, name, singularize, 1);
}
exports.getResourceNameFromPath = getResourceNameFromPath;
function getChildResourceNameFromPath(path, parent, singularize = false) {
return get(path, parent, singularize, 3);
}
exports.getChildResourceNameFromPath = getChildResourceNameFromPath;
function isResourceNameVariable(name) {
return /^{.*}$/g.test(name);
}
//# sourceMappingURL=resourceName.js.map
;