@anexia/ngx-interceptor-tools
Version:
This library provides a toolset for common http interceptor tasks, like request matching.
79 lines (67 loc) • 3.03 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define('@anexia/ngx-interceptor-tools', ['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.anexia = global.anexia || {}, global.anexia['ngx-interceptor-tools'] = {})));
}(this, (function (exports) { 'use strict';
function sanitizeUrlOrFragment(urlOrFragment) {
return String(urlOrFragment)
.replace(/[:\/&?]/g, '')
.trim();
}
var URL_WITH_PARAMS_SELECTOR = function (request) {
return sanitizeUrlOrFragment(request.urlWithParams);
};
var URL_SELECTOR = function (request) {
return sanitizeUrlOrFragment(request.url);
};
var RegExMatcher = /** @class */ (function () {
function RegExMatcher(patterns, selector) {
if (selector === void 0) { selector = URL_WITH_PARAMS_SELECTOR; }
this.patterns = patterns;
this.selector = selector;
if (patterns.length === 0) {
throw new Error('RegExMatcher provided patterns are empty.');
}
}
RegExMatcher.prototype.match = function (request) {
var selector = this.selector ? this.selector(request) : '';
return Boolean(this.patterns.filter(function (pattern) { return Boolean(pattern.test(selector)); }).length);
};
return RegExMatcher;
}());
var UrlFragmentMatcher = /** @class */ (function () {
function UrlFragmentMatcher(urlFragments, selector) {
if (selector === void 0) { selector = URL_WITH_PARAMS_SELECTOR; }
this.urlFragments = urlFragments;
this.selector = selector;
}
UrlFragmentMatcher.prototype.match = function (request) {
var selector = this.selector(request);
return Boolean(this.urlFragments.filter(function (fragment) { return selector.indexOf(fragment) !== -1; }).length);
};
return UrlFragmentMatcher;
}());
function requestBodySerializer(request, bodyParams) {
var postBody = [];
bodyParams.forEach(function (param) {
if (request.body.hasOwnProperty(param)) {
postBody.push(request.body[param]);
}
});
return [postBody.join('_')].join('_');
}
/*
* Public API Surface of ngx-interceptor-tools
*/
/**
* Generated bundle index. Do not edit.
*/
exports.RegExMatcher = RegExMatcher;
exports.URL_SELECTOR = URL_SELECTOR;
exports.URL_WITH_PARAMS_SELECTOR = URL_WITH_PARAMS_SELECTOR;
exports.UrlFragmentMatcher = UrlFragmentMatcher;
exports.requestBodySerializer = requestBodySerializer;
exports.sanitizeUrlOrFragment = sanitizeUrlOrFragment;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=anexia-ngx-interceptor-tools.umd.js.map