Pads `string` on the left and right sides if it's shorter than `length`. Padding characters are truncated if they can't be evenly divided by `length`.
pad('abc', 8)
// => ' abc '
pad('abc', 8, '_-')
// => '_-abc_-_'
pad('abc', 3)
// => 'abc'
Name | Type | Attribute | Description |
---|---|---|---|
string | The string to pad. | ||
length | The padding length. | ||
chars | The string used as padding. |
{ "comment": "/**\r\n * Pads `string` on the left and right sides if it's shorter than `length`.\r\n * Padding characters are truncated if they can't be evenly divided by `length`.\r\n *\r\n * @since 3.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 * pad('abc', 8)\r\n * // => ' abc '\r\n *\r\n * pad('abc', 8, '_-')\r\n * // => '_-abc_-_'\r\n *\r\n * pad('abc', 3)\r\n * // => 'abc'\r\n */", "meta": { "range": [ 677, 993 ], "filename": "pad.js", "lineno": 25, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100006740", "name": "pad", "type": "FunctionDeclaration", "paramnames": [ "string", "length", "chars" ] }, "vars": { "strLength": "pad~strLength", "mid": "pad~mid" } }, "description": "Pads `string` on the left and right sides if it's shorter than `length`.\rPadding characters are truncated if they can't be evenly divided by `length`.", "since": "3.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": [ "pad('abc', 8)\r// => ' abc '\r\rpad('abc', 8, '_-')\r// => '_-abc_-_'\r\rpad('abc', 3)\r// => 'abc'" ], "name": "pad", "longname": "pad", "kind": "function", "scope": "global", "___id": "T000002R000626", "___s": true, "filepath": "pad.js" }