pretty-lights
Version:
CSS-in-JS with a reliable API
39 lines (27 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLabel = getLabel;
exports.omit = omit;
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function getLabel(identifierName, autoLabel, labelFormat, filename) {
if (!identifierName || !autoLabel) return null; // Valid Characters in CSS Class Names Selecter
// https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors#449000
var normalizedName = identifierName.replace(/[^\w-]/g, '');
if (!labelFormat) return normalizedName;
var parsedPath = _path["default"].parse(filename);
var normalizedFilename = parsedPath.name.replace('.', '-').replace(/[^\w-]/g, '');
return labelFormat.replace(/\[local\]/gi, normalizedName).replace(/\[filename\]/gi, normalizedFilename);
}
function omit(obj, testFn) {
var target = {};
var i; // eslint-disable-next-line no-restricted-syntax
for (i in obj) {
if (!testFn(i, obj)) continue; // eslint-disable-line no-continue
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; // eslint-disable-line no-continue
target[i] = obj[i];
}
return target;
}