netpower-js
Version:
A common library that can be used for fe and be
39 lines • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Try to make the uri safely with not double back-splash
* @param path
*/
String.prototype.safeURI = function (path) {
var o = (origin === null || origin === void 0 ? void 0 : origin.endsWith('/')) ? origin === null || origin === void 0 ? void 0 : origin.slice(0, -1) : origin;
var p = (path === null || path === void 0 ? void 0 : path.startsWith('/')) ? path.slice(1) : path;
return o + "/" + p;
};
String.prototype.camelCase = function () {
var string = this.split(' ')
.reduce(function (result, word) { return result + " " + word.capitalize(); }, '');
return string.trim();
};
String.prototype.capitalize = function () {
return this.charAt(0).toUpperCase() + this.toLowerCase().slice(1);
};
String.prototype.isGuid = function () {
var regex = /[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}/i;
var match = regex.exec(this);
return match != null;
};
String.prototype.isValidURL = function () {
var regexQuery = '^(https?://)?(www\\.)?([-a-z0-9]{1,63}\\.)*?[a-z0-9][-a-z0-9]{0,61}[a-z0-9]\\.[a-z]{2,6}(/[-\\w@\\+\\.~#\\?&/=%]*)?$';
var url = new RegExp(regexQuery, 'i');
return url.test(this);
};
String.prototype.isJSON = function () {
try {
JSON.parse(this);
}
catch (e) {
return false;
}
return true;
};
//# sourceMappingURL=string.js.map