Created
October 9, 2017 20:14
-
-
Save lifuzu/a77ffa1868e08e0353b04a881f8c47ce to your computer and use it in GitHub Desktop.
A node/npm functions template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// __tests__/funcs.spec.js | |
const funcs = require("../libs/funcs")() | |
describe('hello', () => { | |
it('should say hello', () => { | |
expect(funcs.hello()).toBe('world!') | |
}) | |
}) | |
describe('world', () => { | |
it('should caculate world', () => { | |
expect(funcs.world([1, 2]) === [2, 4]) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// libs/funcs.js | |
exports = module.exports = (options) => { | |
// PRIVATE FUNCTION(S) | |
// get a random integer between 0 (zero) and max | |
function random_wait(max) { | |
return Math.floor(Math.random() * (max + 1)) | |
} | |
// PRIVATE VARIABLE(S) | |
const private_count = 'something' | |
// PUBLIC FUNCTION(S) | |
return { | |
hello: function (params) { | |
return 'world!' | |
}, | |
world: function (params) { | |
return params.map( p => { | |
return p * 2 | |
}) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// package.json | |
{ | |
// ... | |
"scripts": { | |
"test": "jest", | |
"start": "babel-node --presets env $npm_package_main" | |
}, | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment