File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { tmpdir } from 'os' ;
22import { join } from 'path' ;
3+ import { uuid } from './uuid' ;
34
45export interface IApp {
56 readonly bundleId : string ;
@@ -39,7 +40,7 @@ export const SUPPORTED_FILE_TYPES = [
3940 ...supports . jpegmini ,
4041] . filter ( ( value , i , list ) => list . indexOf ( value ) === i ) ;
4142
42- export const TMPDIR = join ( tmpdir ( ) , 'imageoptim-cli' ) ;
43+ export const TMPDIR = join ( tmpdir ( ) , 'imageoptim-cli' , uuid ( ) ) ;
4344export const VERSION = manifest . version ;
4445export const PNGQUANT_NUMBER_OF_COLORS = '256' ;
4546export const PNGQUANT_QUALITY = '65-80' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Cheaply generate a UUID with a low chance of collisions
3+ * https://stackoverflow.com/a/8809472/745158
4+ */
5+ export function uuid ( ) : string {
6+ let epoch : number = new Date ( ) . getTime ( ) ;
7+ let sessionLength : number = Date . now ( ) * 1000 || 0 ;
8+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, ( character ) => {
9+ let randomNumber : number = Math . random ( ) * 16 ;
10+ if ( epoch > 0 ) {
11+ randomNumber = ( epoch + randomNumber ) % 16 | 0 ;
12+ epoch = Math . floor ( epoch / 16 ) ;
13+ } else {
14+ randomNumber = ( sessionLength + randomNumber ) % 16 | 0 ;
15+ sessionLength = Math . floor ( sessionLength / 16 ) ;
16+ }
17+ return ( character == 'x' ? randomNumber : ( randomNumber & 0x7 ) | 0x8 ) . toString ( 16 ) ;
18+ } ) ;
19+ }
You can’t perform that action at this time.
0 commit comments