"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.length = length; exports.substring = substring; exports.limit = limit; var _string = require("./string"); function length(str) { // Check for input if (typeof str !== "string") { throw new Error("Input must be a string"); } var match = str.match(_string.astralRange); return match === null ? 0 : match.length; } function substring(str) { var begin = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; var end = arguments[2]; // Check for input if (typeof str !== "string") { throw new Error("Input must be a string"); } // Even though negative numbers work here, theyre not in the spec if (typeof begin !== "number" || begin < 0) { begin = 0; } if (typeof end === "number" && end < 0) { end = 0; } return str.match(_string.astralRange).slice(begin, end).join(""); } function limit(str) { var limit = arguments.length <= 1 || arguments[1] === undefined ? 16 : arguments[1]; var padString = arguments.length <= 2 || arguments[2] === undefined ? "#" : arguments[2]; var padPosition = arguments.length <= 3 || arguments[3] === undefined ? "right" : arguments[3]; // Input should be a string, limit should be a number if (typeof str !== "string" || typeof limit !== "number") { throw new Error("Invalid arguments specified"); } // Pad position should be either left or right if (["left", "right"].indexOf(padPosition) === -1) { throw new Error("Pad position should be either left or right"); } // Pad string can be anything, we convert it to string if (typeof padString !== "string") { padString = String(padString); } // Calculate string length considering astral code points var strLength = length(str); if (strLength > limit) { return substring(str, 0, limit); } else if (strLength < limit) { var padRepeats = padString.repeat(limit - strLength); return padPosition === "left" ? padRepeats + str : str + padRepeats; } return str; }