
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
class-c
Chainable class name helper with first class CSS Module support
$ npm install class-c
c
uses the tagged template syntax
import c from "class-c";
c`a b`; // => "a b"
// Extra whitespace will be removed
c` a b `; // => "a b"
c`
a
b
`; // => "a b"
// Calling with a string can be useful for class forwarding, see CSS Modules section
c("a b"); // => "a b"
You can chain as many scopes as you'd like
c`a`.c`b c`.c`d`; // => "a b c d"
// This is more useful when used with CSS Modules, see CSS Modules section for more details
const styles = {
a: "scoped-a",
b: "scoped-b",
};
c(styles)`a b`.c`a b`; // => "scoped-a scoped-b a b"
Falsey values will be omitted, condition-by-class mapping is also supported. This can be useful with object shorthand. This also supports function conditions.
c`a ${condition && b}`; // => condition ? "a b" : "a"
c`a ${{ b: false, c: true }}`; // => "a c"
const focused = true;
const highlighted = false;
const open = true;
c`${{ focused, highlighted, open }}`; // => "focused open"
// Function conditions
const focused = () => true;
const highlighted = () => false;
const open = () => true;
c`${{ focused, highlighted, open }}`; // => "focused open"
Calling c
with a styles object will create a scoped context
const styles = {
a: "scoped-a",
b: "scoped-b",
};
c(styles)`a b`; // => "scoped-a scoped-b"
Chaining will reset context which can be useful for forwarding classes
c(styles)`a b`.c`a b`; // => "scoped-a scoped-b a b"
// Forwarding classes
const someExternalClasses = "external-a external-b";
c(styles)`a b`.c(someExternalClasses); // => "scoped-a scoped-b external-a external-b"
If you need to use a context in many places, it can be convenient to make a new helper
const cs = c(styles);
cs`a`; // => "scoped-a"
// Chaining will still reset context
cs`b`.c`c`; // => "scoped-b"
const otherStyles = {
a: "other-a",
b: "other-b",
};
c(styles)`a b`.c(otherStyles)`a b`; // => "scoped-a scoped-b other-a other-b"
// Non existant classes will be removed
c(styles)`a nonexistant b`; // => "scoped-a scoped-b"
const styles = {
variant_a: "scoped-variant_a",
variant_b: "scoped-variant_b",
};
const variant: "a" | "b" = "a";
c(styles)`variant_${variant}`; // => "scoped-variant_a"
const suffixStyles = {
a_suffix: "scoped-a_suffix",
b_suffix: "scoped-b_suffix",
};
c(suffixStyles)`${variant}_suffix`; // => "scoped-variant_a"
FAQs
className helper
The npm package class-c receives a total of 21 weekly downloads. As such, class-c popularity was classified as not popular.
We found that class-c demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.