keys-converter
Version:
This package provide a util function to convert snake case object keys to camel case
38 lines • 1.31 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidCamelCase = void 0;
const is_camel_case_1 = __importDefault(require("./is_camel_case"));
const isValidCamelCase = (str) => {
if (typeof str === 'string') {
if (str.length > 1) {
const hasAnotherUnderscore = str
.slice(1, str.length)
.search('_') !== -1;
if (hasAnotherUnderscore) {
return false;
}
const hasUppercaseSideBySide = str
.split('')
.map((value, i, arr) => {
if (i < (arr.length - 1))
return is_camel_case_1.default(value) && is_camel_case_1.default(arr[i + 1]);
}).includes(true);
if (hasUppercaseSideBySide) {
return false;
}
return true;
}
else {
return (str !== '' && !is_camel_case_1.default(str));
}
}
else {
return false;
}
};
exports.isValidCamelCase = isValidCamelCase;
exports.default = exports.isValidCamelCase;
//# sourceMappingURL=is_valid_camel_case.js.map
;