├── .gitignore ├── .gitattributes ├── .travis.yml ├── test.js ├── .editorconfig ├── index.js ├── package.json ├── readme.md └── license /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from '.'; 3 | 4 | test(async t => { 5 | await t.notThrows(m(process.env.GITHUB_TOKEN)); 6 | }); 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const ghGot = require('gh-got'); 3 | 4 | module.exports = token => { 5 | if (typeof token !== 'string') { 6 | return Promise.reject(new TypeError('Expected a string')); 7 | } 8 | 9 | return ghGot('user', { 10 | json: true, 11 | token 12 | }).then(res => res.body); 13 | }; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-token-user", 3 | "version": "3.0.0", 4 | "description": "Get the Github user from a token", 5 | "license": "MIT", 6 | "repository": "kevva/github-token-user", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "api", 23 | "github", 24 | "token", 25 | "user" 26 | ], 27 | "dependencies": { 28 | "gh-got": "^5.0.0" 29 | }, 30 | "devDependencies": { 31 | "ava": "*", 32 | "xo": "*" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # github-token-user [![Build Status](https://travis-ci.org/kevva/github-token-user.svg?branch=master)](https://travis-ci.org/kevva/github-token-user) 2 | 3 | > Get the GitHub user from a token 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save github-token-user 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const githubTokenUser = require('github-token-user'); 17 | 18 | githubTokenUser('523ef6911917').then(data => { 19 | console.log(data); 20 | //=> {login: johndoe, id: '1', ...} 21 | }); 22 | ``` 23 | 24 | ## API 25 | 26 | ### githubTokenUser(token) 27 | 28 | Returns a Promise for a user. 29 | 30 | #### token 31 | 32 | Type: `string` 33 | 34 | Token to get the user from. 35 | 36 | 37 | ## Related 38 | 39 | * [github-token-user-cli](https://github.com/kevva/github-token-user-cli) - CLI for this module 40 | 41 | 42 | ## License 43 | 44 | MIT © [Kevin Mårtensson](https://github.com/kevva) 45 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Mårtensson 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 13 | all 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 21 | THE SOFTWARE. 22 | --------------------------------------------------------------------------------