11import CharSet from './charSet'
22import lcm from './lcm'
33
4- const log2 = Math . log2
5- const log10 = Math . log10
6- const log2_10 = log2 ( 10 )
4+ const _log2 = Math . log2
5+ const _log10 = Math . log10
6+ const _log2_10 = _log2 ( 10 )
77
8- const endianByteNum = ( ( ) => {
8+ const _endianByteNum = ( ( ) => {
99 const buf32 = new Uint32Array ( 1 )
1010 const buf8 = new Uint8Array ( buf32 . buffer )
1111 buf32 [ 0 ] = 0xff
@@ -17,11 +17,11 @@ const bits = (total, risk) => {
1717
1818 let N = 0
1919 if ( total < 10001 ) {
20- N = log2 ( total ) + log2 ( total - 1 ) + ( log2_10 * log10 ( risk ) ) - 1
20+ N = _log2 ( total ) + _log2 ( total - 1 ) + ( _log2_10 * _log10 ( risk ) ) - 1
2121 }
2222 else {
23- const n = 2 * log10 ( total ) + log10 ( risk )
24- N = n * log2_10 - 1
23+ const n = 2 * _log10 ( total ) + _log10 ( risk )
24+ N = n * _log2_10 - 1
2525 }
2626 return N
2727}
@@ -31,11 +31,11 @@ const bitsWithRiskPower = (total, rPower) => {
3131
3232 let N = 0
3333 if ( total < 10001 ) {
34- N = log2 ( total ) + log2 ( total - 1 ) + ( log2_10 * rPower ) - 1
34+ N = _log2 ( total ) + _log2 ( total - 1 ) + ( _log2_10 * rPower ) - 1
3535 }
3636 else {
37- const n = 2 * log10 ( total ) + rPower
38- N = n * log2_10 - 1
37+ const n = 2 * _log10 ( total ) + rPower
38+ N = n * _log2_10 - 1
3939 }
4040 return N
4141}
@@ -47,13 +47,13 @@ const bitsWithPowers = (tPower, rPower) => {
4747 }
4848 else {
4949 const n = 2 * tPower + rPower
50- N = n * log2_10 - 1
50+ N = n * _log2_10 - 1
5151 }
5252 return N
5353}
5454
5555const randomString = ( entropy , charSet , crypto = true ) => {
56- const bytes = crypto ? cryptoBytes ( entropy , charSet ) : randomBytes ( entropy , charSet )
56+ const bytes = crypto ? _cryptoBytes ( entropy , charSet ) : _randomBytes ( entropy , charSet )
5757 return randomStringWithBytes ( entropy , charSet , bytes )
5858}
5959
@@ -78,27 +78,27 @@ const randomStringWithBytes = (entropy, charSet, bytes) => {
7878 switch ( charSet ) {
7979 case CharSet . charSet64 :
8080 chars = CharSet . charSet64 . chars
81- ndxFn = ndx64
81+ ndxFn = _ndx64
8282 break
8383 case CharSet . charSet32 :
8484 chars = CharSet . charSet32 . chars
85- ndxFn = ndx32
85+ ndxFn = _ndx32
8686 break
8787 case CharSet . charSet16 :
8888 chars = CharSet . charSet16 . chars
89- ndxFn = ndx16
89+ ndxFn = _ndx16
9090 break
9191 case CharSet . charSet8 :
9292 chars = CharSet . charSet8 . chars
93- ndxFn = ndx8
93+ ndxFn = _ndx8
9494 break
9595 case CharSet . charSet4 :
9696 chars = CharSet . charSet4 . chars
97- ndxFn = ndx4
97+ ndxFn = _ndx4
9898 break
9999 case CharSet . charSet2 :
100100 chars = CharSet . charSet2 . chars
101- ndxFn = ndx2
101+ ndxFn = _ndx2
102102 break
103103 default :
104104 break
@@ -127,12 +127,12 @@ const bytesNeeded = (entropy, charSet) => {
127127 return Math . ceil ( count * bytesPerSlice )
128128}
129129
130- const cryptoBytes = ( entropy , charSet ) => {
130+ const _cryptoBytes = ( entropy , charSet ) => {
131131 const crypto = require ( 'crypto' )
132132 return Buffer . from ( crypto . randomBytes ( bytesNeeded ( entropy , charSet ) ) )
133133}
134134
135- const randomBytes = ( entropy , charSet ) => {
135+ const _randomBytes = ( entropy , charSet ) => {
136136 const byteCount = bytesNeeded ( entropy , charSet )
137137 const randCount = Math . ceil ( byteCount / 6 )
138138
@@ -141,45 +141,45 @@ const randomBytes = (entropy, charSet) => {
141141 for ( let rNum = 0 ; rNum < randCount ; rNum ++ ) {
142142 dataView . setFloat64 ( 0 , Math . random ( ) )
143143 for ( let n = 0 ; n < 6 ; n ++ ) {
144- let fByteNum = endianByteNum [ n ]
144+ let fByteNum = _endianByteNum [ n ]
145145 let bByteNum = 6 * rNum + n
146- bufferByte ( buffer , bByteNum , fByteNum , byteCount , dataView )
146+ _bufferByte ( buffer , bByteNum , fByteNum , byteCount , dataView )
147147 }
148148 }
149149 return buffer
150150}
151151
152- const bufferByte = ( buffer , bByte , nByte , byteCount , dataView ) => {
152+ const _bufferByte = ( buffer , bByte , nByte , byteCount , dataView ) => {
153153 if ( bByte < byteCount ) {
154154 buffer [ bByte ] = dataView . getUint8 ( nByte )
155155 }
156156}
157157
158- const ndx64 = ( chunk , slice , bytes ) => {
159- return ndxGen ( chunk , slice , bytes , 6 )
158+ const _ndx64 = ( chunk , slice , bytes ) => {
159+ return _ndxGen ( chunk , slice , bytes , 6 )
160160}
161161
162- const ndx32 = ( chunk , slice , bytes ) => {
163- return ndxGen ( chunk , slice , bytes , 5 )
162+ const _ndx32 = ( chunk , slice , bytes ) => {
163+ return _ndxGen ( chunk , slice , bytes , 5 )
164164}
165165
166- const ndx16 = ( chunk , slice , bytes ) => {
166+ const _ndx16 = ( chunk , slice , bytes ) => {
167167 return ( ( bytes [ chunk ] << ( 4 * slice ) ) & 0xff ) >> 4
168168}
169169
170- const ndx8 = ( chunk , slice , bytes ) => {
171- return ndxGen ( chunk , slice , bytes , 3 )
170+ const _ndx8 = ( chunk , slice , bytes ) => {
171+ return _ndxGen ( chunk , slice , bytes , 3 )
172172}
173173
174- const ndx4 = ( chunk , slice , bytes ) => {
174+ const _ndx4 = ( chunk , slice , bytes ) => {
175175 return ( ( bytes [ chunk ] << ( 2 * slice ) ) & 0xff ) >> 6
176176}
177177
178- const ndx2 = ( chunk , slice , bytes ) => {
178+ const _ndx2 = ( chunk , slice , bytes ) => {
179179 return ( ( bytes [ chunk ] << slice ) & 0xff ) >> 7
180180}
181181
182- const ndxGen = ( chunk , slice , bytes , bitsPerSlice ) => {
182+ const _ndxGen = ( chunk , slice , bytes , bitsPerSlice ) => {
183183 let bitsPerByte = 8
184184 let slicesPerChunk = lcm ( bitsPerSlice , bitsPerByte ) / bitsPerByte
185185
0 commit comments