Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d31aa8

Browse files
committed
Cleanup examples
1 parentddc9583 commit6d31aa8

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-
letrandom=newRandom()
4-
letbytes=Buffer.from([250,200,150,100])
5+
constrandom=newRandom()
6+
constbytes=Buffer.from([250,200,150,100])
57
letstring=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-
letrandom=newRandom(charSet2)
5+
constrandom=newRandom(charSet2)
46
letflips=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-
letrandom=newRandom('0123456789ABCDEF')
4-
letstring=random.string(48)
5+
constrandom=newRandom('0123456789ABCDEF')
6+
conststring=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-
letrandom=newRandom('123456')
6+
constrandom=newRandom('123456')
57
}
68
catch(error){
7-
console.log('Error: '+error.message)
9+
console.log('\nError: '+error.message)
810
}
911

10-
1112
try{
12-
letrandom=newRandom('01233210')
13+
constrandom=newRandom('01233210')
1314
}
1415
catch(error){
15-
console.log('Error: '+error.message)
16+
console.log('\nError: '+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-
letrandom=newRandom(charSet16)
4-
letbits=Entropy.bits(10000,1000000)
5-
letstrings=Array()
3+
constrandom=newRandom(charSet16)
4+
constbits=Entropy.bits(10000,1000000)
5+
conststrings=Array()
66
for(leti=0;i<5;i++){
7-
letstring=random.string(bits)
7+
conststring=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-
letrandom=newRandom()
4-
letbits=Entropy.bits(10000,1000000)
5-
letstring=random.string(bits)
6-
console.log('\n Base 32 string : '+string+'\n')
5+
constrandom=newRandom()
6+
constbits=Entropy.bits(10000,1000000)
7+
conststring=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-
letrandom=newRandom(charSet16)
4-
letbits=Entropy.bits(30,100000)
5+
constrandom=newRandom(charSet16)
6+
constbits=Entropy.bits(30,100000)
57
letstring=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-
letrandom=newRandom()
4-
letbits=Entropy.bitsWithPowers(10,12)
5-
letstring=random.string(bits)
6-
console.log('\n Base 32 string : '+string+'\n')
5+
constrandom=newRandom()
6+
constbits=Entropy.bitsWithPowers(10,12)
7+
conststring=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)

[8]ページ先頭

©2009-2026 Movatter.jp