Skip to content

Dev #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Node.js CI

on:
push:
branches:
- master
watch:
types: [started]

jobs:
build:

runs-on: ubuntu-latest

if: github.actor == github.event.repository.owner.login

strategy:
matrix:
#node-version: [8.x, 10.x, 12.x]
node-version: [13.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm test
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# Example .gitignore files: https://github.com/github/gitignore
/bower_components/
/node_modules/
npm-debug.log
npm-debug.log
/lib
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
publish.bat
push.bat
.npmignore
.github
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
# random-number-csprng

This is a fork of module random-number-csprng-2 without external dependencies and updated to be compatible with Node v12 and Babel v7.

A CommonJS module for generating cryptographically secure pseudo-random numbers.

Works in Node.js, and should work in the browser as well, using Webpack or Browserify.
Works in Node.js; This fork isn't tested in browser yet. You can help with it.

This module is based on code [originally written](https://gist.github.com/sarciszewski/88a7ed143204d17c3e42) by [Scott Arciszewski](https://github.com/sarciszewski), released under the WTFPL / CC0 / ZAP.
This module is based on code [originally written](https://gist.github.com/sarciszewski/88a7ed143204d17c3e42) by [Scott Arciszewski](https://github.com/sarciszewski), released under the WTFPL / CC0 / ZAP, [random-number-csprng](https://github.com/joepie91/node-random-number-csprng) by [Sven Slootweg](https://github.com/joepie91), and [random-number-csprng-2](https://github.com/PROger4ever-NodeJS/node-random-number-csprng-2).

## License

[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.

## Donate

My income consists largely of donations for my projects. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!

You can donate using Bitcoin, PayPal, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else.
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer.

## Contributing

Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the files in `src/`, not those in `lib/`.

Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
Build tool of choice is `gulp`; simply run `npm run build` while developing, and it will watch for changes.

Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.

## Usage

This module will return the result asynchronously - this is necessary to avoid blocking your entire application while generating a number.

An example:
Promise example:

```javascript
var Promise = require("bluebird");
var randomNumber = require("random-number-csprng");
const randomNumberCsrpg = require("@thzero/random-number-csprng");

Promise.try(function() {
return randomNumber(10, 30);
Promise.resolve().then(function() {
return randomNumberCsrpg(10, 30);
}).then(function(number) {
console.log("Your random number:", number);
}).catch({code: "RandomGenerationError"}, function(err) {
console.log("Something went wrong!");
}).catch(function(err) {
console.log("Something went wrong: " + err.code);
});
```

Await example:

```javascript
const randomNumberCsrpg = require("@thzero/random-number-csprng");
const randomNumber = await randomNumberCsrpg(10, 30);
```

## API

### randomNumber(minimum, maximum, [cb])
Expand All @@ -62,8 +64,8 @@ Any errors that occur during the random number generation process will be of thi

The error message will provide more information, but this kind of error will generally mean that the arguments you've specified are somehow invalid.

## Changelog
## Notes

Don't use ranges any bigger than 2^32 - 1 or 4,294,97,295. Details in [Issue #4 of the original module](https://github.com/joepie91/node-random-number-csprng/issues/4).

* __1.0.2__ (March 8, 2016): __*Security release!*__ Patched handling of large numbers; input values are now checked for `MIN_SAFE_INTEGER` and `MAX_SAFE_INTEGER`, and the correct bitwise operator is used (`>>>` rather than `>>`).
* __1.0.1__ (March 8, 2016): Unimportant file cleanup.
* __1.0.0__ (March 8, 2016): Initial release.
This fork isn't tested in browser yet. You can help with it.
32 changes: 17 additions & 15 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
var gulp = require('gulp');

var gutil = require('gulp-util');
var babel = require('gulp-babel');
var cache = require('gulp-cached');
var remember = require('gulp-remember');
var plumber = require('gulp-plumber');
const gulp = require('gulp');
const babel = require('gulp-babel');

var source = ["src/**/*.js"]

gulp.task('babel', function() {
gulp.task('babel', () => {
return gulp.src(source)
.pipe(plumber())
.pipe(cache("babel"))
.pipe(babel({presets: ["es2015"]}).on('error', gutil.log)).on('data', gutil.log)
.pipe(remember("babel"))
.pipe(babel(
{
presets: [
[
"@babel/preset-env", {
useBuiltIns: false
}
]
]
}
)) //.on('error', gutil.log)).on('data', gutil.log)
.pipe(gulp.dest("lib/"));
});

gulp.task('watch', function () {
gulp.watch(source, ['babel']);
gulp.task('watch', () => {
gulp.watch(source, gulp.series('babel'));
});

gulp.task('default', ['babel', 'watch']);
gulp.task('default', gulp.series('babel'));
Loading