File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change
1
+ import isFalsy from './isFalsy'
2
+
1
3
const { Snowflake } = require ( '../build/Release/snowflake' ) ;
2
4
3
5
const CUSTOM_EPOCH = 1546300800000 ; // 01-01-2019
@@ -14,6 +16,8 @@ const initConfig: Config = {
14
16
returnNumber : false
15
17
}
16
18
19
+
20
+
17
21
/**
18
22
* Constructs a UniqueID object which stores method for generation
19
23
* of a unique 64 bit time sortable id and a method for retreiving
@@ -40,7 +44,9 @@ export class UniqueID {
40
44
41
45
// A 12 bit machine id, if not passed in then a random id will be used
42
46
// Ternary operator was used to make sure "0" isn't considered to be falsy.
43
- this . _MACHINE_ID = config . machineID !== undefined ? config . machineID : Math . floor ( Math . random ( ) * MAX_MACHINE_ID ) ;
47
+ this . _MACHINE_ID = (
48
+ ! isFalsy ( config . machineID ) ? config . machineID : Math . floor ( Math . random ( ) * MAX_MACHINE_ID )
49
+ ) as number ;
44
50
45
51
// Check if the number is satisfies all the conditions
46
52
if ( ! Number . isInteger ( this . _MACHINE_ID ) ) throw Error ( "Machine Id should be a decimal number" ) ;
Original file line number Diff line number Diff line change
1
+ export default ( value : any ) => {
2
+ if ( value === undefined ) return true ;
3
+ if ( isNaN ( value ) ) return true ;
4
+ if ( Array . isArray ( value ) && ! value . length ) return true ;
5
+ if ( value === "" ) return true ;
6
+ if ( value === null ) return true ;
7
+ }
You can’t perform that action at this time.
0 commit comments