nitro-type.js
v2.0.4
Published
A library for interacting with the unofficial Nitro Type API.
Downloads
2
Readme
nitro-type.js
A library for interacting with the unofficial Nitro Type API.
This library consists only of GET requests; no POST requests are included.
Core Contents
These are the core features of this package.
/**
* Fetches data generated by the Nitro Type NTBOOTSTRAP() function.
* @param {Object} [options] - Additional options.
* @param {Boolean} [options.raw=false] - Whether or not to return the data raw from the Nitro Type NTBOOTSTRAP() function.
* @returns {Promise} Resolves to an Object containing Nitro Type data (this includes, but is not limited to: car, sticker, and achievement data).
*/
module.exports.bootstrap = function(options) {
return new Promise(async (resolve, reject) => {
// ...
})
}
/**
* Fetches data on the specified racer.
* @param {String} username - The username of the user you want to search for.
* @returns {Promise} Resolves to an Object containing data on the racer.
*/
module.exports.fetchRacerData = function(username) {
return new Promise(async (resolve, reject) => {
// ...
})
}
/**
* Fetches data on the specified team.
* @param {String} tag - The tag of the team you want to search for.
* @returns {Promise} Resolves to an Object containing data on the team.
*/
module.exports.fetchTeamData = function(tag) {
return new Promise(async (resolve, reject) => {
// ...
})
}
/**
* Fetches data on the last twenty news posts.
* @returns {Promise} Resolves to an Object containing data on last twenty news posts.
*/
module.exports.fetchNewsPosts = function() {
return new Promise(async (resolve, reject) => {
// ...
})
}
/**
* Fetches data on the given news post.
* @param {String|Number} id - The ID of the news post.
* @returns {Promise} Resolves to an Object containing data on the news post.
*/
module.exports.fetchNewsData = function(id) {
return new Promise(async (resolve, reject) => {
// ...
})
}
Additional Contents
These functions take the Core Contents and turn them into something more immediately useful.
/**
* @param {String|Number} searchTerm - The name or ID of the car that you want to fetch data on.
* @param {Object} [options] - Additional options.
* @param {Boolean} [options.case_sensitive=true] - Whether or not the search should be case sensitive.
* @peram {Boolean} [options.exact_match=true] - Whether or not the search should be an exact match. If set to false, the car name can simply include the searchTerm rather than both being exactly equal. Setting this to false will also force options.case_sensitive to set to false.
* @returns {Promise} Resolves to an array of Objects that contain data on each result.
*/
module.exports.fetchCarData = function(searchTerm, options) {
return new Promise(async (resolve, reject) => {
// ...
})
}
Examples
You can demo any of these examples by pasting and running them here.
async function example() {
const nitrotype = require("nitro-type.js");
try { //a try-catch statement for error handling
await nitrotype.fetchRacerData("corndog").then(async data => {
let carURL; // declares a variable to store the image URL
if (data.carHueAngle == 0) { // cars with the default paint job have a different link format than those that are painted
carURL = (await nitrotype.NTBOOTSTRAP()).filter(array => array[0] == "CAR_URL")[0][1]; // fetches the car URL that non-painted cars use ("https://www.nitrotype.com/cars/") and reassigns it to carURL
carURL = carURL + data.carID + "_large_1.png"; // adds the rest of the car URL and reassigns it to carURL
} else {
carURL = (await nitrotype.NTBOOTSTRAP()).filter(array => array[0] == "CAR_PAINTED_URL")[0][1]; // fetches the car URL that painted cars use ("https://www.nitrotype.com/cars/painted/") and reassigns it to carURL
carURL = carURL + data.carID + "_large_1_" + data.carHueAngle + ".png"; // adds the rest of the car URL and reassigns it to carURL
}
console.log(carURL); // prints the URL to the console
})
} catch (error) {
console.log(error);
}
}
example();
async function example() {
const nitrotype = require("nitro-type.js");
try { // a try-catch statement for error handling
await nitrotype.bootstrap().then(data => {
let loot = data.loot; // gets the list of loot
let resultData = loot.filter(sticker => sticker.name == "Good Race!")[0]; // gets info on the particular sticker
console.log(resultData); // prints the sticker's data to the console
})
} catch (error) {
console.log(error);
}
}
example();