UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

55 lines (53 loc) 2.01 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/util/StringUtils/leftPad.ts var leftPad_exports = {}; __export(leftPad_exports, { leftPad: () => leftPad }); module.exports = __toCommonJS(leftPad_exports); var import_defaultIfBlank = require("./defaultIfBlank"); var import_defaultString = require("./defaultString"); var import_getLength = require("./getLength"); var import_repeat = require("./repeat"); function leftPad(text, size, pad) { if (size === void 0 || size <= 0) { return text; } const textLength = (0, import_getLength.getLength)(text); const needLength = size - textLength; if (needLength <= 0) { return text; } const padding = (0, import_defaultIfBlank.defaultIfBlank)(pad, " "); const padLength = (0, import_getLength.getLength)(padding); const quotient = Math.floor(needLength / padLength); const remainder = needLength % padLength; let result = ""; if (quotient > 0) { result = result.concat((0, import_repeat.repeat)(padding, quotient)); } if (remainder > 0) { result = result.concat(padding.substring(0, remainder)); } return result.concat((0, import_defaultString.defaultString)(text)); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { leftPad });