timezonecomplete
Version:
DateTime, TimeZone, Duration and Period library aimed at providing a consistent and complete date-time interface, away from the original JavaScript Date class.
44 lines • 1.54 kB
JavaScript
/**
* Copyright(c) 2014 ABB Switzerland Ltd.
*
* String utility functions
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.padRight = exports.padLeft = void 0;
var assert_1 = require("./assert");
/**
* Pad a string by adding characters to the beginning.
* @param s the string to pad
* @param width the desired minimum string width
* @param char the single character to pad with
* @return the padded string
* @throws timezonecomplete.Argument.Width if width is not an integer number >= 0
*/
function padLeft(s, width, char) {
(0, assert_1.default)(Number.isInteger(width) && width >= 0, "Argument.Width", "width should be an integer number >= 0 but is: %d", width);
var padding = "";
for (var i = 0; i < (width - s.length); i++) {
padding += char;
}
return padding + s;
}
exports.padLeft = padLeft;
/**
* Pad a string by adding characters to the end.
* @param s the string to pad
* @param width the desired minimum string width
* @param char the single character to pad with
* @return the padded string
* @throws timezonecomplete.Argument.Width if width is not an integer number >= 0
*/
function padRight(s, width, char) {
(0, assert_1.default)(Number.isInteger(width) && width >= 0, "Argument.Width", "width should be an integer number >= 0 but is: %d", width);
var padding = "";
for (var i = 0; i < (width - s.length); i++) {
padding += char;
}
return s + padding;
}
exports.padRight = padRight;
//# sourceMappingURL=strings.js.map