UNPKG

keys-converter

Version:

This package provide a util function to convert snake case object keys to camel case

43 lines 1.44 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidSnakeCase = void 0; const is_camel_case_1 = __importDefault(require("./is_camel_case")); const isValidSnakeCase = (str) => { if (typeof str === 'string') { if (str.length > 1) { const hasUnderscoreSideBySide = str .split('') .map((value, i, arr) => { if (i < (arr.length - 1)) return value === '_' && arr[i + 1] === '_'; }).includes(true); if (hasUnderscoreSideBySide) { return false; } const hasSomeUpper = str .split('') .map(is_camel_case_1.default) .includes(true); if (hasSomeUpper) { return false; } const endsWithUnderscore = str[str.length - 1] === '_'; if (endsWithUnderscore) { return false; } return true; } else { return (str !== '' && !is_camel_case_1.default(str)); } } else { return false; } }; exports.isValidSnakeCase = isValidSnakeCase; exports.default = exports.isValidSnakeCase; //# sourceMappingURL=is_valid_snake_case.js.map