{"id":17381902,"url":"https://github.com/nazmus767921/easy-css-modules","last_synced_at":"2026-01-20T04:02:20.592Z","repository":{"id":227827725,"uuid":"772491927","full_name":"nazmus767921/easy-css-modules","owner":"nazmus767921","description":"A lightweight TypeScript utility designed to simplify the usage of CSS module classes.","archived":false,"fork":false,"pushed_at":"2024-05-04T11:18:51.000Z","size":5379,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T13:40:11.885Z","etag":null,"topics":["css-helpers","css-modules","css-modules-typescript-loader","npm-module","npm-package"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/easy-css-modules","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nazmus767921.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-15T09:49:49.000Z","updated_at":"2024-05-04T11:18:54.000Z","dependencies_parsed_at":"2024-03-18T12:52:48.836Z","dependency_job_id":null,"html_url":"https://github.com/nazmus767921/easy-css-modules","commit_stats":null,"previous_names":["nazmus767921/easy-css-modules"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nazmus767921/easy-css-modules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazmus767921%2Feasy-css-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazmus767921%2Feasy-css-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazmus767921%2Feasy-css-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazmus767921%2Feasy-css-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nazmus767921","download_url":"https://codeload.github.com/nazmus767921/easy-css-modules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazmus767921%2Feasy-css-modules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28595322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-helpers","css-modules","css-modules-typescript-loader","npm-module","npm-package"],"created_at":"2024-10-16T07:03:51.405Z","updated_at":"2026-01-20T04:02:20.497Z","avatar_url":"https://github.com/nazmus767921.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Working With CSS Modules is Even Easier\n\nA lightweight TypeScript utility designed to simplify the usage of CSS module classes in your projects. It provides a convenient way to transform a space-separated string of class names into a string containing the corresponding CSS module classes.\n\n## Changelog\n\nv2.0.2\n\n- Throws an error and logs the error stack to the console if no class names are provided or if `$_()` is invoked without class names. Additionally, an error is thrown for invalid CSS class names, such as `.123className`.\n\nv2.0.1\n\n- Minor changes and bug fixes.\n\nv2.0.0\n\n- The `useModuleClasses` is deprecated and will be removed in future updates due to conflicts with React Hooks naming conventions. Please switch to `utilizeModuleClasses` instead.\n- Now, You can access global classes alongside module classes outside the CSS module without extra templates. Simply, prepend a '@' before global class, as demonstrated: `$_(\".moduleClass .@globalClass)`\n- Automatic removal of duplicate classes, extra spaces within class names, class name validation.\n\n## Why Easy-CSS-Modules?\n\nAssuming you have a CSS module with classes defined like so:\n\n```css\n/* styles.module.css */\n.heading {\n  font-size: 24px;\n}\n.paragraph {\n  font-size: 16px;\n}\n```\n\nTypically, we access and utilize module classes in the following manner:\n\n```javascript\nimport styles from \"./styles.module.css\";\n\n\u003cdiv className={`${styles.heading} ${styles.paragraph}`}\u003e***\u003c/div\u003e;\n```\n\n**_It's acceptable, but templating classNames in this manner can become messy and tedious. However, with easy-css-modules, we can eliminate this hassle._**\n\n### Key Features\n\n- Simplified usage with CSS modules.\n- Automatic removal of duplicate classes.\n- Elimination of extra spaces within class names.\n- Robust class name validation, triggering an error on encountering an invalid class name.\n- Optimized for high performance.\n\n## Getting Started\n\nTo install, run the following command in your project directory:\n\n```bash\nnpm install easy-css-modules\nor\nyarn add easy-css-modules\nor\npnpm install easy-css-modules\n```\n\n### Usage\n\n1. Import the `utilizeModuleClasses` function from the package:\n\n```javascript\nimport styles from \"./styles.module.css\";\nimport utilizeModuleClasses from \"easy-css-modules\";\n```\n\n2. Initialize the `utilizeModuleClasses` hook (not specific to React; it functions with any JavaScript framework) as follows: it returns a function that accepts a space-separated string of class names (e.g., \".heading .paragraph\") as an argument. You can assign the hooked function to any variable or assign it to the const `$_` variable for stylistic and convenient usage.\n\n```javascript\nconst $_ = utilizeModuleClasses(styles);\n```\n\n3. Then, utilize the returned function or the `$_` function to dynamically apply these classes.\n\n\u003e 1. Define module classes like this: `$_(\".class .anotherClass\")`.\n\u003e 2. To access global classes alongside module classes outside the CSS module, prepend a '@' before global class, as demonstrated: `$_(\".moduleClass .@globalClass)`.\n\n---\n\n```javascript\n// 1. Import styles from css module and utilizeModuleClasses from easy-css-modules.\nimport styles from \"./styles.module.css\";\nimport { utilizeModuleClasses } from \"easy-css-modules\";\n\n// 2. Initialize the utilizeModuleClasses hook\nconst $_ = utilizeModuleClasses(styles);\n\n// 3. Use the classes\n\u003ch1 className={$_(\".heading .@globalClass\")}\u003e***\u003c/div\u003e;\n```\n\n### ✳Note\n\n\u003e - You are free to utilize any class naming convention, extending beyond camelCase, as exemplified by `.class__using--bem`.\n\u003e - The `.` preceding the classes isn't obligatory for this utility package to function. You can denote classes with a leading dot, as in `$_(\".first-class .second\")`, or without it, like `$_(\"first-class second\")`. However, employing the dot notation makes it easier to discern class references at a glance.\n\n### Parameters\n\n```javascript\nconst $_ = utilizeModuleClasses(styleObject);\n\n$_(classNames);\n```\n\n- `styleObject:` The CSS module classes object.\n\n- `classNames:` A space-separated string of class names (e.g., \".heading .paragraph\").\n  Returns\n  A function that takes a string of class names and returns a string of corresponding CSS module classes.\n\n## Additional Tips\n\n##### You can add these custom snippets in your vs code snippets settings to make your dev experience much more easy and faster.\n\n1. Navigate to `File \u003e Preferences \u003e Configure User Snippets`\n\n2. Copy the JSON code provided below and paste it into both `JavascriptReact(.jsx)` and `TypescriptReact(.tsx)`.\n\n3. Save the file and start using the snippets by typing the prefix associated with each snippet.\n\n- And now you can type any html tag to get snippets suggestions with easy-css-module templates.\n\n```json\n\"easy-css-module-template\": {\n\t\"prefix\": [\n\t\t\"div\",\n\t\t\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\",\n\t\t\"span\",\n\t\t\"p\",\n\t\t\"a\",\n\t\t\"ul\", \"ol\", \"li\",\n\t\t\"table\", \"tr\", \"td\", \"th\",\n\t\t\"form\", \"input\", \"button\",\n\t\t\"section\", \"article\", \"header\", \"footer\",\n\t\t\"nav\", \"aside\", \"main\",\n\t\t\"video\", \"audio\",\n\t],\n\t\"body\": [\n\t\t\"\u003c${TM_CURRENT_WORD} className={\\\\$_(\\\"${1}\\\")}\u003e${2}\u003c/${TM_CURRENT_WORD}\u003e\"\n\t],\n\t\"description\": \"Commented Section divider\"\n},\n\"easy-css-module-template-sct\": {\n\t\"prefix\": [\n\t\t\"img\",\n\t\t\"br\",\n\t\t\"hr\",\n\t\t\"meta\",\n\t\t\"link\",\n\t\t\"input\", // Can be self-closing for certain types (e.g., input type=\"hidden\")\n\t\t// Add more self-closing tags here\n\t],\n\t\"body\": [\n\t\t\"\u003c${TM_CURRENT_WORD} className={\\\\$_(\\\"${1}\\\")} /\u003e${2}\"\n\t],\n\t\"description\": \"Commented Section divider\"\n},\n\"arrow-component-with-css-module\": {\n\t\"scope\": \"javascript, typescript, typescriptreact, javascriptreact\",\n\t\"prefix\": [\n\t\t\"afce\"\n\t],\n\t\"body\": [\n\t\t\"import styles from \\\"${1}\\\";\",\n\t\t\"import  { utilizeModuleClasses } from \\\"easy-css-modules\\\";\",\n\t\t\"\",\n\t\t\"const \\\\$_ = utilizeModuleClasses(styles);\",\n\t\t\"\",\n\t\t\"const ${2:$TM_FILENAME_BASE} = () =\u003e {\",\n\t\t\"  return (\",\n\t\t\"    \u003c\u003e\",\n\t\t\"      ${3}\",\n\t\t\"    \u003c/\u003e\",\n\t\t\"  );\",\n\t\t\"}\",\n\t\t\"\",\n\t\t\"export default ${2:$TM_FILENAME_BASE};\"\n\t],\n\t\"description\": \"Commented Section divider\"\n}\n```\n\n## LICENSE [MIT](https://github.com/nazmus767921/easy-css-modules/blob/main/LISENSE)\n\nThe MIT License (MIT) | Copyright (c) 2024 Nazmus Sakib\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazmus767921%2Feasy-css-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnazmus767921%2Feasy-css-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazmus767921%2Feasy-css-modules/lists"}