-
-
Notifications
You must be signed in to change notification settings - Fork 27
Adding yaml support #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b4aaef5
00cf7d0
10be2bf
cfc77c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import YAML from 'yaml'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: This might be unused | ||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {String | Number | Null | Boolean} value The input number | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -14,14 +16,50 @@ export function isWholeNumber(value: string | number | null | undefined): boolea | |||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {String} string The JSON stringified object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return {Boolean} Returns true if the input string is parse-able | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {String} string The YAML stringified object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {Boolean} logError A boolean that determines if the function should log a caught error to console | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return {Boolean} Returns true if the input string is parse-able | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export function isJsonString(string: string): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export function isYamlString(string: string, logError:boolean = true): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| JSON.parse(string); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| YAML.parse(string); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (logError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Failed parsing .nsprc file: ' + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw e; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |
| } | |
| return false; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic incorrectly determines if content is YAML. The expression isYamlString(string, false) || isJsonString(string, false) assigns the result of the OR operation to isYaml, but since valid JSON is also valid YAML, isYamlString will return true for JSON content, making isYaml always true when either format is valid. This defeats the purpose of distinguishing between formats. Consider checking JSON first, then YAML only if JSON fails.
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type Array<boolean> is unclear and error-prone. Consider using a more descriptive return type such as an object with named properties like { isValid: boolean, isYaml: boolean } or a tuple type [isValid: boolean, isYaml: boolean] to make the API more self-documenting.
| * @return {Array<Boolean>} The first boolean determines if the input string was valid, the second if it is yaml or not | |
| */ | |
| export function getValidStatusAndType(string: string): Array<boolean> { | |
| let isYaml = false; | |
| try { | |
| if ((isYaml = isYamlString(string, false) || isJsonString(string, false))) { | |
| return [true, isYaml]; | |
| } | |
| } catch (e) { | |
| console.log('Failed parsing .nsprc file: ' + e); | |
| } | |
| return [false, false]; | |
| * @return {{ isValid: boolean, isYaml: boolean }} An object where `isValid` indicates if the string was parse-able, and `isYaml` indicates if it is YAML or not | |
| */ | |
| export function getValidStatusAndType(string: string): { isValid: boolean; isYaml: boolean } { | |
| let isYaml = false; | |
| try { | |
| if ((isYaml = isYamlString(string, false) || isJsonString(string, false))) { | |
| return { isValid: true, isYaml }; | |
| } | |
| } catch (e) { | |
| console.log('Failed parsing .nsprc file: ' + e); | |
| } | |
| return { isValid: false, isYaml: false }; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after colon in parameter type annotation. Should be logError: boolean for consistency with TypeScript style conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after colon in parameter type annotation. Should be
logError: booleanfor consistency with TypeScript style conventions.