Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial change to use insertText
- Loading branch information
Showing
2 changed files
with
187 additions
and
28 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,44 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
export function stringifyObject(obj: any, indent: string, stringifyLiteral: (val: any) => string) : string { | ||
if (obj !== null && typeof obj === 'object') { | ||
let newIndent = indent + '\t'; | ||
if (Array.isArray(obj)) { | ||
if (obj.length === 0) { | ||
return '[]'; | ||
} | ||
let result = '[\n'; | ||
for (let i = 0; i < obj.length; i++) { | ||
result += newIndent + stringifyObject(obj[i], newIndent, stringifyLiteral); | ||
if (i < obj.length - 1) { | ||
result += ','; | ||
} | ||
result += '\n'; | ||
} | ||
result += indent + ']'; | ||
return result; | ||
} else { | ||
let keys = Object.keys(obj); | ||
if (keys.length === 0) { | ||
return '{}'; | ||
} | ||
let result = '{\n'; | ||
for (let i = 0; i < keys.length; i++) { | ||
let key = keys[i]; | ||
|
||
result += newIndent + JSON.stringify(key) + ': ' + stringifyObject(obj[key], newIndent, stringifyLiteral); | ||
if (i < keys.length - 1) { | ||
result += ','; | ||
} | ||
result += '\n'; | ||
} | ||
result += indent + '}'; | ||
return result; | ||
} | ||
} | ||
return stringifyLiteral(obj); | ||
} |