I want to ensure that I get a minimum length of 2 otherwise it should be filled with " ". For example:
let string = " "
string.unknownMethod("a")
What function do I need in place of unknown method to get this output " a". But if string.unknownMethod("ab") the output should be "ab"
If what you want is to ensure that you get a string with a minimum length of 2 characters and, otherwise, get it filled with leading spaces, it's easier if you reverse your current logic:
console.log("".padStart(2, '-'));
console.log("a".padStart(2, '-'));
console.log("ab".padStart(2, '-'));
console.log("abc".padStart(2, '-'));
Spaces replaced with - for visibility.
Otherwise, you need to mess with substring offsets or regular expressions. It's doable but not as immediate.