Need some code for your project? We've got you covered.
Choose your language. Choose how many lines.
BÄM! You got code.
First, install dependencies and run the development server:
npm i
npm run dev
Open http://localhost:3000 with your browser to see the result.
The following instructions will guide you through how to add a new language to the generator.
- Add a new file in tools/utils named {language}.js
- There are some helper functions available in tools/utils/helpers.js so the first step in your new file is to import those functions:
import {
getRandomEntry,
getRandomInt,
getRandomNounUpperCase,
getRandomVerbUpperCase,
getRandomLogLine,
} from "./helpers";
It is worth looking at helpers.js in case any of the other functions are applicable to your language, or in case some are in fact not needed at all and don't need to be imported in your file.
- In your new, create a new JavaScript class with the name of your language
export default class <insert language name here> {
}
- If your language uses functions with access modifers or return types, create a static function for this that returns a string wrapped in ``to define this. See
static getRandomMethodName()
in csharp.js for an example - Create a static function called
getRandomFunctionName
orgetRandomMethodName
depending on your language as required which builds up the name using functions from helper.js - Create a static function called
getRandomVariableDeclation
, define the common keywords from your language, that returns a random variable declaration using functions from helper.js such asgetRandomEntry(keywords)
. See javascript.js for an example - Create a function that will return some random log lines from the helper file. Name this after how your language words output. For example csharp.js has
getRandomDebugWriteLine
and javascript.js hasgetRandomConsoleLog
- Inside this function, paste the following
const options = getLogLines();
return getRandomEntry(options);
- We now want to create some silly filler lines so create the following function in your file and update it reflect your language syntax and file name
static getRandomFillerLine() {
const options = [
`console.log(${JavaScript.getRandomConsoleLog()});`,
JavaScript.getRandomVariableDeclaration(),
`${JavaScript.getRandomFunctionName()}();`,
];
return getRandomEntry(options);
}
- Save your file as it is now time to use it
- Open tools/RandomCodeGenerator.js
- Import the reference to your language file, following the pattern of the existing code
- Add your language to the list of languages. The name cannot have special characters but the value as a string is how the language will appear on the buttons so straight text will work such as the existing C++
- After the last case statement but before default, add the word case followed by your language name in quotes and followed by a colon (: symbol)
- Assign a string surrounded by ``to
firstLine
that reflects how a method or function is declared in your language - Paste the following after your
firstLine
assignment, updating to reflect your language syntax and file name, for example:
for (let i = 1; i <= fillerLineQty; i++) {
fillerLines.push(` ${CPlusPlus.getRandomFillerLine()}`);
}
lastLine = "${addNewLine()}}";
return firstLine + fillerLines.join(addNewLine()) + lastLine;
- Open languages.js and add your language to the Languages object
- Open contributors.js and add your GitHub username to the Contributors object at the top of the file
- Make sure everything is saved, then take a look at your changes on http://localhost:3000
npm run dev
- Check the page is displaying correctly and enjoy your hard work :)
- If it all runs and displays your language correctly, submit a PR to the original repo and celebrate 🎉
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
This is a Next.js project bootstrapped with create-next-app
.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.