import { Document } from "./document.ts"; import type { Options } from "./options.ts"; /** * update an fJSON object document's properties in place * without clobbering commits or key ordering. * * overrides are plain objects and get applied left-to-right. * you may use explicit `undefined` to remove a property: * * ```ts * import { apply } from "./mod.ts"; * * apply("x: 0, y: { a: 1, b: 2 }", { y: { c: 3 } }); * // => "x: 0, y: { a: 1, b: 2, c: 3 }" * * apply("x: 0, y: { a: 1, b: 2 }", { y: undefined }, { y: { c: 3 } }); * // => "x: 0, y: { c: 3 }" * ``` * * invalid overrides throw `TypeError`; * nesting beyond the limit throws `RangeError` (see {@linkcode applyWith}) */ export function apply( source: string, ...overrides: unknown[] ): string { return applyWith(source, undefined, ...overrides); } /** * like {@linkcode apply}, * but the nesting limit is configurable in `options` */ export function applyWith( source: string, options: Options | undefined, ...overrides: unknown[] ): string { const document = Document.parseObject(source, options); document.apply(...overrides); return document.source; }