Skip to content

Commit 6d31aa8

Browse files
committed
Cleanup examples
1 parent ddc9583 commit 6d31aa8

21 files changed

+110
-95
lines changed

examples/charSets.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Predefined character sets
2+
13
import {charSet64, charSet32, charSet16, charSet8, charSet4, charSet2} from './entropy-string'
24

35
console.log('\n charSet64: ' + charSet64.chars())

examples/custom_bytes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
// Custom bytes
2+
13
import {Random} from './entropy-string'
24

3-
let random = new Random()
4-
let bytes = Buffer.from([250, 200, 150, 100])
5+
const random = new Random()
6+
const bytes = Buffer.from([250, 200, 150, 100])
57
let string = random.stringWithBytes(30, bytes)
68
console.log('\n Custom bytes string : ' + string + '\n')
79

810
try {
911
string = random.stringWithBytes(32, bytes)
1012
}
1113
catch(error) {
12-
console.log(' Error: ' + error.message)
14+
console.log(' Error: ' + error.message + '\n')
1315
}
1416

examples/custom_chars_1.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// Custom characters: HT for coin flip
2+
13
import {Random, charSet2} from './entropy-string'
24

3-
let random = new Random(charSet2)
5+
const random = new Random(charSet2)
46
let flips = random.string(10)
5-
console.log('\n 10 flips: ' + flips + '\n')
7+
console.log('\n 10 flips: ' + flips)
68

79
random.useChars('HT')
810
flips = random.string(10)
911
console.log('\n 10 flips: ' + flips + '\n')
10-

examples/custom_chars_2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// Custom characters: Uppercase hex
2+
13
import {Random} from './entropy-string'
24

3-
let random = new Random('0123456789ABCDEF')
4-
let string = random.string(48)
5+
const random = new Random('0123456789ABCDEF')
6+
const string = random.string(48)
57
console.log('\n Uppercase hex: ' + string + '\n')

examples/custom_chars_3.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
// Custom character errors
2+
13
import {Random} from './entropy-string'
24

35
try {
4-
let random = new Random('123456')
6+
const random = new Random('123456')
57
}
68
catch(error) {
7-
console.log('Error: ' + error.message)
9+
console.log('\n Error: ' + error.message)
810
}
911

10-
1112
try {
12-
let random = new Random('01233210')
13+
const random = new Random('01233210')
1314
}
1415
catch(error) {
15-
console.log('Error: ' + error.message)
16+
console.log('\n Error: ' + error.message + '\n')
1617
}

examples/gen5.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {Random, Entropy, charSet16} from './entropy-string'
22

3-
let random = new Random(charSet16)
4-
let bits = Entropy.bits(10000, 1000000)
5-
let strings = Array()
3+
const random = new Random(charSet16)
4+
const bits = Entropy.bits(10000, 1000000)
5+
const strings = Array()
66
for (let i = 0; i < 5; i++) {
7-
let string = random.string(bits)
7+
const string = random.string(bits)
88
strings.push(string)
99
}
1010
console.log('\n 5 IDs: ' + strings.join(', ') + '\n')

examples/more_1.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// Ten thousand potential strings with 1 in a million risk of repeat
2+
13
import {Random, Entropy} from './entropy-string'
24

3-
let random = new Random()
4-
let bits = Entropy.bits(10000, 1000000)
5-
let string = random.string(bits)
6-
console.log('\n Base 32 string : ' + string + '\n')
5+
const random = new Random()
6+
const bits = Entropy.bits(10000, 1000000)
7+
const string = random.string(bits)
8+
9+
console.log('\n Ten thousand potential strings with 1 in a million risk of repeat: ' + string + '\n')
710

examples/more_2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Base 16 (hex) and base 4
2+
13
import {Random, Entropy, charSet16, charSet4} from './entropy-string'
24

3-
let random = new Random(charSet16)
4-
let bits = Entropy.bits(30, 100000)
5+
const random = new Random(charSet16)
6+
const bits = Entropy.bits(30, 100000)
57
let string = random.string(bits)
68
console.log('\n Base 16 string : ' + string)
79

examples/more_3.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Ten billion potential strings with 1 in a trillion risk of repeat
2+
13
import {Random, Entropy} from './entropy-string'
24

3-
let random = new Random()
4-
let bits = Entropy.bitsWithPowers(10, 12)
5-
let string = random.string(bits)
6-
console.log('\n Base 32 string : ' + string + '\n')
5+
const random = new Random()
6+
const bits = Entropy.bitsWithPowers(10, 12)
7+
const string = random.string(bits)
8+
9+
console.log('\n Ten billion potential strings with 1 in a trillion risk of repeat: ' + string + '\n')

examples/more_4.js

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

0 commit comments

Comments
 (0)