string-padding
Advanced tools
Comparing version 1.0.1 to 1.0.2
11
index.js
var pad = function(input, length, padding, side) { | ||
input = (input || '').toString(); | ||
input = (input || '').toString(); | ||
length = parseInt(length) || 0; | ||
@@ -9,2 +9,11 @@ padding = (padding || '').toString() || ' '; | ||
if( | ||
length === Infinity || // Non-valid length | ||
padding.length === 0 || // Non-valid padding | ||
(side !== pad.LEFT && // Non-valid padding types | ||
side !== pad.RIGHT && | ||
side !== pad.BOTH) | ||
) return input; | ||
while(input.length < length) { | ||
@@ -11,0 +20,0 @@ if( |
{ | ||
"name": "string-padding", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Pad strings/text", | ||
@@ -5,0 +5,0 @@ |
@@ -15,8 +15,10 @@ # String-padding | ||
- **string**: A string of text of any length. | ||
- **length** (optional): The length the output string should be. Note that it doesn’t truncate the original string. | ||
- **padding** (optional): The character(s) for padding. Yes, you could go crazy with multiple characters ;) | ||
- **side** (optional): The side which should be padded; please use `pad.LEFT`, `pad.RIGHT` or `pad.BOTH`. | ||
- **length** (optional): The length the output string should be. It doesn’t truncate the original string. | ||
- **padding** (optional): The character(s) for padding. You can go crazy with multiple characters ;) | ||
- **side** (optional): The side which should be padded; `pad.LEFT`, `pad.RIGHT` or `pad.BOTH`. | ||
For those who are totally fine with prototyping strings, you can do that. If you do, you can skip the first parameter. | ||
## Extending core String object | ||
For those who are fine with extending the core String object, you can do just that. Note you can skip the first parameter and directly call `.pad()` on a string. | ||
```javascript | ||
@@ -23,0 +25,0 @@ var pad = require('string-padding'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2499
32
30