Skip to content

Commit ef0dd2c

Browse files
committed
Examples
From README
1 parent 2e1e344 commit ef0dd2c

29 files changed

+360
-180
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
*~
33
.DS_Store
4+
examples/dist

README.md

Lines changed: 155 additions & 112 deletions
Large diffs are not rendered by default.

dist/lib/random.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var _stringWithBytes = function _stringWithBytes(entropyBits, bytes, charSet) {
126126

127127
var needed = Math.ceil(count * (bitsPerChar / _bitsPerByte));
128128
if (bytes.length < needed) {
129-
throw new Error('Insufficient bytes. Need ' + needed);
129+
throw new Error('Insufficient bytes: need ' + needed + ' and got ' + bytes.length);
130130
}
131131

132132
var charsPerChunk = charSet.getCharsPerChunk();

entropy-string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Random = require('./dist/lib/random').default
22
const Entropy = require('./dist/lib/entropy').default
33
const CharSet = require('./dist/lib/charSet').default
4-
const {charSet2, charSet4, charSet8, charSet16, charSet32, charSet64} = require('./dist/lib/random')
4+
const {charSet2, charSet4, charSet8, charSet16, charSet32, charSet64} = require('./dist/lib/charSet')
55

66
module.exports = {
77
Random,

examples.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/charSets.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {charSet64, charSet32, charSet16, charSet8, charSet4, charSet2} from './entropy-string'
2+
3+
console.log('\n charSet64: ' + charSet64.chars())
4+
console.log('\n charSet32: ' + charSet32.chars())
5+
console.log('\n charSet16: ' + charSet16.chars())
6+
console.log('\n charSet8: ' + charSet8.chars())
7+
console.log('\n charSet4: ' + charSet4.chars())
8+
console.log('\n charSet2: ' + charSet2.chars() + '\n')

examples/custom_bytes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Random} from './entropy-string'
2+
3+
let random = new Random()
4+
let bytes = Buffer.from([250, 200, 150, 100])
5+
let string = random.stringWithBytes(30, bytes)
6+
console.log('\n Custom bytes string : ' + string + '\n')
7+
8+
try {
9+
string = random.stringWithBytes(32, bytes)
10+
}
11+
catch(error) {
12+
console.log(' Error: ' + error.message)
13+
}
14+

examples/custom_chars_1.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Random, charSet2} from './entropy-string'
2+
3+
let random = new Random(charSet2)
4+
let flips = random.string(10)
5+
console.log('\n 10 flips: ' + flips + '\n')
6+
7+
random.useChars('HT')
8+
flips = random.string(10)
9+
console.log('\n 10 flips: ' + flips + '\n')
10+

examples/custom_chars_2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Random} from './entropy-string'
2+
3+
let random = new Random('0123456789ABCDEF')
4+
let string = random.string(48)
5+
console.log('\n Uppercase hex: ' + string + '\n')

examples/custom_chars_3.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Random} from './entropy-string'
2+
3+
try {
4+
let random = new Random('123456')
5+
}
6+
catch(error) {
7+
console.log('Error: ' + error.message)
8+
}
9+
10+
11+
try {
12+
let random = new Random('01233210')
13+
}
14+
catch(error) {
15+
console.log('Error: ' + error.message)
16+
}

0 commit comments

Comments
 (0)