{"id":14990684,"url":"https://github.com/crown3/cx","last_synced_at":"2026-01-05T01:19:01.605Z","repository":{"id":40422234,"uuid":"365141072","full_name":"crown3/cx","owner":"crown3","description":"cx is a TypeScript utility which contains conditional processing, can process both CSS Module and native CSS className ","archived":false,"fork":false,"pushed_at":"2023-01-18T17:06:04.000Z","size":615,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T21:51:06.574Z","etag":null,"topics":["classnames","css","cssmodules","cssmodules-react","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crown3.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-07T06:50:00.000Z","updated_at":"2021-07-22T02:45:24.000Z","dependencies_parsed_at":"2023-02-10T16:15:44.853Z","dependency_job_id":null,"html_url":"https://github.com/crown3/cx","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crown3%2Fcx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crown3%2Fcx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crown3%2Fcx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crown3%2Fcx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crown3","download_url":"https://codeload.github.com/crown3/cx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244888564,"owners_count":20526829,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["classnames","css","cssmodules","cssmodules-react","typescript"],"created_at":"2024-09-24T14:20:35.334Z","updated_at":"2026-01-05T01:19:01.579Z","avatar_url":"https://github.com/crown3.png","language":"TypeScript","readme":"# \u003cp align=\"center\"\u003e[CX](https://github.com/crown3/cx)\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/crown3\"\u003e\u003cimg alt=\"Author Info\" src=\"https://img.shields.io/badge/-Made%20by%20Crown3-grey?logo=c\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/crown3\"\u003e\u003cimg alt=\"Gzip size\" src=\"https://img.badgesize.io/https:/unpkg.com/@crown3/cx/dist/cx.cjs.production.min.js?style=flat-square\u0026compression=gzip\"\u003e\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/crown3/cx/\"\u003e\u003cimg alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/crown3/cx?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@crown3/cx\"\u003e\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/@crown3/cx?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/crown3/cx\"\u003e\u003cimg alt=\"GitHub license\" src=\"https://img.shields.io/github/license/crown3/cx?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"./docs/README.zh-CN.md\"\u003e中文\u003c/a\u003e｜English\u003c/p\u003e\n\n\u003e `cx` is a TypeScript utility that contains conditional processing, can process both CSS Module and native CSS className (Inspired by [classNames/bind](https://github.com/JedWatson/classnames))\n\n```js\ncx('a', true, { c: true })\n// =\u003e 'a c'  just like classNames function\n\n// But when you bind styles in cx and the first argument is arr\nimport styles from './style.module.css'\nimport classNames from '@crown3/cx'\nconst cx = classNames.bind(styles)\ncx(['a', { b: true }], 'c', { d: true }, [{ e: true }])\n// =\u003e 'a-module-class b-module-class c d e\n```\n\n## Getting Started\n\n```bash\n# via npm\nnpm install @crown3/cx\n\n# or Yarn\nyarn add @crown3/cx\n```\n\nUse with TypeScript\n\n```typescript\nimport classNames, { CX } from '@crown3/cx'\nimport styles from './demo.module.css'\n\nconst cx: CX = classNames.bind(styles)\ncx(['hello'], 'world')\n// =\u003e 'hello-module-class world'\n```\n\nOr in JavaScript\n\n```javascript\nimport { classNames } from '@crown3/cx'\nimport styles from './demo.module.css'\n\nconst cx = classNames.bind(styles)\n```\n\n## Documentation\n\n**Only when you bind this to CSS Module styles and the first argument is array**, cx will handle all arguments in this array as CSS Module (Others are still handled as normal CSS styles)\n\n- Note: If you bind a CSS Module but the first argument isn't array, cx will handle all arguments as normal CSS styles\n- The processing logic of the arguments is similar with [classNames/bind](https://github.com/JedWatson/classnames), all arguments will do a conditionally handle and if the result is true, the key will be output\n  - But there's a little different with [classNames/bind](https://github.com/JedWatson/classnames) in handling CSS Module styles, when the class name doesn't exist in the CSS Module, cx will ignore this instead of returning it as a string like [classNames/bind](https://github.com/JedWatson/classnames)\n\n```javascript\n// mock a CSS Module styles\nimport classNames from '@crown3/cx'\n\nconst cx = classNames\ncx([{ a: true, b: false }], 'c', undefined, null) // =\u003e 'a c'\n\n// But when you bind styles\nconst styles = { a: 'a1', b: 'b2' }\nconst cx = classNames.bind(styles)\n\ncx(['a', { b: true }]) // =\u003e 'a1 b2'\n// But if first arg isn't array, cx will handle all arguments as normal css, even if you bind styles\ncx('a', ['b']) // =\u003e 'a b'\n\n// the arguments can accept any number of items which can be a string, boolean, number, array or Object\n// If the value associated with a given key is falsy, the key won't be included in the output\ncx(['a', { b: true }, [{ b: true }, 'c']], 'a', ['b'], [{ c: true }])\n// =\u003e 'a1 b2 b2 a b c'\n// Note: there hasn't 'cx' in our output, because the Module styles doesn't have the 'c' key\n\n// Even using it like this\ncx(\n  [\n    {\n      toString() {\n        return 'a'\n      },\n    },\n    {\n      toString() {\n        return 'c'\n      },\n    },\n  ],\n  {\n    toString() {\n      return 'b'\n    },\n  }\n)\n// =\u003e 'a1 b'\n```\n\n## License\n\n[@crown3/cx](https://github.com/crown3/cx) is licensed under a [MIT License](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrown3%2Fcx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrown3%2Fcx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrown3%2Fcx/lists"}