1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

used native padStart/End where possible (#4537)

This commit is contained in:
Ondřej Žára 2020-03-31 12:34:13 +02:00 committed by GitHub
parent bdcb926b37
commit a86b07f2df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { pad } from "../strings/pad.ts";
import { assert } from "../testing/asserts.ts";
export type DateFormat = "mm-dd-yyyy" | "dd-mm-yyyy" | "yyyy-mm-dd";
@ -125,7 +124,7 @@ export function currentDayOfYear(): number {
*/
export function toIMF(date: Date): string {
function dtPad(v: string, lPad = 2): string {
return pad(v, lPad, { char: "0" });
return v.padStart(lPad, "0");
}
const d = dtPad(date.getUTCDate().toString());
const h = dtPad(date.getUTCHours().toString());

View file

@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { deepAssign } from "../util/deep_assign.ts";
import { pad } from "../strings/pad.ts";
import { assert } from "../testing/asserts.ts";
class KeyValuePair {
@ -514,7 +513,7 @@ class Dumper {
}
_dateDeclaration(keys: string[], value: Date): string {
function dtPad(v: string, lPad = 2): string {
return pad(v, lPad, { char: "0" });
return v.padStart(lPad, "0");
}
const m = dtPad((value.getUTCMonth() + 1).toString());
const d = dtPad(value.getUTCDate().toString());
@ -542,7 +541,7 @@ class Dumper {
} else {
const m = rDeclaration.exec(l);
if (m) {
out.push(l.replace(m[1], pad(m[1], this.maxPad, { side: "right" })));
out.push(l.replace(m[1], m[1].padEnd(this.maxPad)));
} else {
out.push(l);
}