simple-merge-class-names 1.0.10 → 2.0.1

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/README.md CHANGED
@@ -7,12 +7,16 @@ A straightforward utility for merging CSS class names in `React + Tailwind` and
7
7
  - [Installation](#installation)
8
8
  - [Install Prettier With VSCode (Most Recommended)](#install-prettier-with-vscode-most-recommended)
9
9
  - [Usage](#usage)
10
+
10
11
  - [Workflow To Minimize Typing Strain](#workflow-to-minimize-typing-strain)
12
+
13
+ - [Argument Handling](#argument-handling)
14
+ - [Breaking Changes From Version 1.X.X](#breaking-changes-from-version-1xx)
15
+ - [Testing](#testing)
16
+ - [Source Code](#source-code)
11
17
  - [Why the Mismatch Between Exported Function and Package Name?](#why-the-mismatch-between-exported-function-and-package-name)
12
18
  - [Where This Package Excels](#where-this-package-excels)
13
- - [Source Code](#source-code)
14
- - [Argument Handling](#argument-handling)
15
- - [Testing](#testing)
19
+
16
20
  - [Production Considerations](#production-considerations)
17
21
  - [License](#license)
18
22
 
@@ -89,15 +93,29 @@ function MyComponent() {
89
93
  - Replaces single quotes with double quotes.
90
94
  - Neatly arranges each class name on a new line.
91
95
 
92
- ## Why the Mismatch Between Exported Function and Package Name?
96
+ ## Argument Handling
93
97
 
94
- 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.
98
+ `mergeClassNames` only accepts **_non-empty string values_**, everything else like empty strings (`""`), `null`, `undefined`, numbers, objects and arrays is _ignored_. This ensures stricter and predictable output.
95
99
 
96
- In addition there was already a package named `merge-class-names` but it is no longer maintained (and the developer recommends `clsx` instead).
100
+ ### Breaking Changes From Version 1.X.X
97
101
 
98
- ## Where This Package Excels
102
+ In pervious versions, arguments that were not strings were implicitly converted to strings by the JavaScript engine.
99
103
 
100
- 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.
104
+ ## Testing
105
+
106
+ This project uses `Vitest` as the test runner for fast, modern testing.
107
+
108
+ #### Run All Testing Once
109
+
110
+ ```bash
111
+ pnpm test
112
+ ```
113
+
114
+ #### Run Tests In Watch Mode
115
+
116
+ ```bash
117
+ pnpm test:watch
118
+ ```
101
119
 
102
120
  ## Source Code
103
121
 
@@ -106,39 +124,34 @@ While similar packages exist (`clsx`) with better features and potentially impro
106
124
  * mergeClassNames - A straightforward utility for merging CSS class names in React + Tailwind, and other JavaScript projects.
107
125
  ...
108
126
  */
109
- const isDefined = (val) => val !== undefined && val !== null;
127
+
128
+ const isTypeString = (val) => typeof val === "string";
110
129
 
111
130
  const isNotEmptyString = (val) => val !== "";
112
131
 
113
132
  export const mergeClassNames = (...args) => {
114
- const space = " ";
115
- const values = args.filter(
116
- (val) => isDefined(val) && isNotEmptyString(val)
117
- );
118
- const className = values.join(space);
119
- return className;
120
- };
121
- ```
133
+ const space = "\x20"; // " "; ASCII code for single space character;
122
134
 
123
- ### Argument Handling
135
+ const stringsOnly = args.filter((val) => isTypeString(val));
124
136
 
125
- `mergeClassNames` accepts multiple arguments but filters out `null`, `undefined`, and empty strings (`""`). Remaining values are either strings or are _implicitly converted_ to strings by the JavaScript engine, then joined with spaces to produce the final class name string.
137
+ const trimmed = stringsOnly.map((val) => val.trim());
126
138
 
127
- ### Testing
139
+ const nonEmpty = trimmed.filter((val) => isNotEmptyString(val));
128
140
 
129
- This project uses `Vitest` as the test runner for fast, modern testing.
141
+ const className = nonEmpty.join(space);
142
+ return className;
143
+ };
144
+ ```
130
145
 
131
- #### Run All Testing Once
146
+ ## Why the Mismatch Between Exported Function and Package Name?
132
147
 
133
- ```bash
134
- pnpm test
135
- ```
148
+ 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.
136
149
 
137
- #### Run Tests In Watch Mode
150
+ In addition there was already a package named `merge-class-names` but it is no longer maintained (and the developer recommends `clsx` instead).
138
151
 
139
- ```bash
140
- pnpm test:watch
141
- ```
152
+ ## Where This Package Excels
153
+
154
+ 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.
142
155
 
143
156
  ## Production Considerations
144
157
 
@@ -148,4 +161,6 @@ If you are considering this package for production, you might also want to look
148
161
 
149
162
  This project is licensed under the AGPL-3.0 License. See `LICENSE.txt` for full details.
150
163
 
164
+ ---
165
+
151
166
  Enjoy 😉
@@ -37,15 +37,19 @@
37
37
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
38
38
  */
39
39
 
40
- const isDefined = (val) => val !== undefined && val !== null;
40
+ const isTypeString = (val) => typeof val === "string";
41
41
 
42
42
  const isNotEmptyString = (val) => val !== "";
43
43
 
44
44
  export const mergeClassNames = (...args) => {
45
- const space = " ";
46
- const values = args.filter(
47
- (val) => isDefined(val) && isNotEmptyString(val)
48
- );
49
- const className = values.join(space);
45
+ const space = "\x20"; // " "; ASCII code for single space character;
46
+
47
+ const stringsOnly = args.filter((val) => isTypeString(val));
48
+
49
+ const trimmed = stringsOnly.map((val) => val.trim());
50
+
51
+ const nonEmpty = trimmed.filter((val) => isNotEmptyString(val));
52
+
53
+ const className = nonEmpty.join(space);
50
54
  return className;
51
55
  };
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "simple-merge-class-names",
3
- "version": "1.0.10",
4
- "description": "Example usage: <div className = {mergeClassNames('flex', 'flex-col')}/>",
5
- "main": "mergeClassNames.js",
6
- "exports": "./mergeClassNames.js",
7
- "files": [
8
- "package.json",
9
- "mergeClassNames.js",
10
- "LICENSE.txt",
11
- "README.md"
12
- ],
13
- "scripts": {
14
- "test": "vitest",
15
- "test:watch": "vitest --watch",
16
- "test:ui": "vitest --ui"
17
- },
18
- "keywords": [
19
- "merge",
20
- "class-names-merger",
21
- "utility",
22
- "react",
23
- "tailwindcss"
24
- ],
25
- "author": "Abdullah Fatota",
26
- "license": "AGPL-3.0",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/new-AF/simple-merge-class-names.git"
30
- },
31
- "bugs": {
32
- "url": "https://github.com/new-AF/simple-merge-class-names/issues"
33
- },
34
- "homepage": "https://github.com/new-AF/simple-merge-class-names",
35
- "devDependencies": {
36
- "vitest": "^3.2.3"
37
- }
38
- }
1
+ {
2
+ "name": "simple-merge-class-names",
3
+ "version": "2.0.1",
4
+ "description": "Example usage: <div className = {mergeClassNames('flex', 'flex-col')}/>",
5
+ "main": "mergeClassNames.js",
6
+ "exports": "./mergeClassNames.js",
7
+ "files": [
8
+ "package.json",
9
+ "mergeClassNames.js",
10
+ "LICENSE.txt",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "test": "vitest",
15
+ "test:watch": "vitest --watch",
16
+ "test:ui": "vitest --ui"
17
+ },
18
+ "keywords": [
19
+ "merge",
20
+ "class-names-merger",
21
+ "utility",
22
+ "react",
23
+ "tailwindcss"
24
+ ],
25
+ "author": "Abdullah Fatota",
26
+ "license": "AGPL-3.0",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/new-AF/simple-merge-class-names.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/new-AF/simple-merge-class-names/issues"
33
+ },
34
+ "homepage": "https://github.com/new-AF/simple-merge-class-names",
35
+ "devDependencies": {
36
+ "vitest": "^3.2.3"
37
+ }
38
+ }