Skip to content

Commit

Permalink
chore(exports): rename SEPARATORS
Browse files Browse the repository at this point in the history
to CLASSY_SEPARATORS
  • Loading branch information
rafegoldberg committed Dec 28, 2021
1 parent 67e7f6f commit 7ae8d14
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
36 changes: 18 additions & 18 deletions src/classy.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Classy, { SEPARATORS } from "./classy";
import { classy, CLASSY_SEPARATORS } from ".";

const mockScope = {
RootElem: "bPDD5MZYqy37J8a5Ed",
Expand All @@ -9,29 +9,29 @@ const mockScope = {
describe("Classy", () => {
describe("Class List Normalization", () => {
it("concatenates variable-length arguments", () => {
expect(Classy("test1", "test2", "test3")).toBe("test1 test2 test3");
expect(classy("test1", "test2", "test3")).toBe("test1 test2 test3");
});

it("flattens deeply nested arrays of strings", () => {
expect(Classy(["test1", ["test2", ["test3"]]])).toBe("test1 test2 test3");
expect(classy(["test1", ["test2", ["test3"]]])).toBe("test1 test2 test3");
});

it("expands comma-separated strings", () => {
expect(Classy("test1,test2, test3")).toBe("test1 test2 test3");
expect(classy("test1,test2, test3")).toBe("test1 test2 test3");
});

it("expands dot-separated strings", () => {
expect(Classy(".test1.test2.test3")).toBe("test1 test2 test3");
expect(classy(".test1.test2.test3")).toBe("test1 test2 test3");
});

it("expands space-separated strings", () => {
expect(Classy("test1 test2 test3")).toBe("test1 test2 test3");
expect(classy("test1 test2 test3")).toBe("test1 test2 test3");
});
});

describe("CSS Module Auto-Scoping", () => {
it("accepts an initial hash of scoped selectors", () => {
expect(Classy(mockScope, "RootElem")).toBe("bPDD5MZYqy37J8a5Ed");
expect(classy(mockScope, "RootElem")).toBe("bPDD5MZYqy37J8a5Ed");
});

it("skips pre-scoped classes that end in `-scss` (WHY DO WE DO THIS!?)", () => {
Expand All @@ -43,12 +43,12 @@ describe("Classy", () => {
*/
const prescopedClass = "_1adDfJfhK6H-scss";
const scope = { [prescopedClass]: "PRESCOPED" };
expect(Classy(scope, prescopedClass)).toMatchSnapshot();
expect(classy(scope, prescopedClass)).toMatchSnapshot();
});
});

describe("BEM “Partials” Expansion", () => {
const bem = new Classy({
const bem = new classy({
bem: "RootElem",
});

Expand All @@ -64,29 +64,29 @@ describe("Classy", () => {
expect(bem("_mod")).toBe("RootElem_mod");
});

it("add custom BEM partials via the `SEPARATORS` export", () => {
SEPARATORS.push('@')
it("add custom BEM partials via the `CLASSY_SEPARATORS` export", () => {
CLASSY_SEPARATORS.push('@')
expect(bem("@customBEMPartial")).toBe("RootElem@customBEMPartial");
});
});

describe("Classy Instances", () => {
it("can be created with the `new` keyword", () => {
const bem1 = new Classy(mockScope);
const bem2 = new Classy({ classes: mockScope });
const bem1 = new classy(mockScope);
const bem2 = new classy({ classes: mockScope });
expect(bem1("RootElem")).toBe("bPDD5MZYqy37J8a5Ed");
expect(bem2("RootElem")).toBe("bPDD5MZYqy37J8a5Ed");
});
it("accepts a single object of scoped `classes` and/or a `bem` namespace", () => {
const bem1 = new Classy({ ...mockScope, bem: "RootElem" });
const bem2 = new Classy({ classes: mockScope, bem: "RootElem" });
const bem1 = new classy({ ...mockScope, bem: "RootElem" });
const bem2 = new classy({ classes: mockScope, bem: "RootElem" });
expect(bem1("&")).toBe("bPDD5MZYqy37J8a5Ed");
expect(bem2("&")).toBe("bPDD5MZYqy37J8a5Ed");
});
it("accepts a BEM namespace and/or a module scope as two params (in either order!)", () => {
const bem0 = new Classy("RootElem");
const bem1 = new Classy(mockScope, "RootElem");
const bem2 = new Classy("RootElem", mockScope);
const bem0 = new classy("RootElem");
const bem1 = new classy(mockScope, "RootElem");
const bem2 = new classy("RootElem", mockScope);
expect(bem0("&")).toBe("RootElem");
expect(bem1("&")).toBe("bPDD5MZYqy37J8a5Ed");
expect(bem2("&")).toBe("bPDD5MZYqy37J8a5Ed");
Expand Down
6 changes: 3 additions & 3 deletions src/classy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import isObject from "lodash/isPlainObject";
import flat from "lodash/flattenDeep";

export const SEPARATORS = ["-", "_"];
export const CLASSY_SEPARATORS = ["-", "_"];

const splitClassStrings = (classes) =>
flat(
Expand All @@ -23,7 +23,7 @@ const expandBEMPartials = (classname, namespace) => {
/* Prefix BEM separator "partials"
* with the BEM namespace...
*/
if (SEPARATORS.includes(classname[0])) {
if (CLASSY_SEPARATORS.includes(classname[0])) {
if (!classname.includes("-scss")) return `${namespace}${classname}`;
}

Expand Down Expand Up @@ -86,6 +86,6 @@ export function classy(...args) {
.join(" ");
}

classy.SEPARATORS = SEPARATORS;
classy.SEPARATORS = CLASSY_SEPARATORS;

export default classy;
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
export { classy, SEPARATORS } from "./classy";
export { useClassy } from "./useClassy";
export {
classy,
classy as default,
CLASSY_SEPARATORS,
CLASSY_SEPARATORS as SEPARATORS, // deprecated
} from "./classy";

export { useClassy, CLASSY_PROPTYPE } from "./useClassy";

0 comments on commit 7ae8d14

Please sign in to comment.