Skip to content

Instantly share code, notes, and snippets.

@vmarchesin
Last active May 27, 2020 10:26
Show Gist options
  • Save vmarchesin/5b60a5e5386030c2f976de916f9e62c5 to your computer and use it in GitHub Desktop.
Save vmarchesin/5b60a5e5386030c2f976de916f9e62c5 to your computer and use it in GitHub Desktop.
how-to-publish-a-npm-package
const bool = () => Boolean(Math.round(Math.random()));
export default bool;
const float = (max, min) => Math.random() * (max - min) + min;
export default float;
import bool from './bool';
import float from './float';
import integer from './integer';
const choice = (max = 1, min = 0, options = {}) => {
if (options.float === true) {
return float(max, min);
} else if (options.bool === true) {
return bool();
} else {
return integer(max, min);
}
}
export default choice;
const integer = (max, min) => ~~(Math.random() * (max - min + 1) + min);
export default integer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment