mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(std/encoding/toml): Add boolean support to stringify (#6941)
This commit is contained in:
parent
5fc5e7b54a
commit
40ead6cc98
2 changed files with 10 additions and 0 deletions
|
@ -471,6 +471,8 @@ class Dumper {
|
||||||
out.push(this._strDeclaration([prop], value.toString()));
|
out.push(this._strDeclaration([prop], value.toString()));
|
||||||
} else if (typeof value === "number") {
|
} else if (typeof value === "number") {
|
||||||
out.push(this._numberDeclaration([prop], value));
|
out.push(this._numberDeclaration([prop], value));
|
||||||
|
} else if (typeof value === "boolean") {
|
||||||
|
out.push(this._boolDeclaration([prop], value));
|
||||||
} else if (
|
} else if (
|
||||||
value instanceof Array &&
|
value instanceof Array &&
|
||||||
this._isSimplySerializable(value[0])
|
this._isSimplySerializable(value[0])
|
||||||
|
@ -504,6 +506,7 @@ class Dumper {
|
||||||
return (
|
return (
|
||||||
typeof value === "string" ||
|
typeof value === "string" ||
|
||||||
typeof value === "number" ||
|
typeof value === "number" ||
|
||||||
|
typeof value === "boolean" ||
|
||||||
value instanceof RegExp ||
|
value instanceof RegExp ||
|
||||||
value instanceof Date ||
|
value instanceof Date ||
|
||||||
value instanceof Array
|
value instanceof Array
|
||||||
|
@ -538,6 +541,9 @@ class Dumper {
|
||||||
return `${this._declaration(keys)}${value}`;
|
return `${this._declaration(keys)}${value}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_boolDeclaration(keys: string[], value: boolean): string {
|
||||||
|
return `${this._declaration(keys)}${value}`;
|
||||||
|
}
|
||||||
_dateDeclaration(keys: string[], value: Date): string {
|
_dateDeclaration(keys: string[], value: Date): string {
|
||||||
function dtPad(v: string, lPad = 2): string {
|
function dtPad(v: string, lPad = 2): string {
|
||||||
return v.padStart(lPad, "0");
|
return v.padStart(lPad, "0");
|
||||||
|
|
|
@ -349,6 +349,8 @@ Deno.test({
|
||||||
[1, 2],
|
[1, 2],
|
||||||
],
|
],
|
||||||
hosts: ["alpha", "omega"],
|
hosts: ["alpha", "omega"],
|
||||||
|
bool: true,
|
||||||
|
bool2: false,
|
||||||
};
|
};
|
||||||
const expected = `deno = "is"
|
const expected = `deno = "is"
|
||||||
not = "[node]"
|
not = "[node]"
|
||||||
|
@ -383,6 +385,8 @@ sf5 = NaN
|
||||||
sf6 = NaN
|
sf6 = NaN
|
||||||
data = [["gamma","delta"],[1,2]]
|
data = [["gamma","delta"],[1,2]]
|
||||||
hosts = ["alpha","omega"]
|
hosts = ["alpha","omega"]
|
||||||
|
bool = true
|
||||||
|
bool2 = false
|
||||||
|
|
||||||
[foo]
|
[foo]
|
||||||
bar = "deno"
|
bar = "deno"
|
||||||
|
|
Loading…
Reference in a new issue