Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: upgrade to esmodule #100

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"after": true
},
"parserOptions": {
"ecmaVersion": 2023,
"sourceType": "script",
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
Expand Down
31 changes: 0 additions & 31 deletions lib/index.d.ts

This file was deleted.

32 changes: 15 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const zlib = require('zlib');
const http = require('http');
const https = require('https');
const parse = require('url').parse;
const format = require('url').format;

const debugBody = require('debug')('httpx:body');
const debugHeader = require('debug')('httpx:header');
import zlib from 'zlib';
import http from 'http';
import https from 'https';
import { parse, format } from 'url';
import debug from 'debug';

const debugBody = debug('httpx:body');
const debugHeader = debug('httpx:header');

const httpAgent = new http.Agent({ keepAlive: true });
const httpsAgent = new https.Agent({ keepAlive: true });
Expand Down Expand Up @@ -45,7 +45,7 @@ const isNumber = function (num) {
return num !== null && !isNaN(num);
};

exports.request = function (url, opts) {
export function request(url, opts) {
opts || (opts = {});

const parsed = typeof url === 'string' ? parse(url) : url;
Expand Down Expand Up @@ -180,9 +180,9 @@ exports.request = function (url, opts) {
}
});
});
};
}

exports.read = function (response, encoding) {
export function read(response, encoding) {
const readable = decompress(response);

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -260,7 +260,7 @@ exports.read = function (response, encoding) {
readable.on('data', onData);
readable.on('end', onEnd);
});
};
}

function readyToRead(readable) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -293,7 +293,7 @@ function readyToRead(readable) {
});
}

class Event {
export class Event {
constructor(id, event, data, retry) {
this.id = id;
this.event = event;
Expand All @@ -302,8 +302,6 @@ class Event {
}
}

exports.Event = Event;

const DATA_PREFIX = 'data:';
const EVENT_PREFIX = 'event:';
const ID_PREFIX = 'id:';
Expand Down Expand Up @@ -360,7 +358,7 @@ function tryGetEvents(head, chunk) {
* @param {ReadableStream} response
* @returns AsyncGenerator<Event, void, unknown>
*/
exports.readAsSSE = async function* (response) {
export async function* readAsSSE(response) {
const readable = decompress(response);

const socket = response.socket || response.client;
Expand All @@ -385,4 +383,4 @@ exports.readAsSSE = async function* (response) {
}
}
}
};
}
Loading
Loading