Skip to content

Commit

Permalink
BREAKING(yaml): rename StringifyOptions.noRefs to `StringifyOptions…
Browse files Browse the repository at this point in the history
….useAnchors` (#5288)
  • Loading branch information
iuioiua committed Jul 5, 2024
1 parent 6d16b81 commit b927e8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions yaml/_dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ export interface DumperStateOptions {
/** set max line width. (default: 80) */
lineWidth?: number;
/**
* if true, don't convert duplicate objects
* into references (default: false)
* if false, don't convert duplicate objects
* into references (default: true)
*/
noRefs?: boolean;
useAnchors?: boolean;
/**
* if false don't try to be compatible with older yaml versions.
* Currently: don't quote "yes", "no" and so on,
Expand All @@ -155,7 +155,7 @@ export class DumperState {
flowLevel: number;
sortKeys: boolean | ((a: Any, b: Any) => number);
lineWidth: number;
noRefs: boolean;
useAnchors: boolean;
compatMode: boolean;
condenseFlow: boolean;
implicitTypes: Type[];
Expand All @@ -176,7 +176,7 @@ export class DumperState {
styles = null,
sortKeys = false,
lineWidth = 80,
noRefs = false,
useAnchors = true,
compatMode = true,
condenseFlow = false,
}: DumperStateOptions) {
Expand All @@ -188,7 +188,7 @@ export class DumperState {
this.styleMap = compileStyleMap(styles);
this.sortKeys = sortKeys;
this.lineWidth = lineWidth;
this.noRefs = noRefs;
this.useAnchors = useAnchors;
this.compatMode = compatMode;
this.condenseFlow = condenseFlow;
this.implicitTypes = this.schema.compiledImplicit;
Expand Down Expand Up @@ -917,7 +917,7 @@ function getDuplicateReferences(
export function dump(input: Any, options: DumperStateOptions = {}): string {
const state = new DumperState(options);

if (!state.noRefs) getDuplicateReferences(input, state);
if (state.useAnchors) getDuplicateReferences(input, state);

if (writeNode(state, 0, input, true, true)) return `${state.dump}\n`;

Expand Down
6 changes: 3 additions & 3 deletions yaml/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export type StringifyOptions = {
/** Set max line width. (default: 80) */
lineWidth?: number;
/**
* If true, don't convert duplicate objects
* into references (default: false)
* If false, don't convert duplicate objects
* into references (default: true)
*/
noRefs?: boolean;
useAnchors?: boolean;
/**
* If false don't try to be compatible with older yaml versions.
* Currently: don't quote "yes", "no" and so on,
Expand Down
6 changes: 3 additions & 3 deletions yaml/stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ Deno.test({
});

Deno.test({
name: "stringify() works with noRefs option",
name: "stringify() works with useAnchors option",
fn() {
const obj = { foo: "bar" };
assertEquals(
stringify([obj, obj], { noRefs: true }),
stringify([obj, obj], { useAnchors: false }),
`- foo: bar\n- foo: bar\n`,
);
assertEquals(
stringify([obj, obj], { noRefs: false }),
stringify([obj, obj], { useAnchors: true }),
`- &ref_0\n foo: bar\n- *ref_0\n`,
);
},
Expand Down

0 comments on commit b927e8c

Please sign in to comment.