Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-breaking additions to makeLocalsConventionReducer #154

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [16.x, 18.x, 19.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/
npm-debug.log
index.es5.js
undefined.json
.idea/
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,19 @@ postcss([

### localsConvention

Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => className: string`
Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => className: (string|string[])`
Default: `null`

Style of exported classnames, the keys in your json.

| Name | Type | Description |
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
|:---------------------:| :--------: |:-------------------------------------------------------------------------------------------------|
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
| **`'all'`** | `{String}` | Apply camelCase, dashes, and the orignional naming convention |
| **`'none'`** | `{String}` | Only use the orignional naming convention with out locals |

In lieu of a string, a custom function can generate the exported class names.

Expand Down
56 changes: 19 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-modules",
"version": "6.0.0",
"version": "6.0.1",
"description": "PostCSS plugin to use CSS Modules everywhere",
"main": "build/index.js",
"types": "index.d.ts",
Expand Down
19 changes: 19 additions & 0 deletions src/localsConvention.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,31 @@ export function makeLocalsConventionReducer(localsConvention, inputFile) {
return (tokens, [className, value]) => {
if (isFunc) {
const convention = localsConvention(className, value, inputFile);

if (Array.isArray(convention)) {

convention.forEach(convention => tokens[convention] = value);

return tokens;

}

tokens[convention] = value;

return tokens;
}

switch (localsConvention) {
case "none":
tokens[className] = value;
break;

case "all":
tokens[className] = value;
tokens[camelCase(className)] = value;
tokens[dashesCamelCase(className)] = value;
break;

case "camelCase":
tokens[className] = value;
tokens[camelCase(className)] = value;
Expand Down