mirror of
https://github.com/kennethreitz/bake.git
synced 2026-06-05 23:00:17 +00:00
cleanup
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
support
|
||||
test
|
||||
examples
|
||||
*.sock
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
test:
|
||||
@./node_modules/.bin/mocha \
|
||||
--require should \
|
||||
--reporter spec
|
||||
|
||||
.PHONY: test
|
||||
+30
@@ -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
@@ -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
@@ -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
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user