@lugia/type-utils
Version:
类型相关工具
1 lines • 974 B
JavaScript
;exports.pad=function(t){var e=t.str,r=void 0===e?"":e,n=t.len,i=void 0===n?0:n,s=t.pad,u=void 0===s?" ":s,o=t.dir,a=void 0===o?"right":o,l=0;if(i>r.length)switch(a){case"left":r=u.repeat(i-r.length)+r;break;case"both":var c=Math.ceil((l=i-r.length)/2),h=l-c;r=u.repeat(h)+r+u.repeat(c);break;case"right":r+=u.repeat(i-r.length);break;default:return r}return r},exports.truncate=function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"…";return t.length>=e?t.substr(0,e-r.length)+r:t},exports.strlen=function(t){return(""+t).replace(/\u001b\[(?:\d*;){0,5}\d*m/g,"").split("\n").reduce(function(t,e){return e.length>t?e.length:t},0)},exports.startsWith=function(t,e){return null!=t&&t.startsWith(e)},exports.endsWith=function(t,e){return null!=t&&t.endsWith(e)},exports.containWith=function(t,e){return null!=t&&-1!==t.indexOf(e)},exports.isBlank=function(t){return!t||!t.trim()},exports.isPositiveInteger=function(t){return/^\d+$/.test(t)};