decova-dotnet-developer
Version:
This package provides fundumentals that a .net developer may miss while working with Typescript, whether they are missing functinalities or funcionalities provided in a non-elegant design in javascript. Bad naming, bad design of optional parameters, non-c
109 lines • 3.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("../../x");
let proto = String.prototype;
proto.PadRight = function (totalWidth, paddingChar) {
if (paddingChar.length !== 1)
throw "Only one character expected in paddingChar";
let countLeft = totalWidth - this.length;
let output = this;
for (let x = 0; x < countLeft; x++) {
output = output + paddingChar;
}
return output;
};
proto.PadLeft = function (totalWidth, paddingChar) {
if (paddingChar.length != 1)
throw "Only one character expected in paddingChar";
let countLeft = totalWidth - this.length;
let output = this;
for (let x = 0; x < countLeft; x++) {
output = output + paddingChar;
}
return output;
};
proto.Substring = function (startIndex, length = undefined) {
if (startIndex >= this.length)
throw new Error("Index out of range");
if (length == undefined) {
length = this.length - 1 - startIndex;
}
else {
if (startIndex + length > this.length)
throw "String.Substring() index out of range";
}
let lastIndex = startIndex + length;
return this.slice(startIndex, lastIndex);
};
proto.Remove = function (startIndex, length) {
if (length <= 0)
throw new Error("Invalid argument length");
if (startIndex + length - 1 > this.length)
throw new Error("Out of range.");
let leftPart = this.Substring(0, startIndex);
let rightPart = this.Substring(startIndex + length, this.length - startIndex - length);
return leftPart + rightPart;
};
proto.Contains = function (substr) {
if (substr == null || substr == "")
throw new Error("substr cannot be null or empty");
return this.includes(substr, 0);
};
proto.Insert = function (index, value) {
if (index < 0 || index >= this.length)
throw new Error('Out of range');
return `${this.Substring(0, index)}${value}${this.Substring(index, undefined)}`;
};
proto.ToString = function () {
return this;
};
proto.IsEmpty = function () {
if (this === "")
return true;
return false;
};
proto.IsWhiteSpace = function () {
if (new RegExp(/^\s*$/g).test(this))
return true;
else
return false;
};
proto.StartsWith = function (str) {
return this.startsWith(str);
};
proto.EndsWith = function (str) {
return this.endsWith(str);
};
proto.IndexOf = function (subStr, startSearchFromIndex) {
if (subStr == null)
throw new Error("subStr cannot be null");
if (startSearchFromIndex < 0 || startSearchFromIndex >= subStr.length)
throw new Error("Index out of range");
return this.indexOf(subStr, startSearchFromIndex);
};
proto.LastIndexOf = function (subStr, startSearchFromIndex) {
if (subStr == null)
throw new Error("subStr cannot be null");
if (startSearchFromIndex < 0 || startSearchFromIndex >= subStr.length)
throw new Error("Index out of range");
return this.lastIndexOf(subStr, startSearchFromIndex);
};
proto.ReplaceOnce = function (toReplace, replacement) {
return this.replace(toReplace, replacement);
};
proto.ReplaceAll = function (toReplace, replacement) {
if (toReplace == replacement)
this;
let output = this;
while (output.indexOf(toReplace) >= 0) {
output = output.replace(toReplace, replacement);
}
return output;
};
let protoConstructor = String;
protoConstructor.Join = function (separator, parts) {
if (parts.length == 0)
return '';
return parts.join(separator);
};
//# sourceMappingURL=String.x.js.map