npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fake-person

v1.2.1

Published

A library for creating a fake person with mock properties and simple ai capabilities.

Downloads

438

Readme

fake-person

fake-person is a JavaScript library that allows you to easily generate user(s) with randomized mock properties, and simple AI capabilities.

This library will come in handy when you need to generate dummy user data or if you need an AI player for simple games such as guess the number, the hanging man, rock paper scissors, quizzes, black jack, etc.

🚨 NOTICE: This library was created for a school project.

Installation

Using npm:

npm i fake-person

Usage

Dummy user data

Each fake person instantiated will get their own unique set of randomized properties that can be accessed with getter methods:

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

fakePerson.getFullName() // Helge Svensson
fakePerson.getFirstName() // Helge
fakePerson.getLastName() // Svensson
fakePerson.getGender() // male
fakePerson.getAge() // 45
fakePerson.getCountry() // Sweden
fakePerson.getEmail() // [email protected]
fakePerson.getPassword() // $5Ab!7Ox&9Pa
fakePerson.getDescription() // Hello, my name is Helge Svensson and I am 45 years old. I live in Sweden and you can contact me at [email protected].

Simple AI Capabilities

Beside generating fake user data, a fake person can also be used as an AI player for simple games as demonstrated below.

makeSelectionFromArray(options)

options: An array with more than one item

Method that returns a random element from an array.

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

// Example use case: Guess the number
const correctNumber = 7
const numbers = [...Array(10).keys()]
const aiNumberGuess = fakePerson.makeSelectionFromArray(numbers) // example output: 4

// Example use case: The hanging man
const correctWord = 'jazz'
const availableLetters = 'abcdefghijklmnopqrstuvxyz'.split('')
const aiLetterGuess = fakePerson.makeSelectionFromArray(availableLetters) // example output: j

getDiceValue(faces, numOfDice)

faces: A positive number

numOfDice: A positive number

Method that returns an array containing the result of one or more dice rolls.

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

const rollOneDice = fakePerson.getDiceValue(6, 1) // example output: [4] 
const rollTwoDice = fakePerson.getDiceValue(6, 2) // example output: [2, 6] 
const rollThreeDice = fakePerson.getDiceValue(10, 3) // example output: [9, 3, 5] 

playRockPaperScissors()

Method that simulates an AI's choice in rock, paper, scissors, by returning either "rock", "paper" or "scissors".

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

const aiHand = fakePerson.playRockPaperScissors() // example output: paper 

answerQuizQuestion({ options, correctAnswer }, skillLevel)

options: An array with more than one item

correctAnswer: A string that must exist in the options array

skillLevel: A string that equals either 'beginner', 'average' or 'expert' (defaults to: average)

Method that simulates an AI's answer to a quiz question by returning an option from the provided options array. The probability that the returned option is the correctAnswer is based on the skillLevel:

  • a beginner AI is 60% likely to return an option that match the correctAnswer
  • an average AI is 70% likely to return an option that match the correctAnswer
  • an expert AI is 80% likely to return an option that match the correctAnswer
import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

const question = {
	text: 'What is the capital of Sweden?',
	options: ['Helsinki', 'Stockholm', 'Copenhagen', 'Oslo'],
	correctAnswer: 'Stockholm'
}

const beginnerAiAnswer = fakePerson.answerQuizQuestion(question, 'beginner') // example output: Helsinki
const averageAiAnswer = fakePerson.answerQuizQuestion(question, 'average') // example output: Oslo
const expertAiAnswer = fakePerson.answerQuizQuestion(question, 'expert') // example output: Stockholm

shouldGetNewCard(currentScore, mode)

currentScore: A whole number

mode: A string that equals either 'risky' or 'safe' (defaults to: safe)

Method that simulates an AI's decision whether to receive a new card in the game of Black Jack by returning either true or false based on currentScore and mode.

A 'risky' AI will continue as long as currentScore is 18 and below while a 'safe' AI will continue as long as currentScore is 16 and below.

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

const aiScore = fakePerson.getScore()

if (fakePerson.shouldGetNewCard(aiScore, 'risky')) {
	// Hit AI with a new card
}

Keeping Score

import FakePerson from 'fake-person'

const fakePerson = new FakePerson()

// Get score
const currentScore = fakePerson.getScore() // 0

// Set score
fakePerson.setScore(currentScore + 10)

Version

1.0.0

License

ISC