qms-js
Version:
A common library that can be used for fe and be
53 lines • 2.05 kB
JavaScript
;
/* eslint-disable no-unused-vars */
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Compare 2 string that contains same words:
* For example: ikke risiko vurdert will be matched "risiko vurder ikke"
* @param target string
* @param des string
*/
String.prototype.fullMatch = function (des) {
if (!this || !des)
return false;
var p1 = this.toLocaleLowerCase().split(' ').map(function (x) { return x.trim(); });
var p2 = des.toLocaleLowerCase().split(' ').map(function (x) { return x.trim(); });
return p1.every(function (x) { return p2.some(function (y) { return x.includes(y) || y.includes(x); }); });
};
/**
* 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