NPM package for Javascript/Node.js competitive programmers ✨
- To help Javascript/Node.js competitive programmers:
- To start writing code without any boilerplate code
- To debug the code easily by providing input through terminal one by one and check output instantly
- Write the code which use inputReader utility provided by this npm package.
- this package helps in reading input from terminal one by one.
- For example inputReader.readNumber() will wait for user input and return provided input.
- Now simple global command is provided by this package which convert the code, written using inputReader, into the code which is submittable on websites like codechef, topcoder, hackerrank, hackerearth etc.
- First, install the package globally :
Why? Global package will let you use cp-convert command
npm install -g competitive-programming-js
- Now install it locally in the project :
- Initialize the project (If it's not already NPM project)
npm init -y
- Installing the package
npm install --save competitive-programming-js
- Initialize the project (If it's not already NPM project)
-
example.js
const {inputReader} = require('competitive-programming-js'); // To read Number from console let noOfTestCases = inputReader.readNumber(); console.log(noOfCase,typeof noOfCase); while(noOfTestCases--){ // To read generic array separated by space let tmp = inputReader.readArray(); console.log(tmp, typeof tmp); // To read boolean value i.e. 'true' or 'false' (It's case insensitive) tmp = inputReader.readBoolean(); console.log(tmp, typeof tmp); // To read a single character tmp = inputReader.readChar(); console.log(tmp, typeof tmp); // to read a line tmp = inputReader.readLine(); console.log(tmp, typeof tmp); // To read a numeric array tmp = inputReader.readNumberArray(); console.log(tmp, typeof tmp); }
-
Now to convert the file into code which could be submitted on competitive programming websites, run following command:
-
cp-convert --source example.js --destination output.js
OR
-
cp-convert -s example.js -d output.js
-
-
Hurray, that's all. Now you can submit the code which is there in output.js file on any competitive programming website. To learn more in details keep reading :)
-
const {inputReader} = require('competitive-programming-js');
-
Note: Currently, only these two are supported.
const inputReader = require('competitive-programming-js').inputReader;
All of these functions will wait for user input
- readNumber()
- Get a Number from the user
- This can't read the numbers separated by space
- Special Case To read numbers separated by space, you can use following trick:
Note Above code is just using array destructuring.
// Input : 1 2 3 let [a,b,c] = inputReader.readNumberArray() // After above statement a is 1, b is 2 and c is 3
- readBoolean()
- Get the true or false value entered by user on the console.
- 'true' or 'True' or 'TRUE' etc => true (It's case insensitive)
- 'false' or 'False' or 'FALSE' etc => false (It's case insensitive)
- readChar()
- Get a character from the user
- readLine()
- Get a string from the user
- readArray()
- Get a generic array separated by space
- readNumberArray()
- Get a numeric array separated by space
It's a global utility which is used to convert the written code into code which is submittable on competitive programming websites
-
Options:
Flags Use Required --source, -s Source file path YES --destination, --dest, -d Output file path YES --help Show help - -
Example
- cp-convert --source example.js --destination output.js
- cp-convert -s example.js -d output.js
- ES6/ESNext - Write ES6 code and Babel will transpile it to ES5 for backwards compatibility
- Test - Mocha with Istanbul coverage
- Lint - Preconfigured ESlint with Airbnb config
- CI - TravisCI configuration setup
- Minify - Built code will be minified for performance
npm run clean
- Removelib/
directorynpm run test
- Run tests with linting and coverage results.npm run test:only
- Run tests without linting or coverage.npm run test:watch
- You can even re-run tests on file changes!npm run test:prod
- Run tests with minified code.npm run test:examples
- Test is written examples on pure JS for better understanding module usage.npm run lint
- Run ESlint with airbnb-confignpm run cover
- Get coverage report for your code.npm run build
- Babel will transpile ES6 => ES5 and minify the code.npm run prepublish
- Hook for npm. Do all the checks before publishing your module.
MIT © Manish Menaria