Comparing version 1.0.1 to 2.0.0
@@ -1,1 +0,1 @@ | ||
module.exports = require('./src/Client'); | ||
module.exports = require('./src/Client'); |
{ | ||
"name": "fortnite", | ||
"version": "1.0.1", | ||
"description": "An easy to use module for interacting with the Fortnite API.", | ||
"version": "2.0.0", | ||
"description": "Fortnite leaderboards.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -11,12 +11,9 @@ # Fortnite | ||
// require the package | ||
const Fortnite = require('fortnite'); | ||
// instantiate the client | ||
const client = new Fortnite.Client(); | ||
const fortnite = require('fortnite'); | ||
``` | ||
## Methods | ||
```js | ||
client.info('mrappi', 'pc').then(data => data); | ||
client.stats('mrappi', 'pc').then(data => data); | ||
fortnite('mrappi', 'pc').then(console.log); | ||
``` | ||
- `username` is required and must be a string. | ||
- `platform` is `pc` by default and currently only supports PC. | ||
- `platform` is `pc` by default. Possible platforms are: `pc`, `xbox` `psn`. |
const Info = require('./Info'); | ||
const Stats = require('./Stats'); | ||
const Stat = require('./Stat'); | ||
const Data = require('./Data'); | ||
const { get } = require('snekfetch'); | ||
const { load } = require('cheerio'); | ||
class Client { | ||
info(username, platform = 'pc') { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof username !== 'string' || typeof username === 'undefined') reject('You must supply a username to search.'); | ||
/** | ||
* @param {string} username The username of the player | ||
* @param {string} platform Either `pc` `psn` or `xbox` | ||
* @returns {Promise<Object>} Object containing info for this player | ||
*/ | ||
const { text } = await get(`https://fortnitetracker.com/profile/${platform.toLowerCase()}/${username}`); | ||
const $ = load(text); | ||
if (!$('#profile').length) throw new Error('404'); | ||
const json = {}; | ||
$('script:contains(var)').each((i, el) => { | ||
const text = $(el).html(); | ||
if (!text.startsWith('var ')) return; | ||
json[text.split(' ')[1]] = JSON.parse(text.match(/\[?{.*}\]?/)[0]); | ||
}); | ||
resolve(new Info(json.accountInfo)); | ||
}); | ||
} | ||
module.exports = (username, platform = 'pc') => { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof username !== 'string' || typeof username === 'undefined') reject('You must supply a username to search for.'); | ||
stats(username, platform = 'pc') { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof username !== 'string' || typeof username === 'undefined') reject('You must supply a username to search.'); | ||
const { text } = await get(`https://fortnitetracker.com/profile/${platform.toLowerCase()}/${username}`); | ||
const $ = load(text); | ||
if (!$('#profile').length) throw new Error('404'); | ||
const json = {}; | ||
$('script:contains(var)').each((i, el) => { | ||
const text = $(el).html(); | ||
if (!text.startsWith('var ')) return; | ||
json[text.split(' ')[1]] = JSON.parse(text.match(/\[?{.*}\]?/)[0]); | ||
}); | ||
resolve(new Stats(json.LifeTimeStats)); | ||
const { text } = await get(`https://fortnitetracker.com/profile/${platform.toLowerCase()}/${username}`); | ||
const $ = load(text); | ||
if (!$('#profile').length) throw new Error('404'); | ||
const json = {}; | ||
$('script:contains(var)').each((i, el) => { | ||
const text = $(el).html(); | ||
if (!text.startsWith('var ')) return; | ||
json[text.split(' ')[1]] = JSON.parse(text.match(/\[?{.*}\]?/)[0]); | ||
}); | ||
} | ||
} | ||
module.exports.Client = Client; | ||
resolve({ | ||
info: new Info(json.accountInfo), | ||
lifetimeStats: json.LifeTimeStats.map(stat => new Stat(stat)), | ||
group: { | ||
solo: json.playerData.p2 === undefined ? null : json.playerData.p2.map(data => new Data(data)), | ||
duo: json.playerData.p10 === undefined ? null : json.playerData.p10.map(data => new Data(data)), | ||
squad: json.playerData.p9 === undefined ? null : json.playerData.p9.map(data => new Data(data)) | ||
} | ||
}); | ||
}); | ||
}; |
@@ -10,5 +10,7 @@ class Info { | ||
const platforms = { | ||
'3': 'pc' | ||
1: 'xbox', | ||
2: 'psn', | ||
3: 'pc' | ||
}; | ||
module.exports = Info; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
3189
19