UNPKG

1.35 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _SimpleMap = require('./SimpleMap');
8
9var _SimpleMap2 = _interopRequireDefault(_SimpleMap);
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13var CustomMap = typeof Map === 'undefined' ? _SimpleMap2.default : Map;
14
15var stylesIndex = new CustomMap();
16
17exports.default = function (styles, styleNames, errorWhenNotFound) {
18 var appendClassName = void 0;
19 var stylesIndexMap = void 0;
20
21 stylesIndexMap = stylesIndex.get(styles);
22
23 if (stylesIndexMap) {
24 var styleNameIndex = stylesIndexMap.get(styleNames);
25
26 if (styleNameIndex) {
27 return styleNameIndex;
28 }
29 } else {
30 stylesIndexMap = new CustomMap();
31 stylesIndex.set(styles, new CustomMap());
32 }
33
34 appendClassName = '';
35
36 for (var styleName in styleNames) {
37 if (styleNames.hasOwnProperty(styleName)) {
38 var className = styles[styleNames[styleName]];
39
40 if (className) {
41 appendClassName += ' ' + className;
42 } else if (errorWhenNotFound === true) {
43 throw new Error('"' + styleNames[styleName] + '" CSS module is undefined.');
44 }
45 }
46 }
47
48 appendClassName = appendClassName.trim();
49
50 stylesIndexMap.set(styleNames, appendClassName);
51
52 return appendClassName;
53};
54
55module.exports = exports['default'];
\No newline at end of file