File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " base-x" ,
3- "version" : " 3.0.6 " ,
3+ "version" : " 3.0.7 " ,
44 "description" : " Fast base encoding / decoding of any given alphabet" ,
55 "keywords" : [
66 " base-x" ,
Original file line number Diff line number Diff line change 11/// <reference types="node" />
2- declare function base ( ALPHABET : string ) : {
3- encode : ( source : Buffer ) => string ;
4- decodeUnsafe : ( source : string ) => Buffer | undefined ;
5- decode : ( string : string ) => Buffer ;
6- } ;
2+ declare function base ( ALPHABET : string ) : base . BaseConverter ;
73export = base ;
4+ declare namespace base {
5+ interface BaseConverter {
6+ encode ( buffer : Buffer ) : string ;
7+ decodeUnsafe ( string : string ) : Buffer | undefined ;
8+ decode ( string : string ) : Buffer ;
9+ }
10+ }
Original file line number Diff line number Diff line change 77// @ts -ignore
88const _Buffer = require ( 'safe-buffer' ) . Buffer ;
99
10- function base ( ALPHABET : string ) {
10+ function base ( ALPHABET : string ) : base . BaseConverter {
1111 if ( ALPHABET . length >= 255 ) throw new TypeError ( 'Alphabet too long' )
1212
1313 const BASE_MAP = new Uint8Array ( 256 )
@@ -26,7 +26,7 @@ function base (ALPHABET: string) {
2626 const FACTOR = Math . log ( BASE ) / Math . log ( 256 ) // log(BASE) / log(256), rounded up
2727 const iFACTOR = Math . log ( 256 ) / Math . log ( BASE ) // log(256) / log(BASE), rounded up
2828
29- function encode ( source : Buffer ) {
29+ function encode ( source : Buffer ) : string {
3030 if ( ! _Buffer . isBuffer ( source ) ) throw new TypeError ( 'Expected Buffer' )
3131 if ( source . length === 0 ) return ''
3232
@@ -151,3 +151,11 @@ function base (ALPHABET: string) {
151151}
152152
153153export = base ;
154+
155+ declare namespace base {
156+ interface BaseConverter {
157+ encode ( buffer : Buffer ) : string ;
158+ decodeUnsafe ( string : string ) : Buffer | undefined ;
159+ decode ( string : string ) : Buffer ;
160+ }
161+ }
You can’t perform that action at this time.
0 commit comments