Skip to content

Commit

Permalink
Add prefix config
Browse files Browse the repository at this point in the history
  • Loading branch information
magicismight committed Aug 12, 2021
1 parent 2f6ef3d commit 54cb190
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import { configure, DefaultBEMDelimiters } from 'bem-composer';

// Configure BEM constructor with custom delimiters.
const cbem = configure({
prefix: 'bem-',
element: '__',
modifier: '~~',
modifierValue: '~'
Expand All @@ -98,7 +99,7 @@ console.log(
name: 'active',
value: 'hover'
}).toString()
); // block__icon~~active~hover
); // bem-block__icon~~active~hover
```

## Curried API
Expand Down
2 changes: 2 additions & 0 deletions src/bem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe('curried api', () => {

describe('custom delimiters', () => {
const cbem = configure({
prefix: 'bem-',
element: '__',
modifier: '~~',
modifierValue: '~'
Expand All @@ -271,6 +272,7 @@ describe('custom delimiters', () => {
}).toString()
).toBe(
[
'bem-',
BlockName,
'__',
ElementName,
Expand Down
1 change: 1 addition & 0 deletions src/bem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { block } from './block';

export const DefaultBEMDelimiters: BEMDelimiters = {
prefix: '',
element: '--',
modifier: '__',
modifierValue: '-'
Expand Down
2 changes: 1 addition & 1 deletion src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function block(name: string, delimiters: BEMDelimiters): BEMBlock {
}

const toString = (): string => {
return name;
return delimiters.prefix + name;
};

const toSelector = (): string => {
Expand Down
4 changes: 3 additions & 1 deletion src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function element(
}

const toString = (): string => {
return name ? blockName + delimiters.element + name : blockName;
return delimiters.prefix + name
? blockName + delimiters.element + name
: blockName;
};

const toSelector = (): string => {
Expand Down
1 change: 1 addition & 0 deletions src/modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function modifier(

const toString = (): string => {
return (
delimiters.prefix +
blockName +
(elementName ? delimiters.element + elementName : '') +
(modifierString ? delimiters.modifier + modifierString : '')
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface BEMDelimiters {
prefix: string;
element: string;
modifier: string;
modifierValue: string;
Expand Down

0 comments on commit 54cb190

Please sign in to comment.