1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/css-loader/lib/compile-exports.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
var camelCase = require("lodash/camelCase");
function dashesCamelCase(str) {
return str.replace(/-+(\w)/g, function(match, firstLetter) {
return firstLetter.toUpperCase();
});
}
module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) {
if (!Object.keys(result.exports).length) {
return "";
}
var exportJs = Object.keys(result.exports).reduce(function(res, key) {
var valueAsString = JSON.stringify(result.exports[key]);
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
function addEntry(k) {
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
}
var targetKey;
switch(camelCaseKeys) {
case true:
addEntry(key);
targetKey = camelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
}
break;
case 'dashes':
addEntry(key);
targetKey = dashesCamelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
}
break;
case 'only':
addEntry(camelCase(key));
break;
case 'dashesOnly':
addEntry(dashesCamelCase(key));
break;
default:
addEntry(key);
break;
}
return res;
}, []).join(",\n");
return "{\n" + exportJs + "\n}";
};