trending-news-api 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import type { TrendingNewsData, TrendingNewsOptions, TrendingNewsTopicData } from '../types';
2
+ /**
3
+ * Fetches trending topics (or, when `options.topic` is set, news for a
4
+ * single topic) from a deployed instance of `worker/index.ts`.
5
+ */
6
+ export declare function getTrendingNews(options: TrendingNewsOptions): Promise<TrendingNewsData>;
7
+ /** Fetches news articles for a single topic. */
8
+ export declare function getTrendingNewsForTopic(topic: string, options: Omit<TrendingNewsOptions, 'topic'>): Promise<TrendingNewsTopicData>;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import type { TrendingNewsOptions } from '../types';
3
+ type Props = TrendingNewsOptions & {
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ compact?: boolean;
7
+ /** Max trending topics to render (default 8). */
8
+ maxTopics?: number;
9
+ /**
10
+ * When set on a `compact` card, a chevron toggles between the compact
11
+ * topic row and a full topic-by-topic article list, without leaving the
12
+ * card's layout. Ignored outside `compact` mode, which already shows the
13
+ * full list.
14
+ */
15
+ expandable?: boolean;
16
+ /** Max topics to render once expanded (default 15). */
17
+ expandedMaxTopics?: number;
18
+ /** Show each topic's lead article thumbnail image, when available (default true). */
19
+ showImages?: boolean;
20
+ };
21
+ /**
22
+ * Trending news widget. Requires `apiEndpoint` pointing at a deployed
23
+ * instance of the bundled Cloudflare Worker (`worker/index.ts`) — renders
24
+ * nothing when it's not configured, still loading, or errored, so it never
25
+ * disrupts the layout it's dropped into.
26
+ */
27
+ export declare function TrendingNews(props: Props): React.JSX.Element | null;
28
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { TrendingNewsData, TrendingNewsOptions } from '../types';
2
+ export declare function useTrendingNews(options?: TrendingNewsOptions): {
3
+ data: TrendingNewsData | null;
4
+ error: Error | null;
5
+ loading: boolean;
6
+ };
package/dist/index.d.ts CHANGED
@@ -1,78 +1,5 @@
1
- import React from 'react';
2
-
3
- type NewsArticle = {
4
- title: string;
5
- url?: string;
6
- source?: string;
7
- publishedAt?: string;
8
- imageUrl?: string;
9
- };
10
- type TrendingTopic = {
11
- topic: string;
12
- wikiRank?: number;
13
- wikiViews?: number;
14
- newsCount: number;
15
- articles: NewsArticle[];
16
- };
17
- type TrendingNewsData = {
18
- date?: string;
19
- topics: TrendingTopic[];
20
- };
21
- type TrendingNewsTopicData = {
22
- topic: string;
23
- newsCount: number;
24
- articles: NewsArticle[];
25
- };
26
- type TrendingNewsOptions = {
27
- /** URL of a deployed instance of the bundled Cloudflare Worker (`worker/index.ts`). */
28
- apiEndpoint?: string;
29
- /** When set, fetches news for this single topic instead of the daily trending list. */
30
- topic?: string;
31
- /** Max trending topics to request from the worker (default 25). */
32
- limit?: number;
33
- };
34
-
35
- /** Clears all cached trending news responses. Mainly useful for tests/debugging. */
36
- declare function clearTrendingNewsCache(): void;
37
-
38
- /**
39
- * Fetches trending topics (or, when `options.topic` is set, news for a
40
- * single topic) from a deployed instance of `worker/index.ts`.
41
- */
42
- declare function getTrendingNews(options: TrendingNewsOptions): Promise<TrendingNewsData>;
43
- /** Fetches news articles for a single topic. */
44
- declare function getTrendingNewsForTopic(topic: string, options: Omit<TrendingNewsOptions, 'topic'>): Promise<TrendingNewsTopicData>;
45
-
46
- declare function useTrendingNews(options?: TrendingNewsOptions): {
47
- data: TrendingNewsData | null;
48
- error: Error | null;
49
- loading: boolean;
50
- };
51
-
52
- type Props = TrendingNewsOptions & {
53
- className?: string;
54
- style?: React.CSSProperties;
55
- compact?: boolean;
56
- /** Max trending topics to render (default 8). */
57
- maxTopics?: number;
58
- /**
59
- * When set on a `compact` card, a chevron toggles between the compact
60
- * topic row and a full topic-by-topic article list, without leaving the
61
- * card's layout. Ignored outside `compact` mode, which already shows the
62
- * full list.
63
- */
64
- expandable?: boolean;
65
- /** Max topics to render once expanded (default 15). */
66
- expandedMaxTopics?: number;
67
- /** Show each topic's lead article thumbnail image, when available (default true). */
68
- showImages?: boolean;
69
- };
70
- /**
71
- * Trending news widget. Requires `apiEndpoint` pointing at a deployed
72
- * instance of the bundled Cloudflare Worker (`worker/index.ts`) — renders
73
- * nothing when it's not configured, still loading, or errored, so it never
74
- * disrupts the layout it's dropped into.
75
- */
76
- declare function TrendingNews(props: Props): React.JSX.Element | null;
77
-
78
- export { type NewsArticle, TrendingNews, type TrendingNewsData, type TrendingNewsOptions, type TrendingNewsTopicData, type TrendingTopic, clearTrendingNewsCache, getTrendingNews, getTrendingNewsForTopic, useTrendingNews };
1
+ export * from './types';
2
+ export { clearTrendingNewsCache } from './lib/cache';
3
+ export * from './api/trending';
4
+ export * from './hooks/useTrendingNews';
5
+ export * from './components/TrendingNews';
@@ -0,0 +1,5 @@
1
+ /** Returns the cached value for `key` if it was written within the last 10 minutes. */
2
+ export declare function readCachedTrendingNews<T>(key: string): T | null;
3
+ export declare function writeCachedTrendingNews<T>(key: string, data: T): void;
4
+ /** Clears all cached trending news responses. Mainly useful for tests/debugging. */
5
+ export declare function clearTrendingNewsCache(): void;
@@ -0,0 +1,31 @@
1
+ export type NewsArticle = {
2
+ title: string;
3
+ url?: string;
4
+ source?: string;
5
+ publishedAt?: string;
6
+ imageUrl?: string;
7
+ };
8
+ export type TrendingTopic = {
9
+ topic: string;
10
+ wikiRank?: number;
11
+ wikiViews?: number;
12
+ newsCount: number;
13
+ articles: NewsArticle[];
14
+ };
15
+ export type TrendingNewsData = {
16
+ date?: string;
17
+ topics: TrendingTopic[];
18
+ };
19
+ export type TrendingNewsTopicData = {
20
+ topic: string;
21
+ newsCount: number;
22
+ articles: NewsArticle[];
23
+ };
24
+ export type TrendingNewsOptions = {
25
+ /** URL of a deployed instance of the bundled Cloudflare Worker (`worker/index.ts`). */
26
+ apiEndpoint?: string;
27
+ /** When set, fetches news for this single topic instead of the daily trending list. */
28
+ topic?: string;
29
+ /** Max trending topics to request from the worker (default 25). */
30
+ limit?: number;
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trending-news-api",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "React trending news widget backed by Wikipedia pageviews and The News API, via a Cloudflare Worker proxy",
5
5
  "keywords": [
6
6
  "react",
@@ -37,22 +37,22 @@
37
37
  "react-dom": "^18 || ^19"
38
38
  },
39
39
  "devDependencies": {
40
- "@cloudflare/workers-types": "^4.20250115.0",
41
- "@testing-library/react": "^16.1.0",
42
- "@types/react": "^19.0.0",
43
- "@types/react-dom": "^19.0.0",
44
- "@vitejs/plugin-react": "^6.0.3",
45
- "@vitest/coverage-v8": "^4.0.18",
46
- "jsdom": "^28.1.0",
47
- "react": "^19.2.7",
48
- "react-dom": "^19.2.7",
49
- "tsup": "^8.2.4",
50
- "typescript": "^5.6.3",
51
- "vitest": "^4.0.18",
52
- "wrangler": "^3.88.0"
40
+ "@cloudflare/workers-types": "^5.20260908.1",
41
+ "@testing-library/react": "^16.3.3",
42
+ "@types/react": "^19.2.18",
43
+ "@types/react-dom": "^19.2.7",
44
+ "@vitejs/plugin-react": "^6.1.1",
45
+ "@vitest/coverage-v8": "^5.0.0",
46
+ "jsdom": "^30.0.1",
47
+ "react": "^19.2.8",
48
+ "react-dom": "^19.2.8",
49
+ "tsup": "^8.5.1",
50
+ "typescript": "^7.0.2",
51
+ "vitest": "^5.0.0",
52
+ "wrangler": "^4.130.0"
53
53
  },
54
54
  "scripts": {
55
- "build": "tsup",
55
+ "build": "tsup && tsc --project tsconfig.build.json",
56
56
  "typecheck": "tsc --noEmit",
57
57
  "test": "vitest run",
58
58
  "test:coverage": "vitest run --coverage",
package/dist/index.d.cts DELETED
@@ -1,78 +0,0 @@
1
- import React from 'react';
2
-
3
- type NewsArticle = {
4
- title: string;
5
- url?: string;
6
- source?: string;
7
- publishedAt?: string;
8
- imageUrl?: string;
9
- };
10
- type TrendingTopic = {
11
- topic: string;
12
- wikiRank?: number;
13
- wikiViews?: number;
14
- newsCount: number;
15
- articles: NewsArticle[];
16
- };
17
- type TrendingNewsData = {
18
- date?: string;
19
- topics: TrendingTopic[];
20
- };
21
- type TrendingNewsTopicData = {
22
- topic: string;
23
- newsCount: number;
24
- articles: NewsArticle[];
25
- };
26
- type TrendingNewsOptions = {
27
- /** URL of a deployed instance of the bundled Cloudflare Worker (`worker/index.ts`). */
28
- apiEndpoint?: string;
29
- /** When set, fetches news for this single topic instead of the daily trending list. */
30
- topic?: string;
31
- /** Max trending topics to request from the worker (default 25). */
32
- limit?: number;
33
- };
34
-
35
- /** Clears all cached trending news responses. Mainly useful for tests/debugging. */
36
- declare function clearTrendingNewsCache(): void;
37
-
38
- /**
39
- * Fetches trending topics (or, when `options.topic` is set, news for a
40
- * single topic) from a deployed instance of `worker/index.ts`.
41
- */
42
- declare function getTrendingNews(options: TrendingNewsOptions): Promise<TrendingNewsData>;
43
- /** Fetches news articles for a single topic. */
44
- declare function getTrendingNewsForTopic(topic: string, options: Omit<TrendingNewsOptions, 'topic'>): Promise<TrendingNewsTopicData>;
45
-
46
- declare function useTrendingNews(options?: TrendingNewsOptions): {
47
- data: TrendingNewsData | null;
48
- error: Error | null;
49
- loading: boolean;
50
- };
51
-
52
- type Props = TrendingNewsOptions & {
53
- className?: string;
54
- style?: React.CSSProperties;
55
- compact?: boolean;
56
- /** Max trending topics to render (default 8). */
57
- maxTopics?: number;
58
- /**
59
- * When set on a `compact` card, a chevron toggles between the compact
60
- * topic row and a full topic-by-topic article list, without leaving the
61
- * card's layout. Ignored outside `compact` mode, which already shows the
62
- * full list.
63
- */
64
- expandable?: boolean;
65
- /** Max topics to render once expanded (default 15). */
66
- expandedMaxTopics?: number;
67
- /** Show each topic's lead article thumbnail image, when available (default true). */
68
- showImages?: boolean;
69
- };
70
- /**
71
- * Trending news widget. Requires `apiEndpoint` pointing at a deployed
72
- * instance of the bundled Cloudflare Worker (`worker/index.ts`) — renders
73
- * nothing when it's not configured, still loading, or errored, so it never
74
- * disrupts the layout it's dropped into.
75
- */
76
- declare function TrendingNews(props: Props): React.JSX.Element | null;
77
-
78
- export { type NewsArticle, TrendingNews, type TrendingNewsData, type TrendingNewsOptions, type TrendingNewsTopicData, type TrendingTopic, clearTrendingNewsCache, getTrendingNews, getTrendingNewsForTopic, useTrendingNews };