@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
32 lines • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateApiName = void 0;
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const logger_1 = require("../logger/logger");
/**
* Generate an API name from a string. Matches what the UI does.
*
* @param name - name to be converted into a valid api name
* @returns a valid api name
*/
const generateApiName = (name) => {
const maxLength = 255;
let apiName = name;
apiName = apiName.replace(/[\W_]+/g, '_');
if (apiName.charAt(0).match(/_/i)) {
apiName = apiName.slice(1);
}
apiName = apiName
.replace(/(^\d+)/, 'X$1')
.slice(0, maxLength)
.replace(/_$/, '');
logger_1.Logger.childFromRoot('').debug(`Generated API name: [${apiName}] from name: [${name}]`);
return apiName;
};
exports.generateApiName = generateApiName;
//# sourceMappingURL=generateApiName.js.map
;