css-string

1.0.1 • Public • Published

css-string

create CSS-compatible strings from object trees

let style = document.createElement("style")
document.head.appendChild(style)
style.innerText = stringify({
  body: {
    display: "flex",
    height: "100%"
  }
})

This package exposes the stringify function, which creates CSS-compatible strings from object trees. The resulting strings can be used directly in dynamic stylesheets as well as HTMLElement.style.

usage

npm badge

> stringify({ color: "red" })
"color:red"

Use strings as keys to represent complex selectors, property names, and values.

> stringify({
    "*": {
      "margin": 0,
      "padding": 0,
      "box-sizing": "border-box"
    }
  })
"*{margin:0;padding:0;box-sizing:border-box}"

If a declaration has an object as its value, it will be treated as a rule with its own selector and declarations.

> stringify({
    nav: {
      display: "flex",
      a: {
        color: "inherit"
      }
    }
  })
"nav{display:flex;a{color:inherit}}"

license

MIT © Brandon Semilla

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.14latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.14
1.0.01
0.0.01

Package Sidebar

Install

npm i css-string

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

3.09 kB

Total Files

4

Last publish

Collaborators

  • semibran