UNPKG

@akanass/rx-http-request

Version:

The world-famous HTTP client Request now RxJS compliant, wrote in Typescript | ES6 for client and server side.

81 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const url = require("url"); exports.url = url; const rxjs_1 = require("rxjs"); /** * Class definition */ class RxCookieJar { /** * Class constructor */ constructor(cookieJar) { // check cookie parameter this._checkRequestParam(cookieJar); // set cookie jar object this._cookieJar = cookieJar; } /** * Returns private property _cookieJar * * @return {CookieJar} */ get cookieJar() { return this._cookieJar; } /** * Function to set a new cookie jar * * @param cookie {Cookie} * @param uri {string | url.Url} * @param options {any} * * @return {Observable<void>} */ setCookie(cookie, uri, options) { return rxjs_1.Observable.create((observer) => { this._cookieJar.setCookie(cookie, uri, options); observer.next(); observer.complete(); }); } /** * Function to get cookie string * * @param uri {string | url.Url} * * @return {Observable<string>} */ getCookieString(uri) { return rxjs_1.of(this._cookieJar.getCookieString(uri)); } /** * Funtion to get an array of cookies * * @param uri {string | url.Url} * * @return {Observable<Cookie[]>} */ getCookies(uri) { return rxjs_1.of(this._cookieJar.getCookies(uri)); } /** * Function to check existing function in object passed in parameter for a new instance * * @param cookieJar {CookieJar} * * @private */ _checkRequestParam(cookieJar) { // check existing function in object if (!cookieJar || Object.prototype.toString.call(cookieJar.setCookie) !== '[object Function]' || Object.prototype.toString.call(cookieJar.getCookieString) !== '[object Function]' || Object.prototype.toString.call(cookieJar.getCookies) !== '[object Function]') { throw new TypeError('Parameter must be a valid `CookieJar` object'); } } } exports.RxCookieJar = RxCookieJar; //# sourceMappingURL=rx-cookie-jar.js.map