From 40ead6cc98ab1d02c8ca0587d24c218e81aa47b7 Mon Sep 17 00:00:00 2001 From: Rauf Islam <31735267+ItsRauf@users.noreply.github.com> Date: Mon, 3 Aug 2020 18:17:31 -0400 Subject: [PATCH] fix(std/encoding/toml): Add boolean support to stringify (#6941) --- std/encoding/toml.ts | 6 ++++++ std/encoding/toml_test.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts index 336af97fb2..bd6814ac30 100644 --- a/std/encoding/toml.ts +++ b/std/encoding/toml.ts @@ -471,6 +471,8 @@ class Dumper { out.push(this._strDeclaration([prop], value.toString())); } else if (typeof value === "number") { out.push(this._numberDeclaration([prop], value)); + } else if (typeof value === "boolean") { + out.push(this._boolDeclaration([prop], value)); } else if ( value instanceof Array && this._isSimplySerializable(value[0]) @@ -504,6 +506,7 @@ class Dumper { return ( typeof value === "string" || typeof value === "number" || + typeof value === "boolean" || value instanceof RegExp || value instanceof Date || value instanceof Array @@ -538,6 +541,9 @@ class Dumper { return `${this._declaration(keys)}${value}`; } } + _boolDeclaration(keys: string[], value: boolean): string { + return `${this._declaration(keys)}${value}`; + } _dateDeclaration(keys: string[], value: Date): string { function dtPad(v: string, lPad = 2): string { return v.padStart(lPad, "0"); diff --git a/std/encoding/toml_test.ts b/std/encoding/toml_test.ts index 0a927cde9d..cc3d190b0d 100644 --- a/std/encoding/toml_test.ts +++ b/std/encoding/toml_test.ts @@ -349,6 +349,8 @@ Deno.test({ [1, 2], ], hosts: ["alpha", "omega"], + bool: true, + bool2: false, }; const expected = `deno = "is" not = "[node]" @@ -383,6 +385,8 @@ sf5 = NaN sf6 = NaN data = [["gamma","delta"],[1,2]] hosts = ["alpha","omega"] +bool = true +bool2 = false [foo] bar = "deno"