semantic-analysis
Version:
Extensible semantic Structured Data analysis library for Microdata and JSON-LD
54 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.combine = exports.isUrl = exports.isValuePrimitive = exports.isItem = void 0;
/**
* Item interface type guard
* @param value To inspect
*/
exports.isItem = function (value) {
return !exports.isValuePrimitive(value);
};
/**
* String type guard
* @param value To inspect
*/
exports.isValuePrimitive = function (value) {
return typeof value === 'string';
};
/**
* Find out whether is valid URL
* @param s To check
*/
function isUrl(s) {
try {
new URL(s).toString();
return true;
}
catch (e) {
return false;
}
}
exports.isUrl = isUrl;
/**
* Combines term to the base address
* @param term Term to complete
* @param base Base to apply term to
*/
function combine(term, base) {
try {
if (!base || isUrl(term)) {
return term;
}
var b = new URL(base);
if (b.hash.length > 0 || b.toString().endsWith('#')) {
b.hash = term;
return b.toString();
}
return new URL(term, base).toString();
}
catch (e) {
return term;
}
}
exports.combine = combine;
//# sourceMappingURL=util.js.map