{"id":29864429,"url":"https://github.com/syntax-tree/hast-util-classnames","last_synced_at":"2025-07-30T08:15:57.844Z","repository":{"id":43396329,"uuid":"239459668","full_name":"syntax-tree/hast-util-classnames","owner":"syntax-tree","description":"utility to merge class names together","archived":false,"fork":false,"pushed_at":"2023-08-01T15:14:55.000Z","size":84,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-07-25T16:28:06.467Z","etag":null,"topics":["class","classname","classnames","hast","hast-util","html","svg","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","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/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","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":"2020-02-10T08:14:10.000Z","updated_at":"2023-01-07T13:10:15.000Z","dependencies_parsed_at":"2024-06-19T01:44:34.968Z","dependency_job_id":"69078f74-05d1-4c39-a41d-ccd1af3f98da","html_url":"https://github.com/syntax-tree/hast-util-classnames","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-classnames","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-classnames","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-classnames/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-classnames/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-classnames/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/hast-util-classnames/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-classnames/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267834811,"owners_count":24151642,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["class","classname","classnames","hast","hast-util","html","svg","util"],"created_at":"2025-07-30T08:15:56.736Z","updated_at":"2025-07-30T08:15:57.829Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"readme":"# hast-util-classnames\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[hast][] utility to set classes.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`classnames([node, ]…conditionals)`](#classnamesnode-conditionals)\n    *   [`ConditionalPrimitive`](#conditionalprimitive)\n    *   [`ConditionalMap`](#conditionalmap)\n    *   [`Conditional`](#conditional)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that takes lets you more easily set class names on\nelements.\n\n## When should I use this?\n\nYou can use this package when you find that that you’re repeating yourself\na lot when working with classes in the syntax tree.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-classnames\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {classnames} from 'https://esm.sh/hast-util-classnames@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {classnames} from 'https://esm.sh/hast-util-classnames@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {h} from 'hastscript'\nimport {classnames} from 'hast-util-classnames'\n\nconsole.log(classnames('alpha bravo', {bravo: false}, [123, 'charlie']))\n\nconst node = h('p.alpha', 'Hi!')\nconsole.log(classnames(node, 'bravo', ['charlie', {delta: false, echo: 1}]))\n```\n\nYields:\n\n```js\n['alpha', '123', 'charlie']\n{\n  type: 'element',\n  tagName: 'p',\n  properties: {className: ['alpha', 'bravo', 'charlie', 'echo']},\n  children: [{type: 'text', value: 'Hi!'}]\n}\n```\n\n## API\n\nThis package exports the identifier [`classnames`][api-classnames].\nThere is no default export.\n\n### `classnames([node, ]…conditionals)`\n\nMerge classes.\n\nThis function has two signatures, depending on whether a `node` was passed.\n\n###### Signatures\n\n*   `(node: Node, ...conditionals: Array\u003cConditional\u003e) =\u003e Node`\n*   `(...conditionals: Array\u003cConditional\u003e) =\u003e Array\u003cstring\u003e`\n\n###### Parameters\n\n*   `node` ([`Node`][node])\n    — optionally, node whose classes to append to (must be\n    [`Element`][element])\n*   `conditionals` ([`Array\u003cConditional\u003e`][api-conditional])\n    — class configuration to merge\n\n###### Returns\n\nThe given node ([`Node`][node]), if any, or a list of strings (`Array\u003cstring\u003e`).\n\n### `ConditionalPrimitive`\n\nBasic class names (TypeScript type).\n\n###### Type\n\n```ts\ntype ConditionalPrimitive = number | string\n```\n\n### `ConditionalMap`\n\nMap of class names as keys, with whether they’re turned on or not as values.\n\n###### Type\n\n```ts\ntype ConditionalMap = Record\u003cstring, boolean\u003e\n```\n\n### `Conditional`\n\nDifferent ways to turn class names on or off (TypeScript type).\n\n###### Type\n\n```ts\ntype Conditional =\n  | Array\u003c\n      | Array\u003cConditionalPrimitive | ConditionalMap\u003e\n      | ConditionalMap\n      | ConditionalPrimitive\n    \u003e\n  | ConditionalMap\n  | ConditionalPrimitive\n  | null\n  | undefined\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Conditional`][api-conditional],\n[`ConditionalMap`][api-conditional-map], and\n[`ConditionalPrimitive`][api-conditional-primitive].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `hast-util-classnames@^3`,\ncompatible with Node.js 16.\n\n## Security\n\nClasses are typically not harmful, however, if someone were able to inject\nclasses, it could mean that user-provided content looks like official content,\nwhich may cause security problems due to impersonation.\nEither do not use user input in `classnames` or use\n[`hast-util-sanitize`][hast-util-sanitize] to clean the tree.\n\n## Related\n\n*   [`hastscript`](https://github.com/syntax-tree/hastscript)\n    — create hast trees\n*   [`hast-util-from-selector`](https://github.com/syntax-tree/hast-util-from-selector)\n    — parse CSS selectors to hast nodes\n*   [`hast-util-has-property`](https://github.com/syntax-tree/hast-util-has-property)\n    — check if a node has a property\n*   [`hast-util-is-element`](https://github.com/syntax-tree/hast-util-is-element)\n    — check if a node is a (certain) element\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/hast-util-classnames/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-classnames/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-classnames.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-classnames\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-classnames.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-classnames\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=hast-util-classnames\n\n[size]: https://bundlejs.com/?q=hast-util-classnames\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[hast]: https://github.com/syntax-tree/hast\n\n[node]: https://github.com/syntax-tree/hast#nodes\n\n[element]: https://github.com/syntax-tree/hast#element\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[api-classnames]: #classnamesnode-conditionals\n\n[api-conditional]: #conditional\n\n[api-conditional-map]: #conditionalmap\n\n[api-conditional-primitive]: #conditionalprimitive\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-classnames","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-classnames","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-classnames/lists"}