Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const {
| Function | Description | Parameters | Returns | |
| --------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------- |
| `topAuthors(limit?)` | Fetches authors sorted by total views | `limit` (number, default `10`): number of authors to return (1–50) | `Author[]` | |
| `authorPosts(name, limit?, sort?)` | Retrieves published posts by a given author | `name` (string): display name and profile ID (e.g., "jane-doe-123")<br>`limit` (number, default `10`)<br>`sort` ("newest" | "most\_viewed", default "newest") | `Post[]` |
| `authorPosts(tag, limit?, sort?)` | Retrieves published posts by a given author | `tag` (string): display name and profile ID (e.g., "jane-doe-123")<br>`limit` (number, default `10`)<br>`sort` ("newest" | "most\_viewed", default "newest") | `Post[]` |
| `getTags(limit?)` | Returns tags with their associated post counts | `limit` (number, default `20`): number of tags (1–100) | `Tag[]` | |
| `explore(search?, page?, limit?, sort?, tag?)` | Paginated list of articles with filtering and sorting | `search` (string)<br>`page` (number, default `1`)<br>`limit` (number, default `12`)<br>`sort` ("recommended" | | |
| "newest" | | | | |
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@persian-caesar/hycom-api",
"version": "1.1.1",
"version": "1.1.2",
"description": "A package for easy using hycom.ir api service.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -33,4 +33,4 @@
"devDependencies": {
"@types/node": "^22.15.21"
}
}
}
11 changes: 7 additions & 4 deletions src/HyCom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ async function topAuthors(limit: number = 10) {
const response = await fetch(hycom.url + hycom.topAuthor + `?limit=${limit}`);
const data: TopAuthorResponse = await response.json();

return data.data;
return data.data.map(a => {
a.tag = a.display_name + "-" + a.profile_id
return a;
});
} catch {
return null;
}
Expand All @@ -199,13 +202,13 @@ async function topAuthors(limit: number = 10) {
/**
* Returns published posts by a specific author.
*
* @param display_name Author display name and profile ID. (format: name-code)
* @param tag Author display name and profile ID. (format: name-code)
* @param limit Number of authors to return. (1-50)
* @param sort Sort order. (newest, most_viewed)
*/
async function authorPosts(display_name: string, limit: number = 10, sort: SortParametr = "newest") {
async function authorPosts(tag: string, limit: number = 10, sort: SortParametr = "newest") {
try {
const response = await fetch(hycom.url + hycom.authorPosts + `/${display_name}?limit=${limit}&sort=${sort}`);
const response = await fetch(hycom.url + hycom.authorPosts + `/${tag}?limit=${limit}&sort=${sort}`);
const data: AuthorPostsResponse = await response.json();

return data.data;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type SortParametr = "newest" | "most_viewed";
export type ExploreSortParametr = "recommended" | SortParametr;

export interface Author {
tag: string;
display_name: string;
profile_id: string;
url: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "ES2024", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "libReplacement": true, /* Enable lib replacement. */
Expand Down