1- 'use strict' ;
2-
3- const assert = require ( 'chai' ) . assert ;
1+ const { assert } = require ( 'chai' ) ;
42const Flakeless = require ( '..' ) ;
53
6- describe ( 'Flakeless base16 output' , function ( ) {
7- it ( 'is an object' , function ( ) {
4+ describe ( 'Flakeless base16 output' , ( ) => {
5+ it ( 'is an object' , ( ) => {
86 const flakeless = new Flakeless ( {
9- outputType : 'base16'
7+ outputType : 'base16' ,
108 } ) ;
119
1210 assert . equal ( typeof flakeless , 'object' ) ;
1311 assert . instanceOf ( flakeless , Flakeless ) ;
1412 } ) ;
1513
16- it ( 'returns a string' , function ( ) {
14+ it ( 'returns a string' , ( ) => {
1715 const flakeless = new Flakeless ( {
18- outputType : 'base16'
16+ outputType : 'base16' ,
1917 } ) ;
2018
2119 const id = flakeless . next ( ) ;
2220
2321 assert . typeOf ( id , 'string' ) ;
2422 } ) ;
2523
26- it ( 'is 16 characters long' , function ( ) {
24+ it ( 'is 16 characters long' , ( ) => {
2725 const flakeless = new Flakeless ( {
28- outputType : 'base16'
26+ outputType : 'base16' ,
2927 } ) ;
3028
3129 const id = flakeless . next ( ) ;
3230
3331 assert . lengthOf ( id , 16 ) ;
3432 } ) ;
3533
36- it ( 'increases' , function ( ) {
34+ it ( 'increases' , ( ) => {
3735 // Define a Flakeless counter that outputs in base10.
3836 const flakeless = new Flakeless ( {
3937 epochStart : Date . now ( ) ,
40- outputType : 'base16'
38+ outputType : 'base16' ,
4139 } ) ;
4240
4341 // Generate a bunch of IDs.
4442 const ids = [ ] ;
45- for ( let i = 0 ; i < 1000 ; ++ i ) {
43+ for ( let i = 0 ; i < 1000 ; i += 1 ) {
4644 ids . push ( flakeless . next ( ) ) ;
4745 }
4846
@@ -52,67 +50,67 @@ describe('Flakeless base16 output', function() {
5250 assert . deepEqual ( ids , sortedIds ) ;
5351 } ) ;
5452
55- it ( 'is monotonic' , function ( ) {
53+ it ( 'is monotonic' , ( ) => {
5654 const flakeless = new Flakeless ( {
5755 epochStart : Date . now ( ) ,
58- outputType : 'base16'
56+ outputType : 'base16' ,
5957 } ) ;
6058
6159 // Generate a bunch of IDs.
6260 const ids = [ ] ;
63- for ( let i = 0 ; i < 1000 ; ++ i ) {
61+ for ( let i = 0 ; i < 1000 ; i += 1 ) {
6462 ids . push ( flakeless . next ( ) ) ;
6563 }
6664
6765 // Sort the IDs and remove duplicates. If the output is monotonic, the
6866 // length of the two array should be the same.
69- const sortedIds = ids . sort ( ) . reduce ( function ( prev , curr ) {
67+ const sortedIds = ids . sort ( ) . reduce ( ( prev , curr ) => {
7068 return ( curr === prev [ 0 ] ) ? prev : [ curr ] . concat ( prev ) ;
7169 } , [ ] ) ;
7270 assert . lengthOf ( sortedIds , 1000 ) ;
7371 } ) ;
7472
75- it ( 'has an encoded timestamp' , function ( ) {
73+ it ( 'has an encoded timestamp' , ( ) => {
7674 const flakeless = new Flakeless ( {
7775 epochStart : Date . now ( ) - 100 ,
7876 outputType : 'base16' ,
79- workerID : 0x3ff
77+ workerID : 0x3ff ,
8078 } ) ;
8179
8280 const id = parseInt ( flakeless . next ( ) , 16 ) ;
8381
8482 assert . isAtLeast ( id >> 22 , 100 ) ;
8583 } ) ;
8684
87- it ( 'has an encoded worker ID' , function ( ) {
85+ it ( 'has an encoded worker ID' , ( ) => {
8886 const flakeless = new Flakeless ( {
8987 epochStart : Date . now ( ) ,
9088 outputType : 'base16' ,
91- workerID : 34
89+ workerID : 34 ,
9290 } ) ;
9391
9492 const id = parseInt ( flakeless . next ( ) , 16 ) ;
9593
9694 assert . equal ( ( id & 0x3ff000 ) >> 12 , 34 ) ;
9795 } ) ;
9896
99- it ( 'has a properly sized workerID' , function ( ) {
97+ it ( 'has a properly sized workerID' , ( ) => {
10098 const flakeless = new Flakeless ( {
10199 epochStart : Date . now ( ) ,
102100 outputType : 'base16' ,
103- workerID : 0xffffffff
101+ workerID : 0xffffffff ,
104102 } ) ;
105103
106104 const id = parseInt ( flakeless . next ( ) , 16 ) >> 12 ;
107105
108106 assert . equal ( id & 0x3ff , 0x3ff ) ;
109107 } ) ;
110108
111- it ( 'has an encoded counter' , function ( ) {
109+ it ( 'has an encoded counter' , ( ) => {
112110 const flakeless = new Flakeless ( {
113111 epochStart : Date . now ( ) ,
114112 outputType : 'base16' ,
115- workerID : 0x3ff
113+ workerID : 0x3ff ,
116114 } ) ;
117115
118116 const id = parseInt ( flakeless . next ( ) , 16 ) ;
0 commit comments