simple-merge-class-names 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +41 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,30 @@
1
1
  # simple-merge-class-names
2
2
 
3
- A straightforward utility for merging CSS class names in `React`, `Tailwind` and other JavaScript projects.
3
+ A straightforward utility for merging CSS class names in `React + Tailwind` and other JavaScript projects.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  pnpm add simple-merge-class-names
9
- # or
9
+ ```
10
+
11
+ ```bash
10
12
  yarn add simple-merge-class-names
11
- # or
13
+ ```
14
+
15
+ ```bash
12
16
  npm install simple-merge-class-names
13
17
  ```
14
18
 
15
- ## Install Prettier with VSCode (Recommended)
19
+ ## Install `Prettier` with VSCode (Most Recommended)
16
20
 
17
- For optimal developer experience, install Prettier for VS Code: [https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode), or an equivalent auto code formatter for your IDE.
21
+ Install Prettier for VS Code for most optimal developer experience: [https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
22
+
23
+ Or install an equivalent auto code formatter for your IDE.
18
24
 
19
25
  ## Usage
20
26
 
21
- The single function provided by this package is `mergeClassNames(...args)`.
27
+ `mergeClassNames(...args)` is the single exported function from this package package.
22
28
 
23
29
  ```jsx
24
30
  import { mergeClassNames } from "simple-merge-class-names";
@@ -40,24 +46,37 @@ function MyComponent() {
40
46
  }
41
47
  ```
42
48
 
43
- Using individual strings for each class name can be tedious, however it significantly enhances code readability and Developer Experience (DX). This is in contrast to hard-to-read strings like `className="app min-h-dvh grid grid-rows-[auto_1fr_auto] outline"`.
49
+ Using individual strings for each class name can be tedious (see [Workflow to minimize typing strain](#workflow-to-minimize-typing-strain)), however it significantly enhances code readability and Developer Experience (DX). This is in contrast to hard-to-read strings like:
44
50
 
45
- ## To minimize typing strain:
51
+ ```jsx
52
+ function MyComponent() {
53
+ return (
54
+ <div className="app min-h-dvh grid grid-rows-[auto_1fr_auto] outline">
55
+ Hello, world!
56
+ </div>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ## Workflow to minimize typing strain:
46
62
 
47
63
  ![Screen recording of optimal DX in action: using this package with Prettier as it neatly arranges each class name on a new line](https://raw.githubusercontent.com/new-AF/simple-merge-class-names/main/.github/images/Reduce%20typing%20strain.gif)
48
64
 
49
- - Use single quotes for class names, often a single key press on many keyboards.
50
- - Save the file (e.g., with `Ctrl+S`), and Prettier does the rest; it automatically:
65
+ - Have `Prettier` installed
66
+ - Use single quotes (<kbd>'</kbd>) for class names, often a single key press on many keyboards.
67
+ - Save the file (<kbd>Ctrl+S</kbd>), and Prettier does the formatting heavy-lifting, it automatically:
51
68
  - Replaces single quotes with double quotes.
52
69
  - Neatly arranges each class name on a new line.
53
70
 
54
- ## Why the mismatch between Function, and Package name?
71
+ ## Why the mismatch between exported Function, and Package name?
55
72
 
56
- Although I wanted to name the package as `mergeClassNames` to reflect the single exported function, the NPM Package Registry does not allow capital letters, only lower case and dash characters. In addition there was already a package named merge-class-names but it is no longer maintained.
73
+ I wanted to name the package as `mergeClassNames` to reflect the single exported function, but the NPM Package Registry does not allow capital letters, only lower case and dash characters.
57
74
 
58
- ## Where this Package excels
75
+ In addition there was already a package named `merge-class-names` but it is no longer maintained (and the developer recommends `clsx` instead).
59
76
 
60
- While similar packages exist (see `clsx`) with often better features and potentially improved performance, `simple-merge-class-names` focuses on being very straightforward and easy to reason about, as defined in its source code.
77
+ ## Where this package excels
78
+
79
+ While similar packages exist (`clsx`) with better features and potentially improved performance, `simple-merge-class-names` focuses on being very straightforward and easy to reason about, as defined in its source code.
61
80
 
62
81
  ## Source Code
63
82
 
@@ -98,6 +117,12 @@ export const mergeClassNames = (...args) => {
98
117
  };
99
118
  ```
100
119
 
120
+ ## Argument Handling
121
+
122
+ `mergeClassNames` accepts multiple arguments but filters out `null`, `undefined`, and empty strings (`""`), and the remaining values are either strings or are _implicitly converted_ to strings by the JavaScript engine.
123
+
124
+ Finally the end string values are merged and separated by spaces.
125
+
101
126
  ## Production Considerations
102
127
 
103
128
  If you are considering this package for production, you might also want to look into `clsx` for more advanced features: [https://www.npmjs.com/package/clsx](https://www.npmjs.com/package/clsx)
@@ -105,3 +130,5 @@ If you are considering this package for production, you might also want to look
105
130
  ## License
106
131
 
107
132
  This project is licensed under the AGPL-3.0 License. See `LICENSE.txt` for full details.
133
+
134
+ ## Enjoy 😉
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-merge-class-names",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Example usage: <div className = {mergeClassNames('flex', 'flex-col')}/>",
5
5
  "main": "mergeClassNames.js",
6
6
  "exports": "./mergeClassNames.js",