Skip to content

Commit

Permalink
fix(yaml): speciously restrictive type for stringify()
Browse files Browse the repository at this point in the history
  • Loading branch information
hudlow committed Mar 20, 2024
1 parent 198c7af commit 9217fa8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions yaml/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export type DumpOptions = DumperStateOptions;
* You can disable exceptions by setting the skipInvalid option to true.
*/
export function stringify(
obj: Record<string, unknown>,
data: unknown,
options?: DumpOptions,
): string {
return dump(obj, options);
return dump(data, options);
}
44 changes: 44 additions & 0 deletions yaml/stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,50 @@ binary: !<tag:yaml.org,2002:binary> SGVsbG8=
},
});

Deno.test({
name: "arrays can be stringified directly",
fn() {
const array = [1, 2, 3]

const expected = "- 1\n- 2\n- 3\n";

assertEquals(stringify(array), expected);
},
});

Deno.test({
name: "strings can be stringified directly",
fn() {
const string = 'Hello world';

const expected = 'Hello world\n';

assertEquals(stringify(string), expected);
},
});

Deno.test({
name: "numbers can be stringified directly",
fn() {
const number = 1.01;

const expected = "1.01\n";

assertEquals(stringify(number), expected);
},
});

Deno.test({
name: "booleans can be stringified directly",
fn() {
const boolean = true;

const expected = "true\n";

assertEquals(stringify(boolean), expected);
},
});

Deno.test({
name: "stringify() throws with `!!js/*` yaml types with default schemas",
fn() {
Expand Down

0 comments on commit 9217fa8

Please sign in to comment.