UNPKG

avamaxboobs

Version:

A package for randomly selecting images of various people's boobs. Intended to be used for discord bot commands.

26 lines (20 loc) 958 B
const fs = require('fs'); const path = require('path'); /** * Gets the number of items in a list * @param {string} list The list to get the length of * @returns {Promise<number>} The number of items in the list * @example const avamaxboobslength = await getLength('avamaxboobs') */ async function getLength(list){ if(!list) throw new Error('You didn\'t provide a list to get the length of'); const folder = fs.readdirSync(path.join(__dirname.slice(0,__dirname.length-15),'lists')); if(!folder.includes(`${list}.json`)) throw new Error(`Invalid list. List must be one of the following: ${folder.map(file=>file.slice(0,file.length-5)).join(', ')}`) const listfile = fs.readFileSync(path.join(__dirname.slice(0,__dirname.length-15),'lists',`${list}.json`)) const keys = Object.keys(JSON.parse(listfile.toString())) const val = JSON.parse(listfile.toString())[keys] return val.length; } module.exports={ getLength }