This commit is contained in:
2019-09-17 13:20:42 -04:00
parent d211d1dc34
commit bef10ce4c9
8352 changed files with 568242 additions and 51 deletions
+4
View File
@@ -0,0 +1,4 @@
support
test
examples
*.sock
View File
+7
View File
@@ -0,0 +1,7 @@
test:
@./node_modules/.bin/mocha \
--require should \
--reporter spec
.PHONY: test
+30
View File
@@ -0,0 +1,30 @@
# pad
Trims string whitespace.
## Installation
```
$ npm install pad-component
$ component install component/pad
```
## API
### pad(str, len[, char])
Pad `str` on both sides to the given `len`, with optional `char`
defaulting to a space.
### pad.left(str, len[, char])
Pad `str` on the left to the given `len` with optional `char`.
### pad.right(str, len[, char])
Pad `str` on the right to the given `len` with optional `char`.
## License
MIT
+8
View File
@@ -0,0 +1,8 @@
{
"name": "pad",
"repo": "component/pad",
"version": "0.0.1",
"description": "Pad strings to a given length",
"keywords": ["string", "trim", "utility"],
"scripts": ["index.js"]
}
+58
View File
@@ -0,0 +1,58 @@
/**
* Expose `pad()`.
*/
exports = module.exports = pad;
/**
* Pad `str` to `len` with optional `c` char,
* favoring the left when unbalanced.
*
* @param {String} str
* @param {Number} len
* @param {String} c
* @return {String}
* @api public
*/
function pad(str, len, c) {
c = c || ' ';
if (str.length >= len) return str;
len = len - str.length;
var left = Array(Math.ceil(len / 2) + 1).join(c);
var right = Array(Math.floor(len / 2) + 1).join(c);
return left + str + right;
}
/**
* Pad `str` left to `len` with optional `c` char.
*
* @param {String} str
* @param {Number} len
* @param {String} c
* @return {String}
* @api public
*/
exports.left = function(str, len, c){
c = c || ' ';
if (str.length >= len) return str;
return Array(len - str.length + 1).join(c) + str;
};
/**
* Pad `str` right to `len` with optional `c` char.
*
* @param {String} str
* @param {Number} len
* @param {String} c
* @return {String}
* @api public
*/
exports.right = function(str, len, c){
c = c || ' ';
if (str.length >= len) return str;
return str + Array(len - str.length + 1).join(c);
};
+17
View File
@@ -0,0 +1,17 @@
{
"name": "pad-component",
"version": "0.0.1",
"description": "Pad strings to a given length",
"keywords": ["string", "pad"],
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"dependencies": {},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"component": {
"scripts": {
"pad/index.js": "index.js"
}
}
}