artdaq_node_server  v1_00_07
 All Classes Namespaces Files Variables Pages
pad.js
1 var createPadding = require('./_createPadding'),
2  stringSize = require('./_stringSize'),
3  toInteger = require('./toInteger'),
4  toString = require('./toString');
5 
6 /* Built-in method references for those with the same name as other `lodash` methods. */
7 var nativeCeil = Math.ceil,
8  nativeFloor = Math.floor;
9 
33 function pad(string, length, chars) {
34  string = toString(string);
35  length = toInteger(length);
36 
37  var strLength = length ? stringSize(string) : 0;
38  if (!length || strLength >= length) {
39  return string;
40  }
41  var mid = (length - strLength) / 2;
42  return (
43  createPadding(nativeFloor(mid), chars) +
44  string +
45  createPadding(nativeCeil(mid), chars)
46  );
47 }
48 
49 module.exports = pad;