UNPKG

atlassian-webresource-webpack-plugin

Version:

Auto-generates web-resource definitions from your webpacked code, for usage in an Atlassian product or plugin.

39 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseWebResourceAttributes = void 0; const string_1 = require("./string"); // eslint-disable-next-line sonarjs/cognitive-complexity const parseWebResourceAttributes = (data) => { const attributes = {}; // Only parse objects. if (data && typeof data === 'object') { // define the key if a non-empty string was provided if (Object.prototype.hasOwnProperty.call(data, 'key')) { const customKey = (0, string_1.toTrimmedString)(data.key); if (customKey) { attributes.key = customKey; } } // define the state as either enabled or disabled if (Object.prototype.hasOwnProperty.call(data, 'state')) { let isEnabled = true; if (typeof data.state === 'boolean') { isEnabled = data.state; } else if (typeof data.state === 'string') { isEnabled = data.state !== 'disabled'; } attributes.state = isEnabled ? 'enabled' : 'disabled'; } // define the name if a non-empty string was provided if (Object.prototype.hasOwnProperty.call(data, 'name')) { const customName = (0, string_1.toTrimmedString)(data.name); if (customName) { attributes.name = customName; } } } return attributes; }; exports.parseWebResourceAttributes = parseWebResourceAttributes; //# sourceMappingURL=web-resource-parser.js.map