is-odd-code-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

is-odd-code-generator

CI NPM version NPM monthly downloads

Have you been looking for a npm package that can generate JavaScript code that can determine if a number is odd or not? Look no further. This package takes in a positive integer value, then generates JS code that can determine if a number is odd or not up to and including the supplied positive integer value.

Install

Install with npm:

npm install is-odd-code-generator

Usage

Only supports positive integers as input

import { generateIsOddCode } from 'is-odd-code-generator';

console.log(generateIsOddCode(-1)) // throws Error since the given number is negative

console.log(generateIsOddCode(0));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
// }
console.log(generateIsOddCode(10));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
//   else if(number === 1) return true;
//   else if(number === 2) return false;
//   else if(number === 3) return true;
//   else if(number === 4) return false;
//   else if(number === 5) return true;
//   else if(number === 6) return false;
//   else if(number === 7) return true;
//   else if(number === 8) return false;
//   else if(number === 9) return true;
//   else if(number === 10) return false;
// }
console.log(generateIsOddCode(15));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
//   else if(number === 1) return true;
//   else if(number === 2) return false;
//   else if(number === 3) return true;
//   else if(number === 4) return false;
//   else if(number === 5) return true;
//   else if(number === 6) return false;
//   else if(number === 7) return true;
//   else if(number === 8) return false;
//   else if(number === 9) return true;
//   else if(number === 10) return false;
//   else if(number === 11) return true;
//   else if(number === 12) return false;
//   else if(number === 13) return true;
//   else if(number === 14) return false;
//   else if(number === 15) return true;
// }
Running Tests

In order to run tests, first install the packages then run the tests. Like so:

pnpm install && pnpm test
Building package

In order to build the package, run the following command:

pnpm build

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

License

Released under the MIT License.


Package Sidebar

Install

npm i is-odd-code-generator

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

10.8 kB

Total Files

9

Last publish

Collaborators

  • anmolshres