-
-
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.
feat: experimental support for TOML v1.1 (#163)
* WIP support for TOML v1.1 * update * update * Create rude-pots-leave.md * add tests * support for new escapes * support other unicode key * update test case * support for omit seconds * support for new inline-table * update doc * Update rude-pots-leave.md * refactor * update * update * fix * support for comment char * update
- Loading branch information
Showing
1,407 changed files
with
517,434 additions
and
331 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,5 @@ | ||
--- | ||
"toml-eslint-parser": minor | ||
--- | ||
|
||
feat: experimental support for TOML v1.1 |
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
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 |
---|---|---|
@@ -1,3 +1,54 @@ | ||
export type TOMLVersionOption = | ||
| "1.0" | ||
| "1.1" | ||
| "1.0.0" | ||
| "1.1.0" | ||
| "latest" | ||
| "next"; | ||
export interface TOMLVer { | ||
lt(major: number, minor: number): boolean; | ||
// lte(major:number,minor:number): boolean; | ||
// gt(major:number,minor:number): boolean; | ||
gte(major: number, minor: number): boolean; | ||
// eq(major:number,minor:number): boolean; | ||
} | ||
class TOMLVerImpl implements TOMLVer { | ||
private readonly major: number; | ||
|
||
private readonly minor: number; | ||
|
||
public constructor(major: number, minor: number) { | ||
this.major = major; | ||
this.minor = minor; | ||
} | ||
|
||
public lt(major: number, minor: number): boolean { | ||
return this.major < major || (this.major === major && this.minor < minor); | ||
} | ||
|
||
public gte(major: number, minor: number): boolean { | ||
return this.major > major || (this.major === major && this.minor >= minor); | ||
} | ||
} | ||
const TOML_VERSION_1_0 = new TOMLVerImpl(1, 0); | ||
const TOML_VERSION_1_1 = new TOMLVerImpl(1, 1); | ||
const DEFAULT_TOML_VERSION: TOMLVer = TOML_VERSION_1_0; | ||
const SUPPORTED_TOML_VERSIONS: Record<TOMLVersionOption, TOMLVer> = { | ||
"1.0": TOML_VERSION_1_0, | ||
"1.0.0": TOML_VERSION_1_0, | ||
"1.1": TOML_VERSION_1_1, | ||
"1.1.0": TOML_VERSION_1_1, | ||
latest: TOML_VERSION_1_0, | ||
next: TOML_VERSION_1_1, | ||
}; | ||
export interface ParserOptions { | ||
filePath?: string; | ||
tomlVersion?: TOMLVersionOption; | ||
} | ||
|
||
/** | ||
* Get TOML version object from given TOML version string. | ||
*/ | ||
export function getTOMLVer(v: TOMLVersionOption | undefined | null): TOMLVer { | ||
return SUPPORTED_TOML_VERSIONS[v || "latest"] || DEFAULT_TOML_VERSION; | ||
} |
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
Oops, something went wrong.