Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@whatwg-node/node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
620
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/node-fetch - npm Package Compare versions

Comparing version 0.7.6-alpha-20241227133443-491da4e9c34920079611c68a2aa3b9613ac93caa to 0.7.6-alpha-20250102085451-de4b863f8a6e01d74b4154a7023c6f3704af0666

73

cjs/URL.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PonyfillURL = void 0;
const tslib_1 = require("tslib");
const buffer_1 = require("buffer");
const crypto_1 = require("crypto");
const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring"));
const fast_url_parser_1 = tslib_1.__importDefault(require("@kamilkisiela/fast-url-parser"));
const URLSearchParams_js_1 = require("./URLSearchParams.js");
fast_url_parser_1.default.queryString = fast_querystring_1.default;
const IPV6_REGEX = /^(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?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0-9A-Fa-f]{1,4})?::)(?:\/(?:0?0?[0-9]|0?[1-9][0-9]|1[01][0-9]|12[0-8]))?)$/;
class PonyfillURL extends fast_url_parser_1.default {
constructor(url, base) {
super();
if (url.startsWith('data:')) {
this.protocol = 'data:';
this.pathname = url.slice('data:'.length);
return;
}
this.parse(url, false);
// `fast-url-parser` incorrectly removes `[IPV6]` in the hostname
// Then `hostname` doesn't include `[` and `]` for IPv6 URLs
// This breaks implementations that rely on `hostname` to include `[` and `]`
if ((url.startsWith('http://[') || url.startsWith('https://[')) &&
IPV6_REGEX.test(this.hostname)) {
this.hostname = `[${this.hostname}]`;
}
// `fast-url-parser` incorrectly handle URLs with ports without pathnames correctly like
// `http://localhost:8080?foo=bar` -> `http://localhost/:8080?foo=bar`
if (url.includes(`${this.hostname}:`) && !this.port && this.pathname.startsWith('/:')) {
this.port = this.pathname.slice(2);
this.pathname = '/';
this.host = `${this.hostname}:${this.port}`;
}
if (base) {
const baseParsed = typeof base === 'string' ? new PonyfillURL(base) : base;
this.protocol ||= baseParsed.protocol;
this.host ||= baseParsed.host;
this.pathname ||= baseParsed.pathname;
this.port ||= baseParsed.port;
}
}
get origin() {
return `${this.protocol}//${this.hostname}${this.port ? `:${this.port}` : ''}`;
}
_searchParams;
get searchParams() {
if (!this._searchParams) {
this._searchParams = new URLSearchParams_js_1.PonyfillURLSearchParams(this.query);
}
return this._searchParams;
}
get username() {
return this.auth?.split(':')[0] || '';
}
set username(value) {
this.auth = `${value}:${this.password}`;
}
get password() {
return this.auth?.split(':')[1] || '';
}
set password(value) {
this.auth = `${this.username}:${value}`;
}
toString() {
if (this._searchParams) {
this.search = this._searchParams.toString();
}
return this.format();
}
toJSON() {
return this.toString();
}
class PonyfillURL extends URL {
// This part is only needed to handle `PonyfillBlob` objects
static blobRegistry = new Map();

@@ -80,3 +14,3 @@ static createObjectURL(blob) {

}
static resolveObjectURL(url) {
static revokeObjectURL(url) {
if (!this.blobRegistry.has(url)) {

@@ -92,4 +26,3 @@ URL.revokeObjectURL(url);

}
[Symbol.toStringTag] = 'URL';
}
exports.PonyfillURL = PonyfillURL;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PonyfillURLSearchParams = void 0;
const tslib_1 = require("tslib");
const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring"));
const IteratorObject_js_1 = require("./IteratorObject.js");
function isURLSearchParams(value) {
return value?.entries != null;
}
class PonyfillURLSearchParams {
params;
constructor(init) {
if (init) {
if (typeof init === 'string') {
this.params = fast_querystring_1.default.parse(init);
}
else if (Array.isArray(init)) {
this.params = {};
for (const [key, value] of init) {
this.params[key] = value;
}
}
else if (isURLSearchParams(init)) {
this.params = {};
for (const [key, value] of init.entries()) {
this.params[key] = value;
}
}
else {
this.params = init;
}
}
else {
this.params = {};
}
}
append(name, value) {
const existingValue = this.params[name];
const finalValue = existingValue ? `${existingValue},${value}` : value;
this.params[name] = finalValue;
}
delete(name) {
delete this.params[name];
}
get(name) {
const value = this.params[name];
if (Array.isArray(value)) {
return value[0] || null;
}
return value || null;
}
getAll(name) {
const value = this.params[name];
if (!Array.isArray(value)) {
return value ? [value] : [];
}
return value;
}
has(name) {
return name in this.params;
}
set(name, value) {
this.params[name] = value;
}
sort() {
const sortedKeys = Object.keys(this.params).sort();
const sortedParams = {};
for (const key of sortedKeys) {
sortedParams[key] = this.params[key];
}
this.params = sortedParams;
}
toString() {
return fast_querystring_1.default.stringify(this.params);
}
*_keys() {
for (const key in this.params) {
yield key;
}
}
keys() {
return new IteratorObject_js_1.PonyfillIteratorObject(this._keys(), 'URLSearchParamsIterator');
}
*_entries() {
for (const key of this.keys()) {
const value = this.params[key];
if (Array.isArray(value)) {
for (const item of value) {
yield [key, item];
}
}
else {
yield [key, value];
}
}
}
entries() {
return new IteratorObject_js_1.PonyfillIteratorObject(this._entries(), 'URLSearchParamsIterator');
}
*_values() {
for (const [, value] of this) {
yield value;
}
}
values() {
return new IteratorObject_js_1.PonyfillIteratorObject(this._values(), 'URLSearchParamsIterator');
}
[Symbol.iterator]() {
return this.entries();
}
forEach(callback) {
for (const [key, value] of this) {
callback(value, key, this);
}
}
get size() {
return Object.keys(this.params).length;
}
}
exports.PonyfillURLSearchParams = PonyfillURLSearchParams;
exports.PonyfillURLSearchParams = globalThis.URLSearchParams;
import { resolveObjectURL } from 'buffer';
import { randomUUID } from 'crypto';
import FastQuerystring from 'fast-querystring';
import FastUrl from '@kamilkisiela/fast-url-parser';
import { PonyfillURLSearchParams } from './URLSearchParams.js';
FastUrl.queryString = FastQuerystring;
const IPV6_REGEX = /^(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)(?:\/(?:0?0?[0-9]|0?[1-9][0-9]|1[01][0-9]|12[0-8]))?)$/;
export class PonyfillURL extends FastUrl {
constructor(url, base) {
super();
if (url.startsWith('data:')) {
this.protocol = 'data:';
this.pathname = url.slice('data:'.length);
return;
}
this.parse(url, false);
// `fast-url-parser` incorrectly removes `[IPV6]` in the hostname
// Then `hostname` doesn't include `[` and `]` for IPv6 URLs
// This breaks implementations that rely on `hostname` to include `[` and `]`
if ((url.startsWith('http://[') || url.startsWith('https://[')) &&
IPV6_REGEX.test(this.hostname)) {
this.hostname = `[${this.hostname}]`;
}
// `fast-url-parser` incorrectly handle URLs with ports without pathnames correctly like
// `http://localhost:8080?foo=bar` -> `http://localhost/:8080?foo=bar`
if (url.includes(`${this.hostname}:`) && !this.port && this.pathname.startsWith('/:')) {
this.port = this.pathname.slice(2);
this.pathname = '/';
this.host = `${this.hostname}:${this.port}`;
}
if (base) {
const baseParsed = typeof base === 'string' ? new PonyfillURL(base) : base;
this.protocol ||= baseParsed.protocol;
this.host ||= baseParsed.host;
this.pathname ||= baseParsed.pathname;
this.port ||= baseParsed.port;
}
}
get origin() {
return `${this.protocol}//${this.hostname}${this.port ? `:${this.port}` : ''}`;
}
_searchParams;
get searchParams() {
if (!this._searchParams) {
this._searchParams = new PonyfillURLSearchParams(this.query);
}
return this._searchParams;
}
get username() {
return this.auth?.split(':')[0] || '';
}
set username(value) {
this.auth = `${value}:${this.password}`;
}
get password() {
return this.auth?.split(':')[1] || '';
}
set password(value) {
this.auth = `${this.username}:${value}`;
}
toString() {
if (this._searchParams) {
this.search = this._searchParams.toString();
}
return this.format();
}
toJSON() {
return this.toString();
}
export class PonyfillURL extends URL {
// This part is only needed to handle `PonyfillBlob` objects
static blobRegistry = new Map();

@@ -76,3 +11,3 @@ static createObjectURL(blob) {

}
static resolveObjectURL(url) {
static revokeObjectURL(url) {
if (!this.blobRegistry.has(url)) {

@@ -88,3 +23,2 @@ URL.revokeObjectURL(url);

}
[Symbol.toStringTag] = 'URL';
}

@@ -1,115 +0,1 @@

import FastQuerystring from 'fast-querystring';
import { PonyfillIteratorObject } from './IteratorObject.js';
function isURLSearchParams(value) {
return value?.entries != null;
}
export class PonyfillURLSearchParams {
params;
constructor(init) {
if (init) {
if (typeof init === 'string') {
this.params = FastQuerystring.parse(init);
}
else if (Array.isArray(init)) {
this.params = {};
for (const [key, value] of init) {
this.params[key] = value;
}
}
else if (isURLSearchParams(init)) {
this.params = {};
for (const [key, value] of init.entries()) {
this.params[key] = value;
}
}
else {
this.params = init;
}
}
else {
this.params = {};
}
}
append(name, value) {
const existingValue = this.params[name];
const finalValue = existingValue ? `${existingValue},${value}` : value;
this.params[name] = finalValue;
}
delete(name) {
delete this.params[name];
}
get(name) {
const value = this.params[name];
if (Array.isArray(value)) {
return value[0] || null;
}
return value || null;
}
getAll(name) {
const value = this.params[name];
if (!Array.isArray(value)) {
return value ? [value] : [];
}
return value;
}
has(name) {
return name in this.params;
}
set(name, value) {
this.params[name] = value;
}
sort() {
const sortedKeys = Object.keys(this.params).sort();
const sortedParams = {};
for (const key of sortedKeys) {
sortedParams[key] = this.params[key];
}
this.params = sortedParams;
}
toString() {
return FastQuerystring.stringify(this.params);
}
*_keys() {
for (const key in this.params) {
yield key;
}
}
keys() {
return new PonyfillIteratorObject(this._keys(), 'URLSearchParamsIterator');
}
*_entries() {
for (const key of this.keys()) {
const value = this.params[key];
if (Array.isArray(value)) {
for (const item of value) {
yield [key, item];
}
}
else {
yield [key, value];
}
}
}
entries() {
return new PonyfillIteratorObject(this._entries(), 'URLSearchParamsIterator');
}
*_values() {
for (const [, value] of this) {
yield value;
}
}
values() {
return new PonyfillIteratorObject(this._values(), 'URLSearchParamsIterator');
}
[Symbol.iterator]() {
return this.entries();
}
forEach(callback) {
for (const [key, value] of this) {
callback(value, key, this);
}
}
get size() {
return Object.keys(this.params).length;
}
}
export const PonyfillURLSearchParams = globalThis.URLSearchParams;

4

package.json
{
"name": "@whatwg-node/node-fetch",
"version": "0.7.6-alpha-20241227133443-491da4e9c34920079611c68a2aa3b9613ac93caa",
"version": "0.7.6-alpha-20250102085451-de4b863f8a6e01d74b4154a7023c6f3704af0666",
"description": "Fetch API implementation for Node",
"sideEffects": false,
"dependencies": {
"@kamilkisiela/fast-url-parser": "^1.1.4",
"@whatwg-node/disposablestack": "^0.0.5",
"busboy": "^1.6.0",
"fast-querystring": "^1.1.1",
"tslib": "^2.6.3"

@@ -12,0 +10,0 @@ },

@@ -1,20 +0,7 @@

import FastUrl from '@kamilkisiela/fast-url-parser';
import { PonyfillBlob } from './Blob.js';
import { PonyfillURLSearchParams } from './URLSearchParams.js';
export declare class PonyfillURL extends FastUrl implements URL {
constructor(url: string, base?: string | URL);
get origin(): string;
private _searchParams?;
get searchParams(): PonyfillURLSearchParams;
get username(): string;
set username(value: string);
get password(): string;
set password(value: string);
toString(): string;
toJSON(): string;
private static blobRegistry;
export declare class PonyfillURL extends URL {
static blobRegistry: Map<string, Blob | PonyfillBlob>;
static createObjectURL(blob: Blob): string;
static resolveObjectURL(url: string): void;
static revokeObjectURL(url: string): void;
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
[Symbol.toStringTag]: string;
}

@@ -1,21 +0,4 @@

export declare class PonyfillURLSearchParams implements URLSearchParams {
private params;
constructor(init?: string | string[][] | Record<string, string> | URLSearchParams);
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
set(name: string, value: string): void;
sort(): void;
toString(): string;
_keys(): IterableIterator<string>;
keys(): URLSearchParamsIterator<string>;
_entries(): IterableIterator<[string, string]>;
entries(): URLSearchParamsIterator<[string, string]>;
_values(): IterableIterator<string>;
values(): URLSearchParamsIterator<string>;
[Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
forEach(callback: (value: string, key: string, parent: URLSearchParams) => void): void;
get size(): number;
}
export declare const PonyfillURLSearchParams: {
new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
prototype: URLSearchParams;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc