-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
5141713
commit 1560386
Showing
10 changed files
with
210 additions
and
37 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,2 @@ | ||
import { json2vdf } from './json2vdf' | ||
export { json2vdf } |
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,81 @@ | ||
/************************************************************* | ||
* | ||
* FUNKY KEY VALUES | ||
* | ||
* json2vdf() | ||
* Takes a JSON object and spits out a VDF string | ||
* | ||
************************************************************/ | ||
|
||
type VdfFormattingOptions = { | ||
indentValues: boolean | ||
watermark: boolean | ||
arrayIndexingName?: string | ||
} | ||
|
||
const defaultVdfFormattingOptions: VdfFormattingOptions = { | ||
indentValues: false, | ||
watermark: false, | ||
arrayIndexingName: 'file' | ||
} | ||
|
||
export function json2vdf(json: Object, rootName: string, options?: Partial<VdfFormattingOptions>) { | ||
const opts = { ...defaultVdfFormattingOptions, ...options } as VdfFormattingOptions | ||
|
||
let output = '// File generated by funky\n\n' | ||
|
||
function vdfIndent(level: number) { | ||
return '\t'.repeat(level) | ||
} | ||
|
||
function print(level: number, str: string) { | ||
output += vdfIndent(level) + str + '\n' | ||
} | ||
|
||
output += `"${rootName}"\n{\n` | ||
|
||
function recursivelySerialize(obj: Object, depth: number = 1) { | ||
for (const key in obj) { | ||
const value = obj[key] | ||
|
||
if (typeof value === 'object') { | ||
output += vdfIndent(depth) + `"${key}"` + '\n' | ||
output += vdfIndent(depth) + '{\n' | ||
recursivelySerialize(value, depth + 1) | ||
output += vdfIndent(depth) + '}\n' | ||
|
||
// TODO: Add support for array indexing | ||
} else { | ||
let formattedValue = value | ||
|
||
switch (typeof value) { | ||
case 'string': | ||
break | ||
|
||
case 'number': | ||
formattedValue = value.toString() | ||
break | ||
|
||
case 'boolean': | ||
formattedValue = value ? 'true' : 'false' | ||
break | ||
|
||
default: | ||
console.error(`[FKV json2vdf] Unsupported value type: ${typeof value}`) | ||
formattedValue = 'undefined' | ||
break | ||
} | ||
|
||
let spacingMethod = opts.indentValues ? '\t' : ' ' | ||
output += `${vdfIndent(depth)}"${key}"${spacingMethod}"${formattedValue}"\n` | ||
} | ||
} | ||
} | ||
|
||
recursivelySerialize(json) | ||
|
||
// Close the root object | ||
output += '}\n' | ||
|
||
return output | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/renderer/src/features/settings/components/SettingsDropdown.svelte
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 @@ | ||
<script lang="ts"> | ||
export let value: unknown | ||
export let options: { | ||
label: string | ||
value: string | ||
}[] | ||
</script> | ||
|
||
<select bind:value class="select !bg-surface-500 indent-2 w-auto min-w-[186px]"> | ||
{#each options as option} | ||
<option value={option.value}>{option.label}</option> | ||
{/each} | ||
</select> |
14 changes: 14 additions & 0 deletions
14
src/renderer/src/features/settings/components/SettingsPaper.svelte
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 @@ | ||
<script lang="ts"> | ||
export let label: string | ||
</script> | ||
|
||
<div class="flex items-center justify-between gap-4 p-3 bg-surface-700 rounded-lg"> | ||
<div> | ||
<span class="text-base">{label}</span> | ||
<p class="text-xs opacity-60 mt-1 max-w-[420px]"> | ||
<slot name="description" /> | ||
</p> | ||
</div> | ||
|
||
<slot name="main" /> | ||
</div> |
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