UNPKG

@argodevops/safe-change-case

Version:

Safely transforms Objects, Array and strings between cases.

59 lines (52 loc) 4.07 kB
var $gXNCa$changecase = require("change-case"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "CaseType", () => $4fa36e821943b400$export$558f81ebd042e150); $parcel$export(module.exports, "safeChangeCase", () => $4fa36e821943b400$export$96964c85f21a17a7); $parcel$export(module.exports, "camelCase", () => $4fa36e821943b400$export$8a7688a96d852767); $parcel$export(module.exports, "snakeCase", () => $4fa36e821943b400$export$feae9a740c003485); $parcel$export(module.exports, "kebabCase", () => $4fa36e821943b400$export$7428e6464c9e15e8); $parcel$export(module.exports, "pascalCase", () => $4fa36e821943b400$export$26c6f48841fe1a8a); $parcel$export(module.exports, "capitalCase", () => $4fa36e821943b400$export$7fed55d4315c6715); $parcel$export(module.exports, "sentenceCase", () => $4fa36e821943b400$export$da1ec1d734312f9f); // Define the CaseType enum const $4fa36e821943b400$export$558f81ebd042e150 = Object.freeze({ CAMEL: 'camelCase', SNAKE: 'snakeCase', KEBAB: 'kebabCase', PASCAL: 'pascalCase', CAPITAL: 'capitalCase', SENTENCE: 'sentenceCase' }); /** * Wrapper function to safely transform strings using change-case. * * @param {string|Array|Object|null} input - The input string, array, or object to transform. * @param {string} caseType - The case type to apply, using the CaseType enum. * @param {Object} [options] - Optional additional options for case transformation. * @returns {string} - Transformed string or concatenated array/object as a string. */ function $4fa36e821943b400$export$96964c85f21a17a7(input, caseType, options) { if (input == null) return ''; let inputValue = input; if (Array.isArray(input)) inputValue = input.join(' '); if (typeof input === 'object') inputValue = JSON.stringify(input); if (typeof inputValue !== 'string') throw new Error('Input must be a string, an array, or an object.'); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.CAMEL) return (0, $gXNCa$changecase.camelCase)(inputValue, options); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.SNAKE) return (0, $gXNCa$changecase.snakeCase)(inputValue, options); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.KEBAB) return (0, $gXNCa$changecase.kebabCase)(inputValue, options); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.PASCAL) return (0, $gXNCa$changecase.pascalCase)(inputValue, options); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.CAPITAL) return (0, $gXNCa$changecase.capitalCase)(inputValue, options); if (caseType === $4fa36e821943b400$export$558f81ebd042e150.SENTENCE) return (0, $gXNCa$changecase.sentenceCase)(inputValue, options); throw new Error(`Invalid case type: ${caseType}`); } /** * Standalone functions for each case transformation. * These call the safeChangeCase function internally. */ const $4fa36e821943b400$export$8a7688a96d852767 = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.CAMEL, options); const $4fa36e821943b400$export$feae9a740c003485 = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.SNAKE, options); const $4fa36e821943b400$export$7428e6464c9e15e8 = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.KEBAB, options); const $4fa36e821943b400$export$26c6f48841fe1a8a = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.PASCAL, options); const $4fa36e821943b400$export$7fed55d4315c6715 = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.CAPITAL, options); const $4fa36e821943b400$export$da1ec1d734312f9f = (input, options)=>$4fa36e821943b400$export$96964c85f21a17a7(input, $4fa36e821943b400$export$558f81ebd042e150.SENTENCE, options); //# sourceMappingURL=index.js.map