postcss-modules 1.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Added
6
+
7
+ - [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) by Hamza Mihai Daniel (@allocenx) <https://github.com/css-modules/postcss-modules/pull/103>, <https://github.com/css-modules/postcss-modules/issues/93>
8
+
9
+ ### Breaking changes
10
+
11
+ - `camelCase` camelCase removed, use the [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) instead.
12
+
3
13
  ## 1.5.0
4
14
 
5
15
  - Added `hashPrefix` option by Jesse Thomson (@jessethomson) <https://github.com/css-modules/postcss-modules/pull/98>
package/README.md CHANGED
@@ -181,26 +181,19 @@ postcss([
181
181
  ]);
182
182
  ```
183
183
 
184
- ### Camel cased classes
184
+ ### localsConvention
185
185
 
186
- If you need, you can pass the options `{ camelCase: true }` to transform classes:
186
+ Type: `String`
187
+ Default: `null`
187
188
 
188
- CSS:
189
+ Style of exported classnames.
189
190
 
190
- ```css
191
- .post-title {
192
- color: red;
193
- }
194
- ```
195
-
196
- JSON:
197
-
198
- ```json
199
- {
200
- "post-title": "._post-title_116zl_1",
201
- "postTitle": "._post-title_116zl_1"
202
- }
203
- ```
191
+ | Name | Type | Description |
192
+ | :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
193
+ | **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
194
+ | **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
195
+ | **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
196
+ | **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
204
197
 
205
198
  ## Integration with templates
206
199
 
package/build/index.js CHANGED
@@ -79,6 +79,10 @@ function isResultPlugin(plugin) {
79
79
  return plugin.postcssPlugin !== PLUGIN_NAME;
80
80
  }
81
81
 
82
+ function dashesCamelCase(string) {
83
+ return string.replace(/-+(\w)/g, (_, firstLetter) => firstLetter.toUpperCase());
84
+ }
85
+
82
86
  module.exports = _postcss2.default.plugin(PLUGIN_NAME, (opts = {}) => {
83
87
  const getJSON = opts.getJSON || _saveJSON2.default;
84
88
 
@@ -98,11 +102,31 @@ module.exports = _postcss2.default.plugin(PLUGIN_NAME, (opts = {}) => {
98
102
  const out = loader.finalSource;
99
103
  if (out) css.prepend(out);
100
104
 
101
- if (opts.camelCase) {
102
- Object.keys(parser.exportTokens).forEach(function (token) {
103
- const camelCaseToken = (0, _lodash2.default)(token);
104
- parser.exportTokens[camelCaseToken] = parser.exportTokens[token];
105
- });
105
+ if (opts.localsConvention) {
106
+ parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
107
+ switch (opts.localsConvention) {
108
+ case "camelCase":
109
+ tokens[className] = value;
110
+ tokens[(0, _lodash2.default)(className)] = value;
111
+
112
+ break;
113
+ case "camelCaseOnly":
114
+ tokens[(0, _lodash2.default)(className)] = value;
115
+
116
+ break;
117
+ case "dashes":
118
+ tokens[className] = value;
119
+ tokens[dashesCamelCase(className)] = value;
120
+
121
+ break;
122
+ case "dashesOnly":
123
+ tokens[dashesCamelCase(className)] = value;
124
+
125
+ break;
126
+ }
127
+
128
+ return tokens;
129
+ }, {});
106
130
  }
107
131
 
108
132
  result.messages.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-modules",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "description": "PostCSS plugin to use CSS Modules everywhere",
5
5
  "main": "build/index.js",
6
6
  "keywords": [