UNPKG

@nasriya/hypercloud

Version:

Nasriya HyperCloud is a lightweight Node.js HTTP2 framework.

42 lines (41 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class RequestBody { #_data = {}; /** * Securely set key:value pair * @param name * @param value */ set(name, value) { if (typeof name !== 'string') { throw new TypeError(`The property name can only be a string, instead got ${typeof name}`); } if (!(name === '__proto__' || name === 'constructor' || name === 'prototype')) { this.#_data[name] = decodeURIComponent(value); } } /** * Get the value * @param name */ get(name) { return this.#_data[name]; } _toJSON() { return this.#_data; } /** * Safely copy an object * @param value */ from(value) { if (typeof value === 'object' && Object.keys(value).length > 0) { for (const prop in value) { this.set(prop, value[prop]); } } return this._toJSON(); } } exports.default = RequestBody;