{"id":13447530,"url":"https://github.com/lukeed/obj-str","last_synced_at":"2025-04-04T21:08:11.404Z","repository":{"id":44747718,"uuid":"87672832","full_name":"lukeed/obj-str","owner":"lukeed","description":"A tiny (96B) library for serializing Object values to Strings.","archived":false,"fork":false,"pushed_at":"2023-02-27T16:32:56.000Z","size":55,"stargazers_count":241,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T05:17:01.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"lukeed"}},"created_at":"2017-04-09T00:37:08.000Z","updated_at":"2024-03-21T02:54:10.000Z","dependencies_parsed_at":"2024-01-06T23:59:22.367Z","dependency_job_id":"3c1b9cd0-7de9-49a9-a5f0-a7cea1e9547a","html_url":"https://github.com/lukeed/obj-str","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":"0.046511627906976716","last_synced_commit":"0b3e06087f5807eea4fbeef5d39332c74b860eab"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fobj-str","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fobj-str/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fobj-str/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fobj-str/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/obj-str/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249525,"owners_count":20908212,"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":[],"created_at":"2024-07-31T05:01:20.206Z","updated_at":"2025-04-04T21:08:11.385Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript","Framework agnostic packages"],"sub_categories":["General utilities"],"readme":"# obj-str [![CI](https://github.com/lukeed/obj-str/workflows/CI/badge.svg)](https://github.com/lukeed/obj-str/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/obj-str)](https://codecov.io/gh/lukeed/obj-str)\n\n\u003e A tiny (96B) library for serializing Object values to Strings.\n\nThis module's intended use is for converting an Object with CSS class names (as keys) to a space-delimited `className` string. Other modules have similar goals (like [`classnames`](https://npm.im/classnames)), but `obj-str` only does one thing. This is why it's only 100 bytes gzipped!\n\n_PS: I made this because [Preact 8.0 removed this built-in behavior](https://github.com/developit/preact/commit/b2c85e3f7fa89ebbf242b00f4cab7619641e3a52) and I wanted a quick, drop-in replacement._\n\n## Install\n\n```\n$ npm install --save obj-str\n```\n\n\n## Usage\n\n```js\nimport objstr from 'obj-str';\n\nobjstr({ foo:true, bar:false, baz:isTrue() });\n//=\u003e 'foo baz'\n```\n\n### React\n\nWith React (or any of the React-like libraries!), you can take advantage of any `props` or `state` values in order to express conditional classes as an object.\n\n```js\nimport React from 'react';\nimport objstr from 'obj-str';\n\nconst TodoItem = ({ text, isDone, disabled }) =\u003e (\n  \u003cli className={ objstr({ item:true, completed:isDone, disabled }) }\u003e\n    \u003cinput type=\"checkbox\" disabled={ disabled } checked={ isDone } /\u003e\n    \u003clabel\u003e{ text }\u003c/label\u003e\n  \u003c/li\u003e\n);\n```\n\n### Preact\n\nFor simple use, the [React](#react) example will work for Preact too. However, you may also define a custom vNode \"polyfill\" to automatically handle Objects when used inside `className`.\n\n\u003e **Note:** For users of Preact 7.1 and below, _you do not need this module_! Your version includes this behavior out of the box!\n\n```js\nimport objstr from 'obj-str';\nimport { options } from 'preact';\n\nconst old = options.vnode;\n\noptions.vnode = vnode =\u003e {\n  const props = vnode.attributes;\n  if (props != null) {\n    const k = 'class' in props ? 'class' : 'className';\n    if (props[k] \u0026\u0026 typeof props[k]=='object') {\n      props[k] = objstr(props[k]);\n    }\n  }\n  old \u0026\u0026 old(vnode);\n}\n```\n\n\n## API\n\n### objstr(input)\n\n#### input\n\nType: `Object`\n\nA hashmap of keys \u0026 their truthy/falsey values. Booleans are preferred when speed is critically important.\n\n\n## Related\n\n- [babel-plugin-optimize-obj-str](./babel-plugin-optimize-obj-str) - Babel plugin to transform `obj-str` calls into optimized expressions.\n\n- [clsx](https://github.com/lukeed/clsx) - Drop-in replacement for `obj-str` and `classnames` – handles all (and multiple) input types.\n\n\n## License\n\nMIT © [Luke Edwards](http://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fobj-str","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fobj-str","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fobj-str/lists"}