semantic-network
Version:
A utility library for manipulating a list of links that form a semantic interface to a network of resources.
66 lines • 2.17 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RelationshipTypeUtil = void 0;
var anylogger_1 = __importDefault(require("anylogger"));
var log = (0, anylogger_1.default)('RelationshipTypeUtil');
var RelationshipTypeUtil = /** @class */ (function () {
function RelationshipTypeUtil() {
}
/**
* Takes a string or a Regexp and makes camel cased strings.
*
* @example
*
* test -> test
* /test/ -> test
* /test/g -> test
* /create-form/ -> createForm
*
* @param {RelationshipType} rel
* @returns {string}
*/
RelationshipTypeUtil.toCamel = function (rel) {
var _a, _b;
if (!rel) {
return;
}
// at this stage
if (Array.isArray(rel)) {
log.debug('using first rel type from list');
_a = rel, _b = __read(_a, 1), rel = _b[0];
}
if (typeof rel === 'string') {
return rel;
}
return (rel
.toString()
// remove the regexp aspects eg 'test'' -> test
.replace(/\/[gi]*/g, '')
// remove all other non alpha and hyphen chars
.replace(/[^-a-zA-Z]*/g, '')
// replace create-form --> createForm
.replace(/(-[a-z])/g, function ($1) { return $1.toUpperCase().replace('-', ''); }));
};
return RelationshipTypeUtil;
}());
exports.RelationshipTypeUtil = RelationshipTypeUtil;
//# sourceMappingURL=relationshipTypeUtil.js.map