diff --git a/packages/strings/src/pad-left.ts b/packages/strings/src/pad-left.ts index d0d0ff2417..ce21563659 100644 --- a/packages/strings/src/pad-left.ts +++ b/packages/strings/src/pad-left.ts @@ -9,16 +9,18 @@ import { repeat } from "./repeat"; export const padLeft: ( n: number, ch?: string | number -) => Stringer = memoizeJ< +) => (x: any, length?: number) => string = memoizeJ< number, string | number | undefined, Stringer >((n, ch = " ") => { const buf = repeat(String(ch), n); - return (x: any) => - x != null - ? ((x = x.toString()), x.length < n ? buf.substr(x.length) + x : x) - : buf; + return (x: any, len?: number) => { + if (x == null) return buf; + x = x.toString(); + len = len !== undefined ? len : x.length; + return len! < n ? buf.substr(len!) + x : x; + }; }); /** diff --git a/packages/strings/src/pad-right.ts b/packages/strings/src/pad-right.ts index 4dac93af60..cbf65e18d6 100644 --- a/packages/strings/src/pad-right.ts +++ b/packages/strings/src/pad-right.ts @@ -9,14 +9,16 @@ import { repeat } from "./repeat"; export const padRight: ( n: number, ch?: string | number -) => Stringer = memoizeJ< +) => (x: any, length?: number) => string = memoizeJ< number, string | number | undefined, Stringer >((n, ch = " ") => { const buf = repeat(String(ch), n); - return (x: any) => - x != null - ? ((x = x.toString()), x.length < n ? x + buf.substr(x.length) : x) - : buf; + return (x, len?: number) => { + if (x == null) return buf; + x = x.toString(); + len = len !== undefined ? len : x.length; + return len! < n ? x + buf.substr(len!) : x; + }; });