Skip to content

Commit 1e08f10

Browse files
committed
Fix ESLint errors and README inconsistencies
- Replace `any` types with proper types in ipdata.ts (unknown, LookupResponse[]) - Fix no-use-before-define by moving keyBy() above its usage in tests - Replace for...of with Array.reduce to satisfy no-restricted-syntax rule - Type mockFetchResponse parameter as unknown instead of any - Update README badge URL to match package.json repository (thomasconner) - Add missing organisation field to README response fields list https://claude.ai/code/session_01UabaLo3R3sXovyxaZo2yCF
1 parent a93e8e3 commit 1e08f10

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IPData JavaScript Library
22

3-
[![](https://github.com/ConnerTechnology/ipdata-js-library/workflows/CI/badge.svg)](https://github.com/ConnerTechnology/ipdata-js-library/actions)
3+
[![](https://github.com/thomasconner/ipdata-js-library/workflows/CI/badge.svg)](https://github.com/thomasconner/ipdata-js-library/actions)
44

55
JavaScript library that can be used in a web browser or Node.js application to gather information for an IP address using https://ipdata.co.
66

@@ -154,7 +154,7 @@ ipdata.bulkLookup(ips, fields)
154154

155155
The following fields are available for use with `selectField` and `fields` parameters:
156156

157-
`ip`, `is_eu`, `city`, `region`, `region_code`, `country_name`, `country_code`, `continent_name`, `continent_code`, `latitude`, `longitude`, `asn`, `company`, `postal`, `calling_code`, `flag`, `emoji_flag`, `emoji_unicode`, `carrier`, `languages`, `currency`, `time_zone`, `threat`, `count`
157+
`ip`, `is_eu`, `city`, `region`, `region_code`, `country_name`, `country_code`, `continent_name`, `continent_code`, `latitude`, `longitude`, `asn`, `company`, `organisation`, `postal`, `calling_code`, `flag`, `emoji_flag`, `emoji_unicode`, `carrier`, `languages`, `currency`, `time_zone`, `threat`, `count`
158158

159159
The `company` field returns an object with `name`, `domain`, `network`, and `type` properties.
160160

src/ipdata.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const MOCK_DEFAULT_IP_DATA = {
6666
ip: '203.0.113.1',
6767
};
6868

69-
function mockFetchResponse(data: any, status = 200) {
69+
function mockFetchResponse(data: unknown, status = 200) {
7070
return Promise.resolve({
7171
ok: status >= 200 && status < 300,
7272
status,
@@ -77,6 +77,13 @@ function mockFetchResponse(data: any, status = 200) {
7777
const mockFetch = jest.fn() as jest.Mock;
7878
global.fetch = mockFetch;
7979

80+
function keyBy(items: LookupResponse[]): Record<string, LookupResponse> {
81+
return items.reduce<Record<string, LookupResponse>>((acc, item) => {
82+
acc[item.ip] = item;
83+
return acc;
84+
}, {});
85+
}
86+
8087
describe('constructor()', () => {
8188
it('should throw an error if an apiKey is not provided', () => {
8289
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -359,11 +366,3 @@ describe('bulkLookup()', () => {
359366
});
360367
});
361368
});
362-
363-
function keyBy(items: LookupResponse[]): Record<string, LookupResponse> {
364-
const result: Record<string, LookupResponse> = {};
365-
for (const item of items) {
366-
result[item.ip] = item;
367-
}
368-
return result;
369-
}

src/ipdata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ export default class IPData {
190190
return { ...errorData, status: response.status } as LookupResponse;
191191
}
192192

193-
const responseData = (await response.json()) as any;
193+
const responseData: unknown = await response.json();
194194
let data: LookupResponse;
195195

196196
if (selectField) {
197197
data = { [selectField]: responseData, status: response.status } as unknown as LookupResponse;
198198
} else {
199-
data = { ...responseData, status: response.status };
199+
data = { ...(responseData as Record<string, unknown>), status: response.status } as LookupResponse;
200200
}
201201

202202
this.cache.set(ip || DEFAULT_IP, data);
@@ -245,7 +245,7 @@ export default class IPData {
245245
return { ...errorData, status: response.status } as unknown as LookupResponse[];
246246
}
247247

248-
const responseData = (await response.json()) as any[];
248+
const responseData = (await response.json()) as LookupResponse[];
249249
responseData.forEach((info) => {
250250
this.cache.set(info.ip, { ...info, status: response.status });
251251
responses.push(this.cache.get(info.ip)!);

0 commit comments

Comments
 (0)