Skip to content

Commit

Permalink
Merge pull request #4 from arifszn/rename-devto
Browse files Browse the repository at this point in the history
Rename dev from dev.to
  • Loading branch information
arifszn authored Mar 29, 2022
2 parents d64d7cf + 0e7152f commit e7da8ff
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ yarn add @arifszn/blog-js

## Usage

- **getDevtoPost()**: Get 10 recent posts from [dev.to](https://dev.to)
- **getDevPost()**: Get 10 recent posts from [dev](https://dev.to)

```js
const { getDevtoPost } = require('@arifszn/blog-js');
const { getDevPost } = require('@arifszn/blog-js');

getDevtoPost({
getDevPost({
user: 'yourusername',
}).then((res) => {
console.log(res);
Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface options {
declare function getMediumPost(options: options): Promise<R>;

/**
* Get most recent dev.to posts
* Get most recent dev posts
*/
declare function getDevtoPost(options: options): Promise<R>;
declare function getDevPost(options: options): Promise<R>;

export { getMediumPost, getDevtoPost };
export { getMediumPost, getDevPost };
72 changes: 36 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const { request, formatMediumPost, formatDevtoPost } = require("./util");
const { request, formatMediumPost, formatDevPost } = require('./util');

module.exports = {
/**
* Get most recent medium posts
*
* @param {Object} param
* @returns {Array} posts
*/
getMediumPost: async ({
user
}) => {
try {
if (!user) return [];
/**
* Get most recent medium posts
*
* @param {Object} param
* @returns {Array} posts
*/
getMediumPost: async ({ user }) => {
try {
if (!user) return [];

let response = await request(`https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@${user}`);
let response = await request(
`https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@${user}`
);

return response.data.items.map(item => formatMediumPost(item));
} catch (error) {
return [];
}
},
/**
* Get most recent dev.to posts
*
* @param {Object} param
* @returns {Array} posts
*/
getDevtoPost: async ({
user
}) => {
try {
if (!user) return [];
let response = await request(`https://dev.to/api/articles?per_page=10&username=${user}`);
return response.data.items.map((item) => formatMediumPost(item));
} catch (error) {
return [];
}
},
/**
* Get most recent dev posts
*
* @param {Object} param
* @returns {Array} posts
*/
getDevPost: async ({ user }) => {
try {
if (!user) return [];

let response = await request(
`https://dev.to/api/articles?per_page=10&username=${user}`
);

return response.data.map(item => formatDevtoPost(item));
} catch (error) {
return [];
}
return response.data.map((item) => formatDevPost(item));
} catch (error) {
return [];
}
}
},
};
6 changes: 3 additions & 3 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ const formatMediumPost = (post) => {
};

/**
* Format raw dev.to post
* Format raw dev post
*
* @param {Object} post
* @return {Object} formatted post
*/
const formatDevtoPost = (post) => {
const formatDevPost = (post) => {
return {
title: post.title.trim(),
description: post.description.replace('\n', '').trim(),
Expand Down Expand Up @@ -73,4 +73,4 @@ const textEllipsis = (str, length = 100, ending = '...') => {

module.exports.request = request;
module.exports.formatMediumPost = formatMediumPost;
module.exports.formatDevtoPost = formatDevtoPost;
module.exports.formatDevPost = formatDevPost;

0 comments on commit e7da8ff

Please sign in to comment.