-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamically import smol-toml package
- Loading branch information
1 parent
db2c9b0
commit f5e93a1
Showing
3 changed files
with
28 additions
and
3 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
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,25 @@ | ||
/* | ||
* tomlUtils.ts | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
* | ||
* helpers related to TOML | ||
*/ | ||
|
||
type TomlPrimitive = string | number | boolean | { | ||
[key: string]: TomlPrimitive; | ||
} | TomlPrimitive[]; | ||
|
||
// Dynamically load `smol-toml` to address module loading issues and | ||
// maintain existing module resolution to support multiple environments. | ||
let TOML: any; | ||
(async () => { | ||
TOML = await import('smol-toml'); | ||
})(); | ||
|
||
export const parse = (toml: string): Record<string, TomlPrimitive> => { | ||
if (!TOML) { | ||
throw new Error('TOML module not loaded'); | ||
} | ||
return TOML.parse(toml); | ||
}; |
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