00001 var createPadding = require('./_createPadding'),
00002 stringSize = require('./_stringSize'),
00003 toInteger = require('./toInteger'),
00004 toString = require('./toString');
00005
00006
00007 var nativeCeil = Math.ceil,
00008 nativeFloor = Math.floor;
00009
00033 function pad(string, length, chars) {
00034 string = toString(string);
00035 length = toInteger(length);
00036
00037 var strLength = length ? stringSize(string) : 0;
00038 if (!length || strLength >= length) {
00039 return string;
00040 }
00041 var mid = (length - strLength) / 2;
00042 return (
00043 createPadding(nativeFloor(mid), chars) +
00044 string +
00045 createPadding(nativeCeil(mid), chars)
00046 );
00047 }
00048
00049 module.exports = pad;