39 lines
928 B
JavaScript
39 lines
928 B
JavaScript
import path from "path"
|
|
|
|
/**
|
|
* Formats a filename into the correct container resolution name.
|
|
* Names are camelCase formatted and namespaced by the folder i.e:
|
|
* models/example-person -> examplePersonModel
|
|
* @param {string} fn - the full path of the file
|
|
* @return {string} the formatted name
|
|
*/
|
|
function formatRegistrationName(fn) {
|
|
const parsed = path.parse(fn)
|
|
const parsedDir = path.parse(parsed.dir)
|
|
|
|
const rawname = parsed.name
|
|
let namespace = parsedDir.name
|
|
|
|
switch (namespace) {
|
|
case "repositories":
|
|
namespace = "repositorys"
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
|
|
const upperNamespace =
|
|
namespace.charAt(0).toUpperCase() + namespace.slice(1, -1)
|
|
|
|
const parts = rawname.split("-").map((n, index) => {
|
|
if (index !== 0) {
|
|
return n.charAt(0).toUpperCase() + n.slice(1)
|
|
}
|
|
return n
|
|
})
|
|
|
|
return parts.join("") + upperNamespace
|
|
}
|
|
|
|
export default formatRegistrationName
|