@mikezimm/npmfunctions
Version:
Functions used in my SPFx webparts
66 lines • 3.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExportGroup = exports.createExportObject = exports.exportNotAvailMess = void 0;
var checks_1 = require("../Arrays/checks");
/**
* @param exportStructure returns an object with selected this.properties to export via the help panel
* Should only be property keys that you want to import
* exportStructure = {
* key1: [ prop1, prop2, prop3 ] }
* }
* @param thisProperties - this is the webpart properties
* @returns
*/
exports.exportNotAvailMess = 'Export Unavailable';
/**
*
* @param exportStructure - object with keys as groups of properties to export, will cycle through each group which has it's own property keys in string array
* @param thisProperties - webpart props
* @param ignoreProps - array of property keys to explicitly not export
* @param skipNullUndefined - false by default, will show null and undefined values in export
* @returns
*/
function createExportObject(exportStructure, thisProperties, ignoreProps, skipNullUndefined) {
if (skipNullUndefined === void 0) { skipNullUndefined = false; }
var finalObject = {};
Object.keys(exportStructure).map(function (key) {
if (key === 'wpInstanceID' || key === 'currentWeb') { //If this is the wpInstanceID, then do not look for props
finalObject[key] = exportStructure[key];
}
else {
finalObject[key] = createExportGroup(exportStructure[key], thisProperties, ignoreProps, skipNullUndefined);
}
});
return finalObject;
}
exports.createExportObject = createExportObject;
/**
*
* @param updateOnThese - array of property keys to fetch from webpart props and save to exportProps object
* @param thisProperties - webpart props
* @param ignoreProps - array of property keys to explicitly not export
* @param skipNullUndefined - false by default, will show null and undefined values in export
* @returns
*/
function createExportGroup(updateOnThese, thisProperties, ignoreProps, skipNullUndefined) {
if (skipNullUndefined === void 0) { skipNullUndefined = false; }
var exportProps = {};
updateOnThese.map(function (thisProp) {
if ((0, checks_1.indexOfAnyCase)(thisProp, ignoreProps, true, false) < 0) {
//2022-02-16: had to update this so that it exports false, but also you can now specify to skip null or undefined if neccessary
var isUnknown = thisProperties[thisProp] === null || thisProperties[thisProp] === undefined ? true : false;
if (isUnknown === true && skipNullUndefined === true) {
//Skip this property because it's null or undefined and the paramter says to skip these
}
else {
exportProps[thisProp] = thisProperties[thisProp];
}
}
else {
exportProps[thisProp] = exports.exportNotAvailMess;
}
});
return exportProps;
}
exports.createExportGroup = createExportGroup;
//# sourceMappingURL=ExportFunctions.js.map
;