Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'.'.padEnd is not a function. #3

Open
PsChina opened this issue Jul 16, 2020 · 1 comment
Open

'.'.padEnd is not a function. #3

PsChina opened this issue Jul 16, 2020 · 1 comment

Comments

@PsChina
Copy link
Owner

PsChina commented Jul 16, 2020

'.'.padEnd is not a function.

@PsChina
Copy link
Owner Author

PsChina commented Jul 16, 2020

Create a file and paste the following content into the file and import it into the project entry file.

const RequireObjectCoercible = O => {
    if (O === null || typeof O === 'undefined') {
        throw new TypeError('"this" value must not be null or undefined');
    }
    return O;
};
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
const ToLength = argument => {
    const len = Number(argument);
    if (Number.isNaN(len) || len <= 0) { return 0; }
    if (len > MAX_SAFE_INTEGER) { return MAX_SAFE_INTEGER; }
    return len;
};

if (!String.prototype.padStart) {
    String.prototype.padStart = function padStart(maxLength, fillString = ' ') {
        const O = RequireObjectCoercible(this);
        const S = String(O);
        const intMaxLength = ToLength(maxLength);
        const stringLength = ToLength(S.length);
        if (intMaxLength <= stringLength) { return S; }
        let filler = typeof fillString === 'undefined' ? ' ' : String(fillString);
        if (filler === '') { return S; }
        const fillLen = intMaxLength - stringLength;
        while (filler.length < fillLen) {
            const fLen = filler.length;
            const remainingCodeUnits = fillLen - fLen;
            if (fLen > remainingCodeUnits) {
                filler += filler.slice(0, remainingCodeUnits);
            } else {
                filler += filler;
            }
        }
        const truncatedStringFiller = filler.slice(0, fillLen);
        return truncatedStringFiller + S;
    };
}

if (!String.prototype.padEnd) {
    String.prototype.padEnd = function padEnd(maxLength, fillString = ' ') {
        const O = RequireObjectCoercible(this);
        const S = String(O);
        const intMaxLength = ToLength(maxLength);
        const stringLength = ToLength(S.length);
        if (intMaxLength <= stringLength) { return S; }
        let filler = typeof fillString === 'undefined' ? ' ' : String(fillString);
        if (filler === '') { return S; }
        const fillLen = intMaxLength - stringLength;
        while (filler.length < fillLen) {
            const fLen = filler.length;
            const remainingCodeUnits = fillLen - fLen;
            if (fLen > remainingCodeUnits) {
                filler += filler.slice(0, remainingCodeUnits);
            } else {
                filler += filler;
            }
        }
        const truncatedStringFiller = filler.slice(0, fillLen);
        return S + truncatedStringFiller;
    };
}

@PsChina PsChina closed this as completed Jul 16, 2020
@PsChina PsChina changed the title '.'padEnd is not a function. '.'.padEnd is not a function. Jul 16, 2020
@PsChina PsChina reopened this Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant