tiktok-trends-api 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # tiktok-trends-api
2
+
3
+ TikTok hashtag volume over time via REST API. Weekly or daily series, period-over-period growth, and live TikTok trending hashtags. No TikTok API approval needed.
4
+
5
+ **[Get your free API key at trendsmcp.ai](https://trendsmcp.ai)** — 100 requests/month, no credit card.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install tiktok-trends-api
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```typescript
16
+ import { TrendsMcpClient } from "tiktok-trends-api";
17
+
18
+ const client = new TrendsMcpClient({ apiKey: "YOUR_API_KEY" });
19
+
20
+ // 5-year weekly time series
21
+ const series = await client.getTrends({
22
+ source: "tiktok",
23
+ keyword: "BookTok",
24
+ });
25
+ console.log(series[0]);
26
+ // { date: "2026-03-28", value: 72, volume: null, keyword: "BookTok", source: "tiktok" }
27
+
28
+ // Period-over-period growth
29
+ const growth = await client.getGrowth({
30
+ source: "tiktok",
31
+ keyword: "BookTok",
32
+ percent_growth: ["3M", "1Y"],
33
+ });
34
+ console.log(growth.results[0]);
35
+ // { period: "3M", growth: 14.5, direction: "increase", ... }
36
+
37
+ // What's trending right now
38
+ const trending = await client.getTopTrends({ limit: 10 });
39
+ console.log(trending.data);
40
+ // [[1, "topic one"], [2, "topic two"], ...]
41
+ ```
42
+
43
+ ## Methods
44
+
45
+ ### `getTrends(params)`
46
+
47
+ Returns a historical time series for a keyword. Defaults to 5 years of weekly data. Pass `data_mode: "daily"` for the last 30 days.
48
+
49
+ ### `getGrowth(params)`
50
+
51
+ Calculates percentage growth between two points in time. Pass preset strings (`"3M"`, `"1Y"`, `"YTD"`, etc.) or custom date pairs.
52
+
53
+ **Growth presets:** `7D` `14D` `30D` `1M` `2M` `3M` `6M` `9M` `12M` `1Y` `18M` `24M` `2Y` `36M` `3Y` `48M` `60M` `5Y` `MTD` `QTD` `YTD`
54
+
55
+ ### `getTopTrends(params?)`
56
+
57
+ Returns today's live trending items. Omit `type` to get all feeds at once.
58
+
59
+ ## All supported sources
60
+
61
+ This package exposes the full `TrendsMcpClient` — all sources work, not just `tiktok`:
62
+
63
+ | source | Description |
64
+ |---|---|
65
+ | `"google search"` | Google search volume |
66
+ | `"google images"` | Google image search volume |
67
+ | `"google news"` | Google News search volume |
68
+ | `"google shopping"` | Google Shopping search volume |
69
+ | `"youtube"` | YouTube search volume |
70
+ | `"tiktok"` | TikTok hashtag volume |
71
+ | `"reddit"` | Reddit mention volume |
72
+ | `"amazon"` | Amazon product search volume |
73
+ | `"wikipedia"` | Wikipedia page views |
74
+ | `"news volume"` | News article mention volume |
75
+ | `"news sentiment"` | News sentiment score |
76
+ | `"npm"` | npm package weekly downloads |
77
+ | `"steam"` | Steam concurrent players |
78
+
79
+ ## Error handling
80
+
81
+ ```typescript
82
+ import { TrendsMcpClient, TrendsMcpError } from "tiktok-trends-api";
83
+
84
+ try {
85
+ const series = await client.getTrends({ source: "tiktok", keyword: "BookTok" });
86
+ } catch (err) {
87
+ if (err instanceof TrendsMcpError) {
88
+ console.error(err.status); // 429
89
+ console.error(err.code); // "rate_limited"
90
+ console.error(err.message);
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Links
96
+
97
+ - [API docs](https://trendsmcp.ai/docs)
98
+ - [Get a free API key](https://trendsmcp.ai)
99
+ - [All packages](https://www.npmjs.com/~trendsmcp)
100
+ - [GitHub](https://github.com/trendsmcp/trendsmcp-js)
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1,6 @@
1
+ export { CustomGrowthPeriod, GetGrowthParams, GetGrowthResponse, GetTopTrendsParams, GetTopTrendsResponse, GetTrendsParams, GetTrendsResponse, GrowthMetadata, GrowthPreset, GrowthResult, TopTrendsFeed, TrendsDataPoint, TrendsMcpClient, TrendsMcpClientOptions, TrendsMcpError, TrendsMcpErrorBody, TrendsSource } from 'trendsmcp';
2
+
3
+ /** Default source for this package. Pass to `source` in any request. */
4
+ declare const SOURCE: "tiktok";
5
+
6
+ export { SOURCE };
@@ -0,0 +1,6 @@
1
+ export { CustomGrowthPeriod, GetGrowthParams, GetGrowthResponse, GetTopTrendsParams, GetTopTrendsResponse, GetTrendsParams, GetTrendsResponse, GrowthMetadata, GrowthPreset, GrowthResult, TopTrendsFeed, TrendsDataPoint, TrendsMcpClient, TrendsMcpClientOptions, TrendsMcpError, TrendsMcpErrorBody, TrendsSource } from 'trendsmcp';
2
+
3
+ /** Default source for this package. Pass to `source` in any request. */
4
+ declare const SOURCE: "tiktok";
5
+
6
+ export { SOURCE };
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SOURCE: () => SOURCE,
24
+ TrendsMcpClient: () => TrendsMcpClient,
25
+ TrendsMcpError: () => TrendsMcpError
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // node_modules/trendsmcp/dist/index.mjs
30
+ var TrendsMcpError = class extends Error {
31
+ constructor(status, body) {
32
+ var _a;
33
+ super(body.message);
34
+ this.name = "TrendsMcpError";
35
+ this.status = status;
36
+ this.code = (_a = body.error) != null ? _a : String(status);
37
+ }
38
+ };
39
+ var BASE_URL = "https://api.trendsmcp.ai/api";
40
+ var TrendsMcpClient = class {
41
+ constructor(options) {
42
+ var _a, _b;
43
+ if (!options.apiKey) {
44
+ throw new Error(
45
+ "TrendsMcpClient: apiKey is required. Get a free key at https://trendsmcp.ai"
46
+ );
47
+ }
48
+ this.apiKey = options.apiKey;
49
+ this.baseUrl = (_b = (_a = options.baseUrl) == null ? void 0 : _a.replace(/\/$/, "")) != null ? _b : BASE_URL;
50
+ }
51
+ async post(body) {
52
+ const res = await fetch(this.baseUrl, {
53
+ method: "POST",
54
+ headers: {
55
+ Authorization: `Bearer ${this.apiKey}`,
56
+ "Content-Type": "application/json"
57
+ },
58
+ body: JSON.stringify(body)
59
+ });
60
+ const envelope = await res.json();
61
+ let parsed;
62
+ if (envelope !== null && typeof envelope === "object" && typeof envelope.statusCode === "number" && typeof envelope.body === "string") {
63
+ parsed = JSON.parse(envelope.body);
64
+ if (envelope.statusCode >= 400) {
65
+ throw new TrendsMcpError(envelope.statusCode, parsed);
66
+ }
67
+ } else {
68
+ if (!res.ok) {
69
+ throw new TrendsMcpError(res.status, envelope);
70
+ }
71
+ parsed = envelope;
72
+ }
73
+ return parsed;
74
+ }
75
+ /**
76
+ * Returns a historical time series for a keyword from a single source.
77
+ *
78
+ * Defaults to 5 years of weekly data. Set `data_mode: "daily"` for the
79
+ * last 30 days at daily granularity.
80
+ *
81
+ * @example
82
+ * const series = await client.getTrends({
83
+ * source: "google search",
84
+ * keyword: "bitcoin",
85
+ * });
86
+ *
87
+ * @example
88
+ * const daily = await client.getTrends({
89
+ * source: "reddit",
90
+ * keyword: "AI agents",
91
+ * data_mode: "daily",
92
+ * });
93
+ */
94
+ getTrends(params) {
95
+ const body = {
96
+ source: params.source,
97
+ keyword: params.keyword
98
+ };
99
+ if (params.data_mode) body.data_mode = params.data_mode;
100
+ return this.post(body);
101
+ }
102
+ /**
103
+ * Calculates point-to-point percentage growth for a keyword over one or
104
+ * more time windows.
105
+ *
106
+ * Accepts preset strings ("12M", "YTD", etc.) or custom date pairs.
107
+ *
108
+ * @example
109
+ * const growth = await client.getGrowth({
110
+ * source: "google search",
111
+ * keyword: "nike",
112
+ * percent_growth: ["12M", "3M", "YTD"],
113
+ * });
114
+ *
115
+ * @example
116
+ * const custom = await client.getGrowth({
117
+ * source: "amazon",
118
+ * keyword: "air fryer",
119
+ * percent_growth: [
120
+ * { name: "holiday season", recent: "2025-12-31", baseline: "2025-10-01" }
121
+ * ],
122
+ * });
123
+ */
124
+ getGrowth(params) {
125
+ const body = {
126
+ source: params.source,
127
+ keyword: params.keyword,
128
+ percent_growth: params.percent_growth
129
+ };
130
+ if (params.data_mode) body.data_mode = params.data_mode;
131
+ return this.post(body);
132
+ }
133
+ /**
134
+ * Returns today's top trending items from live platform feeds.
135
+ * Omit `type` to receive all feeds at once.
136
+ *
137
+ * @example
138
+ * const trending = await client.getTopTrends({ type: "Google Trends", limit: 10 });
139
+ *
140
+ * @example
141
+ * const all = await client.getTopTrends({});
142
+ */
143
+ getTopTrends(params = {}) {
144
+ const body = { mode: "top_trends" };
145
+ if (params.type) body.type = params.type;
146
+ if (params.limit) body.limit = params.limit;
147
+ return this.post(body);
148
+ }
149
+ };
150
+
151
+ // src/index.ts
152
+ var SOURCE = "tiktok";
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ SOURCE,
156
+ TrendsMcpClient,
157
+ TrendsMcpError
158
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,129 @@
1
+ // node_modules/trendsmcp/dist/index.mjs
2
+ var TrendsMcpError = class extends Error {
3
+ constructor(status, body) {
4
+ var _a;
5
+ super(body.message);
6
+ this.name = "TrendsMcpError";
7
+ this.status = status;
8
+ this.code = (_a = body.error) != null ? _a : String(status);
9
+ }
10
+ };
11
+ var BASE_URL = "https://api.trendsmcp.ai/api";
12
+ var TrendsMcpClient = class {
13
+ constructor(options) {
14
+ var _a, _b;
15
+ if (!options.apiKey) {
16
+ throw new Error(
17
+ "TrendsMcpClient: apiKey is required. Get a free key at https://trendsmcp.ai"
18
+ );
19
+ }
20
+ this.apiKey = options.apiKey;
21
+ this.baseUrl = (_b = (_a = options.baseUrl) == null ? void 0 : _a.replace(/\/$/, "")) != null ? _b : BASE_URL;
22
+ }
23
+ async post(body) {
24
+ const res = await fetch(this.baseUrl, {
25
+ method: "POST",
26
+ headers: {
27
+ Authorization: `Bearer ${this.apiKey}`,
28
+ "Content-Type": "application/json"
29
+ },
30
+ body: JSON.stringify(body)
31
+ });
32
+ const envelope = await res.json();
33
+ let parsed;
34
+ if (envelope !== null && typeof envelope === "object" && typeof envelope.statusCode === "number" && typeof envelope.body === "string") {
35
+ parsed = JSON.parse(envelope.body);
36
+ if (envelope.statusCode >= 400) {
37
+ throw new TrendsMcpError(envelope.statusCode, parsed);
38
+ }
39
+ } else {
40
+ if (!res.ok) {
41
+ throw new TrendsMcpError(res.status, envelope);
42
+ }
43
+ parsed = envelope;
44
+ }
45
+ return parsed;
46
+ }
47
+ /**
48
+ * Returns a historical time series for a keyword from a single source.
49
+ *
50
+ * Defaults to 5 years of weekly data. Set `data_mode: "daily"` for the
51
+ * last 30 days at daily granularity.
52
+ *
53
+ * @example
54
+ * const series = await client.getTrends({
55
+ * source: "google search",
56
+ * keyword: "bitcoin",
57
+ * });
58
+ *
59
+ * @example
60
+ * const daily = await client.getTrends({
61
+ * source: "reddit",
62
+ * keyword: "AI agents",
63
+ * data_mode: "daily",
64
+ * });
65
+ */
66
+ getTrends(params) {
67
+ const body = {
68
+ source: params.source,
69
+ keyword: params.keyword
70
+ };
71
+ if (params.data_mode) body.data_mode = params.data_mode;
72
+ return this.post(body);
73
+ }
74
+ /**
75
+ * Calculates point-to-point percentage growth for a keyword over one or
76
+ * more time windows.
77
+ *
78
+ * Accepts preset strings ("12M", "YTD", etc.) or custom date pairs.
79
+ *
80
+ * @example
81
+ * const growth = await client.getGrowth({
82
+ * source: "google search",
83
+ * keyword: "nike",
84
+ * percent_growth: ["12M", "3M", "YTD"],
85
+ * });
86
+ *
87
+ * @example
88
+ * const custom = await client.getGrowth({
89
+ * source: "amazon",
90
+ * keyword: "air fryer",
91
+ * percent_growth: [
92
+ * { name: "holiday season", recent: "2025-12-31", baseline: "2025-10-01" }
93
+ * ],
94
+ * });
95
+ */
96
+ getGrowth(params) {
97
+ const body = {
98
+ source: params.source,
99
+ keyword: params.keyword,
100
+ percent_growth: params.percent_growth
101
+ };
102
+ if (params.data_mode) body.data_mode = params.data_mode;
103
+ return this.post(body);
104
+ }
105
+ /**
106
+ * Returns today's top trending items from live platform feeds.
107
+ * Omit `type` to receive all feeds at once.
108
+ *
109
+ * @example
110
+ * const trending = await client.getTopTrends({ type: "Google Trends", limit: 10 });
111
+ *
112
+ * @example
113
+ * const all = await client.getTopTrends({});
114
+ */
115
+ getTopTrends(params = {}) {
116
+ const body = { mode: "top_trends" };
117
+ if (params.type) body.type = params.type;
118
+ if (params.limit) body.limit = params.limit;
119
+ return this.post(body);
120
+ }
121
+ };
122
+
123
+ // src/index.ts
124
+ var SOURCE = "tiktok";
125
+ export {
126
+ SOURCE,
127
+ TrendsMcpClient,
128
+ TrendsMcpError
129
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "tiktok-trends-api",
3
+ "version": "1.0.0",
4
+ "description": "TikTok hashtag volume over time via REST API. Weekly or daily series, period-over-period growth, and live TikTok trending hashtags. No TikTok API approval needed. Powered by trendsmcp.ai",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "tiktok",
24
+ "tiktok-api",
25
+ "tiktok-trends",
26
+ "hashtag-volume",
27
+ "trend-data",
28
+ "social-media",
29
+ "analytics",
30
+ "growth-rate",
31
+ "viral",
32
+ "trendsmcp"
33
+ ],
34
+ "author": "Trends MCP",
35
+ "license": "MIT",
36
+ "homepage": "https://trendsmcp.ai",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/trendsmcp/trendsmcp-js"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/trendsmcp/trendsmcp-js/issues"
43
+ },
44
+ "devDependencies": {
45
+ "tsup": "^8.0.0",
46
+ "typescript": "^5.0.0",
47
+ "trendsmcp": "^1.0.0"
48
+ }
49
+ }