wordle-cli
Advanced tools
Comparing version 1.0.1 to 1.0.2
const fs = require('fs') | ||
const path = require('path') | ||
let buffer = fs.readFileSync(path.join(__dirname, 'words.json')) | ||
let words = JSON.parse(buffer) | ||
let wordsBuffer = fs.readFileSync(path.join(__dirname, 'words.json')) | ||
let words = JSON.parse(wordsBuffer) | ||
const getWord = (date = new Date(),random) => { | ||
let validWordsBuffer = fs.readFileSync(path.join(__dirname, 'validWords.json')) | ||
let validWords = JSON.parse(validWordsBuffer) | ||
if(random) { | ||
const validateWord = (word) => { | ||
if (words.includes(word) || validWords.includes(word)) { | ||
return true | ||
} | ||
} | ||
const getWord = (date = new Date(), random) => { | ||
if (random) { | ||
return words[Math.floor(Math.random() * words.length)].toUpperCase().split('') | ||
@@ -17,5 +25,4 @@ } | ||
return words[index].toUpperCase().split('') | ||
} | ||
module.exports = getWord | ||
module.exports = { getWord, validateWord } |
#! /usr/bin/env node | ||
const { createInterface } = require('readline') | ||
const getWord = require('./getWord') | ||
const { getWord, validateWord } = require('./getWord') | ||
const getOptions = require('./getOptions') | ||
@@ -31,2 +31,8 @@ const showWord = require('./showWord') | ||
return | ||
} else if (!validateWord(input.toLowerCase())) { | ||
console.log(`\n${input.toUpperCase()} is not a valid word!\n`) | ||
round() | ||
return | ||
} else if (!options.unlimited) { | ||
currentRound++ | ||
} | ||
@@ -82,4 +88,3 @@ | ||
// Start new round or end game | ||
if (currentRound < rounds - 1 && !gameWon) { | ||
if (!options.unlimited) currentRound++ | ||
if (currentRound < rounds && !gameWon) { | ||
round() | ||
@@ -103,3 +108,3 @@ } else { | ||
// Start game | ||
if(options.help) { | ||
if (options.help) { | ||
messages.title() | ||
@@ -106,0 +111,0 @@ messages.help() |
@@ -0,1 +1,12 @@ | ||
const formattingCodes = { | ||
green: [30, 42], | ||
yellow: [30, 43], | ||
none: [1, 37, 40], | ||
reset: [0], | ||
} | ||
const format = (color = 'reset') => `\x1b[${formattingCodes[color].join(';')}m` | ||
const endTile = () => format() + ' ' | ||
const insertSpaces = (num) => new Array(num + 1).join(' ') | ||
const showWord = (result) => { | ||
@@ -5,26 +16,10 @@ let topBottom = '' | ||
result.forEach((item) => { | ||
switch (item.color) { | ||
case 'green': | ||
topBottom += `\x1b[30;42m \x1b[0m ` | ||
middle += `\x1b[30;42m ${item.letter} \x1b[0m ` | ||
break | ||
case 'yellow': | ||
topBottom += `\x1b[43;30m \x1b[0m ` | ||
middle += `\x1b[43;30m ${item.letter} \x1b[0m ` | ||
break | ||
default: | ||
topBottom += `\x1b[1;30;37m \x1b[0m ` | ||
middle += `\x1b[1;30;37m ${item.letter} \x1b[0m ` | ||
break | ||
} | ||
result.forEach(({ color, letter }) => { | ||
topBottom += format(color) + insertSpaces(7) + endTile() | ||
middle += format(color) + insertSpaces(3) + letter + insertSpaces(3) + endTile() | ||
}) | ||
console.log('\n') | ||
console.log(topBottom) | ||
console.log(middle) | ||
console.log(topBottom) | ||
console.log('\n') | ||
console.log(`\n\n${topBottom}\n${middle}\n${topBottom}\n\n`) | ||
} | ||
module.exports = showWord |
{ | ||
"name": "wordle-cli", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "CLI interpretation of the game Wordle", | ||
@@ -5,0 +5,0 @@ "main": "bin/index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
152953
9
13225
1