Skip to content

Commit

Permalink
feat(init): updated using generator-node-mdl v4.1.0 πŸ”₯
Browse files Browse the repository at this point in the history
  • Loading branch information
sharvit committed Dec 28, 2019
1 parent 95e4d48 commit 388d7e0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 20 deletions.
4 changes: 1 addition & 3 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const path = require('path');

const config = {
mode: 'production',
target: 'node',

entry: path.resolve(__dirname, '../src/index.js'),

output: {
path: path.resolve(__dirname, '../dist'),
filename: 'index.js',
library: 'node-mdl-starter',
globalObject: 'this',
libraryTarget: 'umd',
},

Expand Down
8 changes: 5 additions & 3 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ Build the project:
```sh
yarn build
# only build the dist folder from source
yarn build:babel
yarn webpack:build
# build webpack with a development mode and watch files
yarn webpack:develop
# only build the docs using esdocs
yarn build:docs
yarn docs:build
# build docs in watch mode
yarn develop:docs
yarn docs:develop
```

Run linter to validate the project code:
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
},
"scripts": {
"prebuild": "rimraf dist",
"build": "yarn build:webpack && yarn build:docs",
"build:webpack": "webpack --config ./config/webpack.config.js",
"build:docs": "esdoc -c ./config/esdoc.config.js",
"develop:docs": "watch \"yarn build:docs\" . --ignoreDirectoryPattern='/node_modules|docs|dist|coverage|.git|.nyc*./'",
"build": "yarn webpack:build && yarn docs:build",
"webpack:build": "webpack --mode production --config ./config/webpack.config.js",
"webpack:develop": "webpack --mode development --watch --watch-poll --config ./config/webpack.config.js",
"docs:build": "esdoc -c ./config/esdoc.config.js",
"docs:develop": "watch \"yarn docs:build\" . --ignoreDirectoryPattern='/node_modules|docs|dist|coverage|.git|.nyc*./'",
"test:watch": "jest --config ./config/jest.config.js --watch",
"test": "jest --config ./config/jest.config.js --coverage",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
Expand Down
31 changes: 31 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ nodeMdlStarter('some text');
//=> some text
```

## Usage

```js
import nodeMdlStarter, { isEven, isOdd } from 'node-mdl-starter';

nodeMdlStarter('some text');
//=> some text

isEven(8);
//=> true
isEven(9);
//=> false
isOdd(8);
//=> false
isOdd(9);
//=> true
```

If you are not able to use `es-modules`, you can use `require` instead of `import`
```js
const { default: nodeMdlStarter, isEven, isOdd } = require('node-mdl-starter');
```

To use it directly inside a browser, load it via a script `tag`:
```html
<script type="text/javascript" src="./node_modules/node-mdl-starter/dist/index.js"></script>
<script type="text/javascript">
const { default: nodeMdlStarter, isEven, isOdd } = window['node-mdl-starter'];
</script>
```

## Related

// TODO
Expand Down
22 changes: 18 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
export default (input = 'No args passed!') => input;

/**
* Return the passed argument as is.
* @param {String} [input='No args passed!'] input argument to return.
* @return {String} return the recived import.
* Check if a numeric value is an even number.
* @param {Number} number a number to check.
* @return {Boolean} boolean indication whether the given number is even.
* @throws {TypeError} throw error when the argument is not a number.
*/
export const isEven = number => {
if (isNaN(number)) {
throw new TypeError('The first argument must be a number');
}
return number % 2 === 0;
};

/**
* Check if a numeric value is an odd number.
* @param {Number} number a number to check.
* @return {Boolean} boolean indication whether the given number is odd.
* @throws {TypeError} throw error when the argument is not a number.
*/
export const namedExport = (input = 'No args passed!') => input;
export const isOdd = number => !isEven(number);
35 changes: 29 additions & 6 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import nodeMdlStarter, { namedExport } from './index';
import nodeMdlStarter, { isEven, isOdd } from './index';

test('output', () => {
expect(nodeMdlStarter('🐰')).toBe('🐰');
expect(nodeMdlStarter()).toBe('No args passed!');
describe('node-mdl-starter', () => {
test('default', () => {
expect(nodeMdlStarter('🐰')).toBe('🐰');
expect(nodeMdlStarter()).toBe('No args passed!');
});

expect(namedExport('🐰')).toBe('🐰');
expect(namedExport()).toBe('No args passed!');
test('isEven', () => {
for (let i = 0; i < 20; i += 2) {
expect(isEven(i)).toBe(true);
}

for (let i = 1; i < 20; i += 2) {
expect(isEven(i)).toBe(false);
}

expect(() => isEven('not-a-number')).toThrow(TypeError);
});

test('isOdd', () => {
for (let i = 0; i < 20; i += 2) {
expect(isOdd(i)).toBe(false);
}

for (let i = 1; i < 20; i += 2) {
expect(isOdd(i)).toBe(true);
}

expect(() => isOdd('not-a-number')).toThrow(TypeError);
});
});

0 comments on commit 388d7e0

Please sign in to comment.