1
0
Fork 0

Fix getReadableName (3.3) (#6273)

This commit is contained in:
Alan Plum 2018-09-11 08:53:04 +02:00 committed by Jan
parent 15829f66c3
commit d04ce21f6d
2 changed files with 20 additions and 10 deletions

View File

@ -46,10 +46,10 @@ const DEFAULT_REPLICATION_FACTOR_SYSTEM = internal.DEFAULT_REPLICATION_FACTOR_SY
function getReadableName (name) {
const readable = name
.replace(/([-_]|\s)+/g, ' ')
.replace(/([a-z])([A-Z])/g, (m) => `${m[0]} ${m[1]}`)
.replace(/([A-Z])([A-Z][a-z])/g, (m) => `${m[0]} ${m[1]}`)
.replace(/\s([a-z])/g, (m) => ` ${m[1].toUpperCase()}`);
.replace(/([-_]|\s)+/g, " ")
.replace(/[a-z][A-Z]/g, str => `${str.charAt(0)} ${str.slice(1)}`)
.replace(/[A-Z][A-Z][a-z]/g, str => `${str.charAt(0)} ${str.slice(1)}`)
.replace(/\s[a-z]/g, str => `${str.toUpperCase()}`);
return readable.charAt(0).toUpperCase() + readable.substr(1);
}

View File

@ -1,11 +1,21 @@
/* global test */
/*global suite, test */
"use strict";
const { expect } = require("chai");
const { getReadableName } = require("@arangodb/foxx/manager-utils");
test("getReadableName", () => {
expect(getReadableName("catch-fire")).to.equal("Catch Fire");
expect(getReadableName("catchFire")).to.equal("Catch Fire");
expect(getReadableName("CatchFire")).to.equal("Catch Fire");
expect(getReadableName("cAtChFiRe")).to.equal("C At Ch Fi Re");
suite("getReadableName", () => {
for (const [input, output] of [
["catch-fire", "Catch Fire"],
["catchFire", "Catch Fire"],
["CatchFire", "Catch Fire"],
["catch fire", "Catch Fire"],
["CATCH FIRE", "CATCH FIRE"],
["CATCHFIRE", "CATCHFIRE"],
["cAtChFiRe", "C At Ch Fi Re"],
["XmlHTTPRequest", "Xml HTTP Request"]
]) {
test(`"${input}" -> "${output}"`, () => {
expect(getReadableName(input)).to.equal(output);
});
}
});