Skip to content

Commit b22d974

Browse files
author
Andrii Kirmas
committed
#40 Add primitives array support to core function
1 parent ef757ff commit b22d974

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/bem.core.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe(bem2arr.name, () => {
1515
[{base: true }, "base"],
1616
[{base: "mod" }, "base base--mod"],
1717
//@ts-expect-error //TODO #40
18-
[{base: ["mod"] }, "base base--0--mod" /* TODO #40 "base base--mod"*/],
18+
[{base: ["mod"] }, "base base--mod" /* TODO #40 "base base--mod"*/],
1919
//@ts-expect-error //TODO #40
2020
[{base: [false] }, "base"],
2121
[{base: {} }, "base"],

src/bem.core.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { BemInGeneral } from "./bem.types"
22

3+
const {isArray: $isArray} = Array
4+
35
let modDelimiter = "--"
46
, elementDelimiter = "__"
57

@@ -29,12 +31,19 @@ function bem2arr(query: BemInGeneral) {
2931
continue
3032
}
3133

34+
const isArray = $isArray(baseQ)
35+
36+
// TODO check performance of `const in Array`
3237
for (const mod in baseQ) {
3338
const modValue = baseQ[mod]
3439
if (!modValue)
3540
continue
3641

37-
$return.push(`${base}${modDelimiter}${mod}${
42+
$return.push(`${base}${
43+
isArray
44+
? ""
45+
: `${modDelimiter}${mod}`
46+
}${
3847
typeof modValue !== "string"
3948
? ""
4049
: `${modDelimiter}${modValue}`

0 commit comments

Comments
 (0)