@sap-cloud-sdk/util
Version:
SAP Cloud SDK for JavaScript general utilities
75 lines • 2.72 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.webEOL = exports.unixEOL = void 0;
exports.upperCaseSnakeCase = upperCaseSnakeCase;
exports.camelCase = camelCase;
exports.titleFormat = titleFormat;
exports.pascalCase = pascalCase;
exports.kebabCase = kebabCase;
exports.formatJson = formatJson;
const voca_1 = __importDefault(require("voca"));
/**
* Within all files generated by the SDK we use the unix style end of line delimiter.
* We do not consider if the generator is executed on windows or unix systems.
* It will always be `\n` to have consistent clients between operating systems.
*/
exports.unixEOL = '\n';
/**
* For request payloads, etc., it is convention to use the `\r\n` new line.
*/
exports.webEOL = '\r\n';
/**
* Convert a string to the uppercase snake case. This format is used e.g. for static properties on entity classes.
* @param str - The string to be transformed.
* @returns The input string in the case used by static methods on entity-classes.
*/
function upperCaseSnakeCase(str) {
return voca_1.default.upperCase(voca_1.default.snakeCase(str));
}
/**
* Convert a string to camelCase. This format used e.g. for properties on entity class instances.
* @param str - The string to be transformed.
* @returns The transformed string.
*/
function camelCase(str) {
return voca_1.default.camelCase(str);
}
/**
* Convert a string to a human readable format, e.g. it transforms `to_BusinessPartner` to `To Business Partner`.
* @param str - The string to be transformed.
* @returns The transformed string.
*/
function titleFormat(str) {
return voca_1.default.titleCase(voca_1.default.words(str).join(' '));
}
/**
* Convert a string to pascal case. This format is used e.g. for types.
* @param str - The string to be transformed.
* @returns The transformed string.
*/
function pascalCase(str) {
return voca_1.default
.words(str)
.map(word => voca_1.default.capitalize(word))
.join('');
}
/**
* Convert a string to kebab case. This format is used e.g. for file names.
* @param str - The string to be transformed.
* @returns The transformed string.
*/
function kebabCase(str) {
return voca_1.default.kebabCase(str);
}
/**
* Convert a JSON object to a string using formatting in line with the prettier with indentation and new line at the end.
* @param json - Object to be stringified.
* @returns The JSON object as string.
*/
function formatJson(json) {
return JSON.stringify(json, null, 2) + exports.unixEOL;
}
//# sourceMappingURL=string-formatter.js.map