ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
35 lines (34 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var errors = require("./../errors");
var StringUtils = /** @class */ (function () {
function StringUtils() {
}
StringUtils.isNullOrWhitespace = function (str) {
return typeof str !== "string" || str.trim().length === 0;
};
StringUtils.repeat = function (str, times) {
var newStr = "";
for (var i = 0; i < times; i++)
newStr += str;
return newStr;
};
StringUtils.startsWith = function (str, startsWithString) {
return str.substr(0, startsWithString.length) === startsWithString;
};
StringUtils.endsWith = function (str, endsWithString) {
return str.substr(str.length - endsWithString.length, endsWithString.length) === endsWithString;
};
StringUtils.getLineNumberFromPos = function (str, pos) {
errors.throwIfOutOfRange(pos, [0, str.length + 1], "pos");
// do not allocate a string in this method
var count = 0;
for (var i = 0; i < pos; i++) {
if (str[i] === "\n" || (str[i] === "\r" && str[i + 1] !== "\n"))
count++;
}
return count + 1; // convert count to line number
};
return StringUtils;
}());
exports.StringUtils = StringUtils;