Home

function: padStart


padStart(string: string, length: number, chars: string): string

Pads `string` on the left side if it's shorter than `length`. Padding characters are truncated if they exceed `length`.

Example(s):

padStart('abc', 6)
// => '   abc'

padStart('abc', 6, '_-')
// => '_-_abc'

padStart('abc', 3)
// => 'abc'

Params:

Name Type Attribute Description
string The string to pad.
length The padding length.
chars The string used as padding.

Returns:

string

  {
    "comment": "/**\r\n * Pads `string` on the left side if it's shorter than `length`. Padding\r\n * characters are truncated if they exceed `length`.\r\n *\r\n * @since 4.0.0\r\n * @category String\r\n * @param {string} [string=''] The string to pad.\r\n * @param {number} [length=0] The padding length.\r\n * @param {string} [chars=' '] The string used as padding.\r\n * @returns {string} Returns the padded string.\r\n * @example\r\n *\r\n * padStart('abc', 6)\r\n * // => '   abc'\r\n *\r\n * padStart('abc', 6, '_-')\r\n * // => '_-_abc'\r\n *\r\n * padStart('abc', 3)\r\n * // => 'abc'\r\n */",
    "meta": {
        "range": [
            657,
            869
        ],
        "filename": "padStart.js",
        "lineno": 25,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006846",
            "name": "padStart",
            "type": "FunctionDeclaration",
            "paramnames": [
                "string",
                "length",
                "chars"
            ]
        },
        "vars": {
            "strLength": "padStart~strLength"
        }
    },
    "description": "Pads `string` on the left side if it's shorter than `length`. Padding\rcharacters are truncated if they exceed `length`.",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "String",
            "value": "String"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "string"
                ]
            },
            "optional": true,
            "defaultvalue": "''",
            "description": "The string to pad.",
            "name": "string"
        },
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "optional": true,
            "defaultvalue": 0,
            "description": "The padding length.",
            "name": "length"
        },
        {
            "type": {
                "names": [
                    "string"
                ]
            },
            "optional": true,
            "defaultvalue": "' '",
            "description": "The string used as padding.",
            "name": "chars"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "string"
                ]
            },
            "description": "Returns the padded string."
        }
    ],
    "examples": [
        "padStart('abc', 6)\r// => '   abc'\r\rpadStart('abc', 6, '_-')\r// => '_-_abc'\r\rpadStart('abc', 3)\r// => 'abc'"
    ],
    "name": "padStart",
    "longname": "padStart",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000633",
    "___s": true,
    "filepath": "padStart.js"
}