-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrii Kirmas
committed
Mar 10, 2021
1 parent
599e9b8
commit 1a47d01
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare namespace Bem { | ||
interface Options { | ||
$default: { | ||
elementDelimiter: "__" | ||
modDelimiter: "--" | ||
blockModKey: "$" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// <reference path="./config-types.d.ts"/> | ||
|
||
export {} | ||
|
||
const options = { | ||
current: { | ||
elementDelimiter: "__" as const, | ||
modDelimiter: "--" as const, | ||
blockModKey: "$" as const, | ||
} | ||
} | ||
|
||
|
||
export { | ||
setOpts, getOpts | ||
} | ||
|
||
function setOpts<e extends string, m extends string, b extends string>( | ||
elementDelimiter: e, | ||
modDelimiter: m, | ||
blockModKey: b | ||
) { | ||
const current = { | ||
elementDelimiter, | ||
modDelimiter, | ||
blockModKey | ||
} | ||
|
||
//@ts-expect-error | ||
options.current = current | ||
} | ||
|
||
function getOpts() { | ||
return options.current as { | ||
elementDelimiter: "elementDelimiter" extends keyof Bem.Options | ||
? Bem.Options["elementDelimiter"] | ||
: Bem.Options["$default"]["elementDelimiter"] | ||
modDelimiter: "modDelimiter" extends keyof Bem.Options | ||
? Bem.Options["modDelimiter"] | ||
: Bem.Options["$default"]["modDelimiter"] | ||
blockModKey: | ||
"blockModKey" extends keyof Bem.Options | ||
? Bem.Options["blockModKey"] | ||
: Bem.Options["$default"]["blockModKey"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare namespace Bem { | ||
interface Options { | ||
elementDelimiter: "_" | ||
modDelimiter: "-" | ||
blockModKey: "&" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// <reference path="./set-config.d.ts" /> | ||
|
||
import { setOpts, getOpts} from "./config"; | ||
|
||
setOpts( | ||
"_" as const, | ||
"-" as const, | ||
"&" as const | ||
) | ||
|
||
const x = getOpts().blockModKey | ||
, check: typeof x extends "&" ? true : false = true | ||
|
||
export {x, check} |