How to use the @sqs/jsonc-parser.applyEdits function in @sqs/jsonc-parser

To help you get started, we’ve selected a few @sqs/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 sourcegraph / sourcegraph / browser / src / platform / settings.ts View on Github external
const getNext = (prev: string): string =>
        typeof edit === 'string'
            ? edit
            : applyEdits(
                  prev,
                  // TODO(chris): remove `.slice()` (which guards against mutation) once
                  // https://github.com/Microsoft/node-jsonc-parser/pull/12 is merged in.
                  setProperty(prev, edit.path.slice(), edit.value, {
                      tabSize: 2,
                      insertSpaces: true,
                      eol: '\n',
                  })
              )
    if (isInPage) {
github sourcegraph / sourcegraph / src / settings / MonacoSettingsEditor.tsx View on Github external
run: editor => {
            eventLogger.log('SiteConfigurationActionExecuted', { id })
            editor.focus()
            editor.pushUndoStop()
            const { edits, selectText, cursorOffset } = run(editor.getValue())
            const monacoEdits = toMonacoEdits(model, edits)
            let selection: monaco.Selection | undefined
            if (typeof selectText === 'string') {
                const afterText = jsonc.applyEdits(editor.getValue(), edits)
                let offset = afterText.slice(edits[0].offset).indexOf(selectText)
                if (offset !== -1) {
                    offset += edits[0].offset
                    if (typeof cursorOffset === 'number') {
                        selection = monaco.Selection.fromPositions(
                            getPositionAt(afterText, offset + cursorOffset),
                            getPositionAt(afterText, offset + cursorOffset)
                        )
                    } else {
                        selection = monaco.Selection.fromPositions(
                            getPositionAt(afterText, offset),
                            getPositionAt(afterText, offset + selectText.length)
                        )
                    }
                }
            }
github sourcegraph / sourcegraph / shared / src / e2e / driver.ts View on Github external
export function modifyJSONC(text: string, path: jsonc.JSONPath, f: (oldValue: jsonc.Node | undefined) => any): any {
    const old = jsonc.findNodeAtLocation(jsonc.parseTree(text), path)
    return jsonc.applyEdits(
        text,
        jsoncEdit.setProperty(text, path, f(old), {
            eol: '\n',
            insertSpaces: true,
            tabSize: 2,
        })
    )
}
github sourcegraph / sourcegraph / packages / webapp / src / settings / MonacoSettingsEditor.tsx View on Github external
run: editor => {
            eventLogger.log('SiteConfigurationActionExecuted', { id })
            editor.focus()
            editor.pushUndoStop()
            const { edits, selectText, cursorOffset } = run(editor.getValue())
            const monacoEdits = toMonacoEdits(model, edits)
            let selection: monaco.Selection | undefined
            if (typeof selectText === 'string') {
                const afterText = jsonc.applyEdits(editor.getValue(), edits)
                let offset = afterText.slice(edits[0].offset).indexOf(selectText)
                if (offset !== -1) {
                    offset += edits[0].offset
                    if (typeof cursorOffset === 'number') {
                        selection = monaco.Selection.fromPositions(
                            getPositionAt(afterText, offset + cursorOffset),
                            getPositionAt(afterText, offset + cursorOffset)
                        )
                    } else {
                        selection = monaco.Selection.fromPositions(
                            getPositionAt(afterText, offset),
                            getPositionAt(afterText, offset + selectText.length)
                        )
                    }
                }
            }
github sourcegraph / sourcegraph / web / src / regression / util / helpers.ts View on Github external
export async function editSiteConfig(
    gqlClient: GraphQLClient,
    ...edits: ((contents: string) => jsonc.Edit[])[]
): Promise<{ destroy: ResourceDestructor; result: boolean }> {
    const origConfig = await fetchSiteConfiguration(gqlClient).toPromise()
    let newContents = origConfig.configuration.effectiveContents
    for (const editFn of edits) {
        newContents = jsonc.applyEdits(newContents, editFn(newContents))
    }
    return {
        result: await updateSiteConfiguration(gqlClient, origConfig.configuration.id, newContents).toPromise(),
        destroy: async () => {
            const c = await fetchSiteConfiguration(gqlClient).toPromise()
            await updateSiteConfiguration(
                gqlClient,
                c.configuration.id,
                origConfig.configuration.effectiveContents
            ).toPromise()
        },
    }
}
github sourcegraph / sourcegraph / web / src / enterprise / campaigns / detail / forms.tsx View on Github external
const createChangeHandler = (prop: string) => (event: React.ChangeEvent<{ value: string }>) =>
        onChange(
            jsonc.applyEdits(
                campaignArguments,
                setProperty(campaignArguments, [prop], event.target.value, defaultFormattingOptions)
            )
        )
github sourcegraph / browser-extensions / app / backend / extensions.ts View on Github external
storage.getSync(storageItems => {
                const format = { tabSize: 2, insertSpaces: true, eol: '\n' }
                if (edit) {
                    storageItems.clientSettings = applyEdits(
                        storageItems.clientSettings,
                        setProperty(storageItems.clientSettings, edit.path, edit.value, format)
                    )
                } else if (typeof enabled === 'boolean') {
                    storageItems.clientSettings = applyEdits(
                        storageItems.clientSettings,
                        setProperty(storageItems.clientSettings, ['extensions', extensionID], enabled, format)
                    )
                } else if (remove) {
                    storageItems.clientSettings = applyEdits(
                        storageItems.clientSettings,
                        removeProperty(storageItems.clientSettings, ['extensions', extensionID], format)
                    )
                }
                storage.setSync(storageItems, () => {
                    update.next(undefined)
                })
            })
            return update

@sqs/jsonc-parser

Scanner and parser for JSON with comments.

MIT
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis

Similar packages