├── .buckconfig ├── .flowconfig ├── .gitignore ├── .npmignore ├── .watchmanconfig ├── LICENSE ├── README.md ├── index.js ├── package.json └── trending └── GitHubTrending.js /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.android.js 5 | 6 | # Ignore templates with `@flow` in header 7 | .*/local-cli/generator.* 8 | 9 | # Ignore malformed json 10 | .*/node_modules/y18n/test/.*\.json 11 | 12 | # Ignore the website subdir 13 | /website/.* 14 | 15 | # Ignore BUCK generated dirs 16 | /\.buckd/ 17 | 18 | # Ignore unexpected extra @providesModule 19 | .*/node_modules/commoner/test/source/widget/share.js 20 | 21 | # Ignore duplicate module providers 22 | # For RN Apps installed via npm, "Libraries" folder is inside node_modules/react-native but in the source repo it is in the root 23 | .*/Libraries/react-native/React.js 24 | .*/Libraries/react-native/ReactNative.js 25 | .*/node_modules/jest-runtime/build/__tests__/.* 26 | 27 | [include] 28 | 29 | [libs] 30 | node_modules/react-native/Libraries/react-native/react-native-interface.js 31 | node_modules/react-native/flow 32 | flow/ 33 | 34 | [options] 35 | module.system=haste 36 | 37 | esproposal.class_static_fields=enable 38 | esproposal.class_instance_fields=enable 39 | 40 | experimental.strict_type_args=true 41 | 42 | munge_underscores=true 43 | 44 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 45 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 46 | 47 | suppress_type=$FlowIssue 48 | suppress_type=$FlowFixMe 49 | suppress_type=$FixMe 50 | 51 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-9]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 52 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-9]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 53 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 54 | 55 | unsafe.enable_getters_and_setters=true 56 | 57 | [version] 58 | ^0.29.0 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | .idea/ 6 | 7 | 8 | # Xcode 9 | # 10 | build/ 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | xcuserdata 20 | *.xccheckout 21 | *.moved-aside 22 | DerivedData 23 | *.hmap 24 | *.ipa 25 | *.xcuserstate 26 | project.xcworkspace 27 | 28 | # Android/IJ 29 | # 30 | *.iml 31 | .idea 32 | .gradle 33 | local.properties 34 | 35 | # node.js 36 | # 37 | node_modules/ 38 | npm-debug.log 39 | 40 | # BUCK 41 | buck-out/ 42 | \.buckd/ 43 | android/app/libs 44 | android/keystores/debug.keystore 45 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | Screenshots 3 | .gif 4 | *.iml 5 | # OSX 6 | # 7 | .DS_Store 8 | # Xcode 9 | # 10 | build/ 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | xcuserdata 20 | *.xccheckout 21 | *.moved-aside 22 | DerivedData 23 | *.hmap 24 | *.ipa 25 | *.xcuserstate 26 | 27 | # node.js 28 | # 29 | node_modules/ 30 | npm-debug.log 31 | examples 32 | 33 | .buckconfig 34 | .flowconfig 35 | .watchmanconfig 36 | /android/build 37 | /android/RCTWeChat.iml 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jia PengHui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHubTrending 2 | 3 | [![Download](https://img.shields.io/badge/Download-v5.0.0-ff69b4.svg) ](https://www.npmjs.com/package/GitHubTrending) 4 | [ ![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/crazycodeboy/GitHubTrending/pulls) 5 | 6 | This is a library for fetch object data from "https://github.com/trending". 7 | 8 | 9 | 10 | ## Installation 11 | 12 | Run `npm i GitHubTrending --save` 13 | 14 | ## Usage 15 | 16 | ```JavaScript 17 | const AUTH_TOKEN = '输入最新的token'; 18 | new GitHubTrending(AUTH_TOKEN).fetchTrending(url) 19 | .then((data)=> { 20 | // 21 | }).catch((error)=> { 22 | // 23 | }); 24 | ``` 25 | token从[https://coding.imooc.com/class/304.html](https://coding.imooc.com/class/304.html)的问答区获取。 26 | 27 | 28 | TrendingRepoModel 29 | ------- 30 | 31 | ```js 32 | export default class TrendingRepoModel { 33 | constructor(fullName, url, description, language, meta, contributors, contributorsUrl, starCount, forkCount) { 34 | this.fullName = fullName; 35 | this.url = url; 36 | this.description = description; 37 | this.language = language; 38 | this.meta = meta; 39 | this.contributors = contributors; 40 | this.contributorsUrl = contributorsUrl; 41 | this.starCount = starCount; 42 | this.forkCount = forkCount; 43 | } 44 | } 45 | 46 | ``` 47 | 48 | 49 | ```js 50 | contributors: (5) ["https://avatars3.githubusercontent.com/u/1316332?s=40&v=4", "https://avatars1.githubusercontent.com/u/90494?s=40&v=4", "https://avatars1.githubusercontent.com/u/379606?s=40&v=4", "https://avatars1.githubusercontent.com/u/1151041?s=40&v=4", "https://avatars2.githubusercontent.com/u/1348527?s=40&v=4"] 51 | contributorsUrl: "d-inline-block" 52 | description: "The Expo platform for making cross-platform mobile apps" 53 | forkCount: "730" 54 | fullName: "expo/expo" 55 | language: "Objective-C" 56 | meta: "9 stars today" 57 | starCount: "6,466" 58 | url: "/expo/expo" 59 | ``` 60 | 61 | >More examples can refer to [GitHubPopular](https://github.com/crazycodeboy/GitHubPopular) 62 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 从https://github.com/trending获取数据 4 | * https://github.com/crazycodeboy 5 | * @flow 6 | */ 7 | import GitHubTrending from './trending/GitHubTrending'; 8 | 9 | module.exports=GitHubTrending -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GitHubTrending", 3 | "version": "5.0.0", 4 | "description": "This is a library for obtaining https://github.com/trending data.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/crazycodeboy/GitHubTrending.git" 12 | }, 13 | "keywords": [ 14 | "GitHubTrending", 15 | "Trending", 16 | "open source" 17 | ], 18 | "author": "crazycodeboy", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/crazycodeboy/GitHubTrending/issues" 22 | }, 23 | "peerDependencies": { 24 | "react-native": ">=0.20.0" 25 | }, 26 | "homepage": "https://github.com/crazycodeboy/GitHubTrending#readme" 27 | } 28 | -------------------------------------------------------------------------------- /trending/GitHubTrending.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 从https://github.com/trending获取数据 3 | * 项目地址:https://github.com/crazycodeboy/GitHubTrending 4 | * 博客地址:http://www.devio.org 5 | * @flow 6 | */ 7 | const FILTER_URLS = [ 8 | { 9 | from: 'https://github.com/trending/All Language?', 10 | to: 'https://github.com/trending?', 11 | }, 12 | ]; 13 | const URL = 'http://api.devio.org/as/trending?sourceUrl='; 14 | export default class GitHubTrending { 15 | constructor(authToken) {//Singleton pattern 16 | if (typeof GitHubTrending.instance === 'object') { 17 | return GitHubTrending.instance; 18 | } 19 | this.authToken = authToken; 20 | GitHubTrending.instance = this; 21 | } 22 | 23 | fetchTrending(url) { 24 | url = this.filterUrl(url); 25 | url = `${URL}${url}`; 26 | return new Promise((resolve, reject) => { 27 | fetch(url, {headers: {'auth-token': this.authToken}}) 28 | .then((response) => { 29 | return response.json(); 30 | }) 31 | .then((responseData) => { 32 | if (responseData['code'] === 0) { 33 | resolve(responseData['data']['list']); 34 | } else { 35 | throw new Error(JSON.stringify(responseData)); 36 | } 37 | 38 | }) 39 | .catch((error) => { 40 | reject(error); 41 | }); 42 | }); 43 | } 44 | 45 | filterUrl(url) { 46 | for (let i = 0; i < FILTER_URLS.length; i++) { 47 | let val = FILTER_URLS[i]; 48 | if (url.startsWith(val.from)) { 49 | return url.replace(val.from, val.to); 50 | } 51 | } 52 | return url; 53 | } 54 | } 55 | 56 | --------------------------------------------------------------------------------