@@ -12,11 +12,12 @@ var _createClass2 = require('babel-runtime/helpers/createClass');
12
12
13
13
var _createClass3 = _interopRequireDefault ( _createClass2 ) ;
14
14
15
- var _charSet = require ( './charSet' ) ;
15
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
16
16
17
- var _charSet2 = _interopRequireDefault ( _charSet ) ;
17
+ var CharSet = require ( './charset' ) . default ;
18
18
19
- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
19
+ var _require = require ( './charset' ) ,
20
+ charset32 = _require . charset32 ;
20
21
21
22
var Crypto = require ( 'crypto' ) ;
22
23
var WeakMap = require ( 'weak-map' ) ;
@@ -32,12 +33,12 @@ var endianByteNum = function () {
32
33
return buf8 [ 0 ] === 0xff ? [ 2 , 3 , 4 , 5 , 6 , 7 ] : [ 0 , 1 , 2 , 3 , 6 , 7 ] ;
33
34
} ( ) ;
34
35
35
- var _stringWithBytes = function _stringWithBytes ( entropyBits , bytes , charSet ) {
36
+ var _stringWithBytes = function _stringWithBytes ( entropyBits , bytes , charset ) {
36
37
if ( entropyBits <= 0 ) {
37
38
return '' ;
38
39
}
39
40
40
- var bitsPerChar = charSet . getBitsPerChar ( ) ;
41
+ var bitsPerChar = charset . getBitsPerChar ( ) ;
41
42
var count = Math . ceil ( entropyBits / bitsPerChar ) ;
42
43
if ( count <= 0 ) {
43
44
return '' ;
@@ -48,12 +49,12 @@ var _stringWithBytes = function _stringWithBytes(entropyBits, bytes, charSet) {
48
49
throw new Error ( 'Insufficient bytes: need ' + need + ' and got ' + bytes . length ) ;
49
50
}
50
51
51
- var charsPerChunk = charSet . getCharsPerChunk ( ) ;
52
+ var charsPerChunk = charset . getCharsPerChunk ( ) ;
52
53
var chunks = Math . floor ( count / charsPerChunk ) ;
53
54
var partials = count % charsPerChunk ;
54
55
55
- var ndxFn = charSet . getNdxFn ( ) ;
56
- var chars = charSet . getChars ( ) ;
56
+ var ndxFn = charset . getNdxFn ( ) ;
57
+ var chars = charset . getChars ( ) ;
57
58
58
59
var string = '' ;
59
60
for ( var chunk = 0 ; chunk < chunks ; chunk += 1 ) {
@@ -96,107 +97,107 @@ var _class = function () {
96
97
function _class ( arg ) {
97
98
( 0 , _classCallCheck3 . default ) ( this , _class ) ;
98
99
99
- var charSet = void 0 ;
100
+ var charset = void 0 ;
100
101
if ( arg === undefined ) {
101
- charSet = _charSet . charSet32 ;
102
- } else if ( arg instanceof _charSet2 . default ) {
103
- charSet = arg ;
102
+ charset = charset32 ;
103
+ } else if ( arg instanceof CharSet ) {
104
+ charset = arg ;
104
105
} else if ( typeof arg === 'string' || arg instanceof String ) {
105
- charSet = new _charSet2 . default ( arg ) ;
106
+ charset = new CharSet ( arg ) ;
106
107
} else {
107
108
throw new Error ( 'Invalid arg: must be either valid CharSet or valid chars' ) ;
108
109
}
109
110
var hideProps = {
110
- charSet : charSet
111
+ charset : charset
111
112
} ;
112
113
propMap . set ( this , hideProps ) ;
113
114
}
114
115
115
116
( 0 , _createClass3 . default ) ( _class , [ {
116
117
key : 'smallID' ,
117
118
value : function smallID ( ) {
118
- var charSet = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charSet ;
119
+ var charset = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charset ;
119
120
120
- return this . string ( 29 , charSet ) ;
121
+ return this . string ( 29 , charset ) ;
121
122
}
122
123
} , {
123
124
key : 'mediumID' ,
124
125
value : function mediumID ( ) {
125
- var charSet = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charSet ;
126
+ var charset = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charset ;
126
127
127
- return this . string ( 69 , charSet ) ;
128
+ return this . string ( 69 , charset ) ;
128
129
}
129
130
} , {
130
131
key : 'largeID' ,
131
132
value : function largeID ( ) {
132
- var charSet = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charSet ;
133
+ var charset = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charset ;
133
134
134
- return this . string ( 99 , charSet ) ;
135
+ return this . string ( 99 , charset ) ;
135
136
}
136
137
} , {
137
138
key : 'sessionID' ,
138
139
value : function sessionID ( ) {
139
- var charSet = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charSet ;
140
+ var charset = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charset ;
140
141
141
- return this . string ( 128 , charSet ) ;
142
+ return this . string ( 128 , charset ) ;
142
143
}
143
144
} , {
144
145
key : 'token' ,
145
146
value : function token ( ) {
146
- var charSet = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charSet ;
147
+ var charset = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : propMap . get ( this ) . charset ;
147
148
148
- return this . string ( 256 , charSet ) ;
149
+ return this . string ( 256 , charset ) ;
149
150
}
150
151
} , {
151
152
key : 'string' ,
152
153
value : function string ( entropyBits ) {
153
- var charSet = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charSet ;
154
+ var charset = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charset ;
154
155
155
- var bytesNeeded = charSet . bytesNeeded ( entropyBits ) ;
156
- return this . stringWithBytes ( entropyBits , cryptoBytes ( bytesNeeded ) , charSet ) ;
156
+ var bytesNeeded = charset . bytesNeeded ( entropyBits ) ;
157
+ return this . stringWithBytes ( entropyBits , cryptoBytes ( bytesNeeded ) , charset ) ;
157
158
}
158
159
} , {
159
160
key : 'stringRandom' ,
160
161
value : function stringRandom ( entropyBits ) {
161
- var charSet = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charSet ;
162
+ var charset = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charset ;
162
163
163
- var bytesNeeded = charSet . bytesNeeded ( entropyBits ) ;
164
- return this . stringWithBytes ( entropyBits , randomBytes ( bytesNeeded ) , charSet ) ;
164
+ var bytesNeeded = charset . bytesNeeded ( entropyBits ) ;
165
+ return this . stringWithBytes ( entropyBits , randomBytes ( bytesNeeded ) , charset ) ;
165
166
}
166
167
} , {
167
168
key : 'stringWithBytes' ,
168
169
value : function stringWithBytes ( entropyBits , bytes ) {
169
- var charSet = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : propMap . get ( this ) . charSet ;
170
+ var charset = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : propMap . get ( this ) . charset ;
170
171
171
- return _stringWithBytes ( entropyBits , bytes , charSet ) ;
172
+ return _stringWithBytes ( entropyBits , bytes , charset ) ;
172
173
}
173
174
} , {
174
175
key : 'bytesNeeded' ,
175
176
value : function bytesNeeded ( entropyBits ) {
176
- var charSet = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charSet ;
177
+ var charset = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : propMap . get ( this ) . charset ;
177
178
178
- return charSet . bytesNeeded ( entropyBits ) ;
179
+ return charset . bytesNeeded ( entropyBits ) ;
179
180
}
180
181
} , {
181
182
key : 'chars' ,
182
183
value : function chars ( ) {
183
- return propMap . get ( this ) . charSet . chars ( ) ;
184
+ return propMap . get ( this ) . charset . chars ( ) ;
184
185
}
185
186
} , {
186
187
key : 'use' ,
187
- value : function use ( charSet ) {
188
- if ( ! ( charSet instanceof _charSet2 . default ) ) {
188
+ value : function use ( charset ) {
189
+ if ( ! ( charset instanceof CharSet ) ) {
189
190
throw new Error ( 'Invalid CharSet' ) ;
190
191
}
191
- propMap . get ( this ) . charSet = charSet ;
192
+ propMap . get ( this ) . charset = charset ;
192
193
}
193
194
} , {
194
195
key : 'useChars' ,
195
196
value : function useChars ( chars ) {
196
197
if ( ! ( typeof chars === 'string' || chars instanceof String ) ) {
197
198
throw new Error ( 'Invalid chars: Must be string' ) ;
198
199
}
199
- this . use ( new _charSet2 . default ( chars ) ) ;
200
+ this . use ( new CharSet ( chars ) ) ;
200
201
}
201
202
} ] ) ;
202
203
return _class ;
0 commit comments