UNPKG

@rxap/nest-open-api

Version:

This package provides tools and utilities for integrating OpenAPI specifications into NestJS applications. It includes features for handling upstream API requests, managing server configurations, and generating OpenAPI documentation. It also offers interc

68 lines (67 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpParams = void 0; class HttpParams { constructor() { this.params = new Map(); } static ToHttpQueryString(params = {}) { if (!Object.keys(params).length) { return ''; } const httpParams = new HttpParams(); for (const [key, value] of Object.entries(params)) { httpParams.set(key, value); } return '?' + httpParams.toString(); } set(key, value) { return this.params.set(key, value); } has(key) { return this.params.has(key); } append(key, value) { if (this.params.has(key)) { const currentValue = this.params.get(key); let newValue; if (Array.isArray(currentValue)) { newValue = currentValue.slice(); if (Array.isArray(value)) { newValue.push(...value); } else { newValue.push(value); } } else { if (Array.isArray(value)) { newValue = [currentValue, ...value]; } else { newValue = [currentValue, value]; } } newValue = newValue.filter((v, i, a) => a.indexOf(v) === i); this.params.set(key, newValue); } else { this.set(key, value); } } toString() { const paramList = []; for (const [key, value] of this.params.entries()) { if (Array.isArray(value)) { for (const v of value) { paramList.push(`${key}=${encodeURIComponent(v)}`); } } else { paramList.push(`${key}=${encodeURIComponent(value)}`); } } return paramList.join('&'); } } exports.HttpParams = HttpParams;