How to use the jsonc-parser.applyEdits function in jsonc-parser

To help you get started, we’ve selected a few jsonc-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github njpanderson / push / src / Service / ServiceSettings / index.js View on Github external
).then((env) => {
				if (env === undefined || env.label === '') {
					return;
				}

				try {
					// Modify JSON document & Write changes
					settings.newContents = jsonc.applyEdits(
						settings.contents,
						jsonc.modify(
							settings.contents,
							['env'],
							env.label,
							{
								formattingOptions: {
									tabSize: 4
								}
							}
						)
					);

					// Write back to the file
					fs.writeFileSync(
						this.paths.getNormalPath(settings.uri),
github dzsquared / query-editor-boost / src / vscode-snippet-creator / SnippetsManager.ts View on Github external
var edit = jsonc.modify(jsonText, [snippet.name],
				{
					prefix: snippet.prefix,
					body: snippet.body,
					description: snippet.description
				},
				{
					formattingOptions: { // based on default vscode snippet format
						tabSize: 2,
						insertSpaces: false,
						eol: ''
					}
				});

			var fileContent = jsonc.applyEdits(jsonText, edit);
			fs.writeFile(snippetFile, fileContent, () => { });
			vscode.window.showInformationMessage("Snippet " + snippet.name + " added to " + snippet.language + " snippets");
		});
	}
github neoclide / coc.nvim / src / configuration / shape.ts View on Github external
private async modifyConfiguration(target: ConfigurationTarget, key: string, value?: any): Promise {
    let { nvim, workspace } = this
    let file = workspace.getConfigFile(target)
    if (!file) return
    let formattingOptions: FormattingOptions = { tabSize: 2, insertSpaces: true }
    let content = fs.readFileSync(file, 'utf8')
    value = value == null ? undefined : value
    let edits = modify(content, [key], value, { formattingOptions })
    content = applyEdits(content, edits)
    fs.writeFileSync(file, content, 'utf8')
    let doc = workspace.getDocument(URI.file(file).toString())
    if (doc) nvim.command('checktime', true)
    return
  }
github aws / aws-toolkit-vscode / src / lambda / config / templates.ts View on Github external
const allowedTypesSet = new Set(allowedTypes)

        if (node && !allowedTypesSet.has(node.type)) {
            throw new TemplatesConfigFieldTypeError({
                message: 'Invalid configuration',
                jsonPath: jsonPath,
                actualType: node.type,
                expectedTypes: allowedTypes
            })
        }

        if (!node || node.type === 'null') {
            const edits = jsonParser.modify(this.json, jsonPath, value, this.modificationOptions)

            if (edits.length > 0) {
                this.json = jsonParser.applyEdits(this.json, edits)
                this.isDirty = true
            }
        }
    }
github Bearer / bearer-js / packages / cli / src / commands / setup / auth.ts View on Github external
private persistSetup(config: contexts.OAuth2 | contexts.OAuth1 | contexts.ApiKey | contexts.Basic) {
    const setupRc = this.locator.localConfigPath
    if (!fs.existsSync(setupRc)) {
      fs.writeFileSync(setupRc, '{}', { encoding: 'utf8' })
    }
    const rawSetup = fs.readFileSync(setupRc, { encoding: 'utf8' })
    const updates = modify(rawSetup, ['setup', 'auth'], config, {
      formattingOptions: {
        insertSpaces: true,
        tabSize: 2,
        eol: '\n'
      }
    })
    const newSetupRc = applyEdits(rawSetup, updates)
    this.debug('Writing setup config\n%j', { config, setupRc: newSetupRc })
    fs.writeFileSync(setupRc, newSetupRc, { encoding: 'utf8' })
    this.success(`Auth credentials have been saved to ${this.locator.toRelative(setupRc)}`)
  }